blob: 35c4c37278368d363d1a6402007496e20825f41f [file] [log] [blame]
Guy Schalnat0d580581995-07-20 02:43:20 -05001
Andreas Dilger47a0c421997-05-16 02:46:07 -05002/* png.h - header file for PNG reference library
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05004 * libpng 1.0.1c
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06005 * For conditions of distribution and use, see the COPYRIGHT NOTICE below.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06006 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
7 * Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrson2687fcc1998-01-07 20:54:20 -06008 * Copyright (c) 1998 Glenn Randers-Pehrson
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -05009 * May 9, 1998
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -060010 *
11 * Note about libpng version numbers:
12 *
13 * Due to various miscommunications, unforeseen code incompatibilities
14 * and occasional factors outside the authors' control, version numbering
15 * on the library has not always been consistent and straightforward.
16 * The following table summarizes matters since version 0.89c, which was
17 * the first widely used release:
18 *
Glenn Randers-Pehrson8f8fb6a1998-03-09 23:02:06 -060019 * source png.h png.h shared-lib
20 * version string int version
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -050021 * ------- ------ ----- ----------
22 * 0.89c ("1.0 beta 3") 0.89 89 1.0.89
23 * 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
24 * 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
25 * 0.96 ("1.0 beta 6") 0.96 96 0.96 [should have been 2.0.96]
26 * 0.97b ("1.00.97 beta 7") 1.00.97 97 1.0.1 [should have been 2.0.97]
27 * 0.97c 0.97 97 2.0.97
28 * 0.98 0.98 98 2.0.98
29 * 0.99 0.99 98 2.0.99
30 * 0.99a-m 0.99 99 2.0.99
31 * 1.00 1.00 100 2.1.0 [int should be 10000]
32 * 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
33 * 1.0.1 1.0.1 10001 2.1.0
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -050034 * 1.0.1a 1.0.1a 10002 2.1.0.1a
35 * 1.0.1b 1.0.1b 10002 2.1.0.1b
36 * 1.0.1c 1.0.1c 10002 2.1.0.1c
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -060037 *
38 * Henceforth the source version will match the shared-library minor
39 * and patch numbers; the shared-library major version number will be
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -050040 * used for changes in backward compatibility, as it is intended. The
41 * PNG_PNGLIB_VER macro, which is not used within libpng but is available
42 * for applications, is an unsigned integer of the form xyyzz corresponding
43 * to the source version x.y.z (leading zeros in y and z).
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060044 *
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -050045 * See libpng.txt or libpng.3 for more information. The PNG specification
46 * is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -060047 * and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060048 *
49 * Contributing Authors:
50 * John Bowler
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060051 * Kevin Bracey
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -060052 * Sam Bushell
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060053 * Andreas Dilger
54 * Magnus Holmgren
55 * Tom Lane
56 * Dave Martindale
57 * Glenn Randers-Pehrson
58 * Greg Roelofs
59 * Guy Eric Schalnat
60 * Paul Schmidt
61 * Tom Tanner
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -060062 * Willem van Schaik
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060063 * Tim Wegner
64 *
65 * The contributing authors would like to thank all those who helped
66 * with testing, bug fixes, and patience. This wouldn't have been
67 * possible without all of you.
68 *
69 * Thanks to Frank J. T. Wojcik for helping with the documentation.
70 *
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -060071 * COPYRIGHT NOTICE:
72 *
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060073 * The PNG Reference Library is supplied "AS IS". The Contributing Authors
74 * and Group 42, Inc. disclaim all warranties, expressed or implied,
75 * including, without limitation, the warranties of merchantability and of
76 * fitness for any purpose. The Contributing Authors and Group 42, Inc.
77 * assume no liability for direct, indirect, incidental, special, exemplary,
78 * or consequential damages, which may result from the use of the PNG
79 * Reference Library, even if advised of the possibility of such damage.
80 *
81 * Permission is hereby granted to use, copy, modify, and distribute this
82 * source code, or portions hereof, for any purpose, without fee, subject
83 * to the following restrictions:
84 * 1. The origin of this source code must not be misrepresented.
85 * 2. Altered versions must be plainly marked as such and must not be
86 * misrepresented as being the original source.
87 * 3. This Copyright notice may not be removed or altered from any source or
88 * altered source distribution.
89 *
90 * The Contributing Authors and Group 42, Inc. specifically permit, without
91 * fee, and encourage the use of this source code as a component to
92 * supporting the PNG file format in commercial products. If you use this
93 * source code in a product, acknowledgment is not required but would be
94 * appreciated.
95 */
Guy Schalnat0d580581995-07-20 02:43:20 -050096
97#ifndef _PNG_H
98#define _PNG_H
99
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600100#ifdef __cplusplus
101extern "C" {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500102#endif /* __cplusplus */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600103
Guy Schalnat0d580581995-07-20 02:43:20 -0500104/* This is not the place to learn how to use libpng. The file libpng.txt
Andreas Dilger47a0c421997-05-16 02:46:07 -0500105 * describes how to use libpng, and the file example.c summarizes it
106 * with some code on which to build. This file is useful for looking
107 * at the actual function definitions and structure components.
108 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500109
Guy Schalnat0d580581995-07-20 02:43:20 -0500110/* include the compression library's header */
111#include "zlib.h"
112
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500113/* include all user configurable info */
114#include "pngconf.h"
Guy Schalnat0d580581995-07-20 02:43:20 -0500115
Andreas Dilger47a0c421997-05-16 02:46:07 -0500116/* This file is arranged in several sections. The first section contains
117 * structure and type definitions. The second section contains the external
118 * library functions, while the third has the internal library functions,
119 * which applications aren't expected to use directly.
120 */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500121
Andreas Dilger47a0c421997-05-16 02:46:07 -0500122/* Version information for png.h - this should match the version in png.c */
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -0500123#define PNG_LIBPNG_VER_STRING "1.0.1c"
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500124
Glenn Randers-Pehrsonf9f2fe01998-03-15 18:20:23 -0600125/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
126 * We must not include leading zeros.
Glenn Randers-Pehrson8f8fb6a1998-03-09 23:02:06 -0600127 * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
128 * version 1.0.0 was mis-numbered 100 instead of 10000). From
Glenn Randers-Pehrsonf9f2fe01998-03-15 18:20:23 -0600129 * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=bugfix */
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500130#define PNG_LIBPNG_VER 10002 /* 1.0.2 */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500131
132/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600133#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500134/* Version information for C files, stored in png.c. This had better match
135 * the version above.
136 */
Glenn Randers-Pehrson8f8fb6a1998-03-09 23:02:06 -0600137extern char png_libpng_ver[12]; /* need room for 99.99.99aa */
Guy Schalnat0d580581995-07-20 02:43:20 -0500138
Andreas Dilger47a0c421997-05-16 02:46:07 -0500139/* Structures to facilitate easy interlacing. See png.c for more details */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600140extern int FARDATA png_pass_start[7];
141extern int FARDATA png_pass_inc[7];
142extern int FARDATA png_pass_ystart[7];
143extern int FARDATA png_pass_yinc[7];
144extern int FARDATA png_pass_mask[7];
145extern int FARDATA png_pass_dsp_mask[7];
Andreas Dilger47a0c421997-05-16 02:46:07 -0500146/* These aren't currently used. If you need them, see png.c for more details
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600147extern int FARDATA png_pass_width[7];
148extern int FARDATA png_pass_height[7];
Andreas Dilger47a0c421997-05-16 02:46:07 -0500149*/
150#endif /* PNG_NO_EXTERN */
151
152/* Three color definitions. The order of the red, green, and blue, (and the
153 * exact size) is not important, although the size of the fields need to
154 * be png_byte or png_uint_16 (as defined below).
155 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500156typedef struct png_color_struct
157{
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600158 png_byte red;
Guy Schalnat0d580581995-07-20 02:43:20 -0500159 png_byte green;
160 png_byte blue;
161} png_color;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500162typedef png_color FAR * png_colorp;
163typedef png_color FAR * FAR * png_colorpp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500164
165typedef struct png_color_16_struct
166{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500167 png_byte index; /* used for palette files */
168 png_uint_16 red; /* for use in red green blue files */
Guy Schalnat0d580581995-07-20 02:43:20 -0500169 png_uint_16 green;
170 png_uint_16 blue;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500171 png_uint_16 gray; /* for use in grayscale files */
Guy Schalnat0d580581995-07-20 02:43:20 -0500172} png_color_16;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500173typedef png_color_16 FAR * png_color_16p;
174typedef png_color_16 FAR * FAR * png_color_16pp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500175
176typedef struct png_color_8_struct
177{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500178 png_byte red; /* for use in red green blue files */
Guy Schalnat0d580581995-07-20 02:43:20 -0500179 png_byte green;
180 png_byte blue;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500181 png_byte gray; /* for use in grayscale files */
Guy Schalnat0d580581995-07-20 02:43:20 -0500182 png_byte alpha; /* for alpha channel files */
183} png_color_8;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500184typedef png_color_8 FAR * png_color_8p;
185typedef png_color_8 FAR * FAR * png_color_8pp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500186
Andreas Dilger47a0c421997-05-16 02:46:07 -0500187/* png_text holds the text in a PNG file, and whether they are compressed
188 in the PNG file or not. The "text" field points to a regular C string. */
Guy Schalnat0d580581995-07-20 02:43:20 -0500189typedef struct png_text_struct
190{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500191 int compression; /* compression value, see PNG_TEXT_COMPRESSION_ */
192 png_charp key; /* keyword, 1-79 character description of "text" */
193 png_charp text; /* comment, may be an empty string (ie "") */
194 png_size_t text_length; /* length of "text" field */
Guy Schalnat0d580581995-07-20 02:43:20 -0500195} png_text;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500196typedef png_text FAR * png_textp;
197typedef png_text FAR * FAR * png_textpp;
198
199/* Supported compression types for text in PNG files (tEXt, and zTXt).
200 * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */
201#define PNG_TEXT_COMPRESSION_NONE_WR -3
202#define PNG_TEXT_COMPRESSION_zTXt_WR -2
203#define PNG_TEXT_COMPRESSION_NONE -1
204#define PNG_TEXT_COMPRESSION_zTXt 0
205#define PNG_TEXT_COMPRESSION_LAST 1 /* Not a valid value */
Guy Schalnat0d580581995-07-20 02:43:20 -0500206
207/* png_time is a way to hold the time in an machine independent way.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600208 * Two conversions are provided, both from time_t and struct tm. There
209 * is no portable way to convert to either of these structures, as far
210 * as I know. If you know of a portable way, send it to me. As a side
211 * note - PNG is Year 2000 compliant!
212 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500213typedef struct png_time_struct
214{
215 png_uint_16 year; /* full year, as in, 1995 */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500216 png_byte month; /* month of year, 1 - 12 */
217 png_byte day; /* day of month, 1 - 31 */
218 png_byte hour; /* hour of day, 0 - 23 */
219 png_byte minute; /* minute of hour, 0 - 59 */
220 png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
Guy Schalnat0d580581995-07-20 02:43:20 -0500221} png_time;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500222typedef png_time FAR * png_timep;
223typedef png_time FAR * FAR * png_timepp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500224
Andreas Dilger47a0c421997-05-16 02:46:07 -0500225/* png_info is a structure that holds the information in a PNG file so
226 * that the application can find out the characteristics of the image.
227 * If you are reading the file, this structure will tell you what is
228 * in the PNG file. If you are writing the file, fill in the information
229 * you want to put into the PNG file, then call png_write_info().
230 * The names chosen should be very close to the PNG specification, so
231 * consult that document for information about the meaning of each field.
232 *
233 * With libpng < 0.95, it was only possible to directly set and read the
234 * the values in the png_info_struct, which meant that the contents and
235 * order of the values had to remain fixed. With libpng 0.95 and later,
236 * however, * there are now functions which abstract the contents of
237 * png_info_struct from the application, so this makes it easier to use
238 * libpng with dynamic libraries, and even makes it possible to use
239 * libraries that don't have all of the libpng ancillary chunk-handing
240 * functionality.
241 *
242 * In any case, the order of the parameters in png_info_struct should NOT
243 * be changed for as long as possible to keep compatibility with applications
244 * that use the old direct-access method with png_info_struct.
245 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500246typedef struct png_info_struct
247{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500248 /* the following are necessary for every PNG file */
249 png_uint_32 width; /* width of image in pixels (from IHDR) */
250 png_uint_32 height; /* height of image in pixels (from IHDR) */
251 png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600252 png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500253 png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
254 png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
255 png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
256 png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
257 png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
258 png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
259 png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
260 png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500261
Andreas Dilger47a0c421997-05-16 02:46:07 -0500262 /* The following is informational only on read, and not used on writes. */
263 png_byte channels; /* number of data channels per pixel (1, 3, 4)*/
264 png_byte pixel_depth; /* number of bits per pixel */
265 png_byte spare_byte; /* to align the data, and for future use */
266 png_byte signature[8]; /* magic bytes read by libpng from start of file */
267
268 /* The rest of the data is optional. If you are reading, check the
269 * valid field to see if the information in these are valid. If you
270 * are writing, set the valid field to those chunks you want written,
271 * and initialize the appropriate fields below.
272 */
273
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600274#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) || \
275 defined(PNG_READ_GAMMA_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500276 /* The gAMA chunk describes the gamma characteristics of the system
277 * on which the image was created, normally in the range [1.0, 2.5].
278 * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
279 */
280 float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
281#endif /* PNG_READ_gAMA_SUPPORTED || PNG_WRITE_gAMA_SUPPORTED */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600282
283#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
284 /* GR-P, 0.96a */
285 /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
286 png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
287#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
288
Guy Schalnate5a37791996-06-05 15:50:50 -0500289#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
290 defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500291 /* The tEXt and zTXt chunks contain human-readable textual data in
292 * uncompressed and compressed forms, respectively. The data in "text"
293 * is an array of pointers to uncompressed, null-terminated C strings.
294 * Each chunk has a keyword which describes the textual data contained
295 * in that chunk. Keywords are not required to be unique, and the text
296 * string may be empty. Any number of text chunks may be in an image.
297 */
298 int num_text; /* number of comments read/to write */
299 int max_text; /* current size of text array */
300 png_textp text; /* array of comments read/to write */
301#endif /* PNG_READ_tEXt/zTXt_SUPPORTED || PNG_WRITE_tEXt/zTXt_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500302#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500303 /* The tIME chunk holds the last time the displayed image data was
304 * modified. See the png_time struct for the contents of this struct.
305 */
306 png_time mod_time;
307#endif /* PNG_READ_tIME_SUPPORTED || PNG_WRITE_tIME_SUPPORTED */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500308#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500309 /* The sBIT chunk specifies the number of significant high-order bits
310 * in the pixel data. Values are in the range [1, bit_depth], and are
311 * only specified for the channels in the pixel data. The contents of
312 * the low-order bits is not specified. Data is valid if
313 * (valid & PNG_INFO_sBIT) is non-zero.
314 */
315 png_color_8 sig_bit; /* significant bits in color channels */
316#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500317#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500318 /* The tRNS chunk supplies transparency data for paletted images and
319 * other image types that don't need a full alpha channel. There are
320 * "num_trans" transparency values for a paletted image, stored in the
321 * same order as the palette colors, starting from index 0. Values
322 * for the data are in the range [0, 255], ranging from fully transparent
323 * to fully opaque, respectively. For non-paletted images, there is a
324 * single color specified which should be treated as fully transparent.
325 * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
326 */
327 png_bytep trans; /* transparent values for paletted image */
328 png_color_16 trans_values; /* transparent color for non-palette image */
329#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600330#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED) || \
331 defined(PNG_READ_BACKGROUND_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500332 /* The bKGD chunk gives the suggested image background color if the
333 * display program does not have its own background color and the image
334 * is needs to composited onto a background before display. The colors
335 * in "background" are normally in the same color space/depth as the
336 * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
337 */
338 png_color_16 background;
339#endif /* PNG_READ_bKGD_SUPPORTED || PNG_WRITE_bKGD_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500340#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500341 /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
342 * and downwards from the top-left corner of the display, page, or other
343 * application-specific co-ordinate space. See the PNG_OFFSET_ defines
344 * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
345 */
Guy Schalnate5a37791996-06-05 15:50:50 -0500346 png_uint_32 x_offset; /* x offset on page */
347 png_uint_32 y_offset; /* y offset on page */
348 png_byte offset_unit_type; /* offset units type */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500349#endif /* PNG_READ_oFFs_SUPPORTED || PNG_WRITE_oFFs_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500350#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500351 /* The pHYs chunk gives the physical pixel density of the image for
352 * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
353 * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
354 */
355 png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
356 png_uint_32 y_pixels_per_unit; /* vertical pixel density */
357 png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
358#endif /* PNG_READ_pHYs_SUPPORTED || PNG_WRITE_pHYs_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500359#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500360 /* The hIST chunk contains the relative frequency or importance of the
361 * various palette entries, so that a viewer can intelligently select a
362 * reduced-color palette, if required. Data is an array of "num_palette"
363 * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
364 * is non-zero.
365 */
366 png_uint_16p hist;
367#endif /* PNG_READ_hIST_SUPPORTED || PNG_WRITE_hIST_SUPPORTED */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500368#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500369 /* The cHRM chunk describes the CIE color characteristics of the monitor
370 * on which the PNG was created. This data allows the viewer to do gamut
371 * mapping of the input image to ensure that the viewer sees the same
372 * colors in the image as the creator. Values are in the range
373 * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
374 */
375 float x_white;
Guy Schalnat0d580581995-07-20 02:43:20 -0500376 float y_white;
377 float x_red;
378 float y_red;
379 float x_green;
380 float y_green;
381 float x_blue;
382 float y_blue;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500383#endif /* PNG_READ_cHRM_SUPPORTED || PNG_WRITE_cHRM_SUPPORTED */
384#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
385 /* The pCAL chunk describes a transformation between the stored pixel
386 * values and original physcical data values used to create the image.
387 * The integer range [0, 2^bit_depth - 1] maps to the floating-point
388 * range given by [pcal_X0, pcal_X1], and are further transformed by a
389 * (possibly non-linear) transformation function given by "pcal_type"
390 * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
391 * defines below, and the PNG-Group's Scientific Visualization extension
392 * chunks document png-scivis-19970203 for a complete description of the
393 * transformations and how they should be implemented, as well as the
394 * png-extensions document for a description of the ASCII parameter
395 * strings. Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
396 */
397 png_charp pcal_purpose; /* pCAL chunk description string */
398 png_int_32 pcal_X0; /* minimum value */
399 png_int_32 pcal_X1; /* maximum value */
400 png_charp pcal_units; /* Latin-1 string giving physical units */
401 png_charpp pcal_params; /* ASCII strings containing parameter values */
402 png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
403 png_byte pcal_nparams; /* number of parameters given in pcal_params */
404#endif /* PNG_READ_pCAL_SUPPORTED || PNG_WRITE_pCAL_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500405} png_info;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500406typedef png_info FAR * png_infop;
407typedef png_info FAR * FAR * png_infopp;
Guy Schalnat0d580581995-07-20 02:43:20 -0500408
Andreas Dilger47a0c421997-05-16 02:46:07 -0500409/* These describe the color_type field in png_info. */
Guy Schalnat0d580581995-07-20 02:43:20 -0500410/* color type masks */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500411#define PNG_COLOR_MASK_PALETTE 1
412#define PNG_COLOR_MASK_COLOR 2
413#define PNG_COLOR_MASK_ALPHA 4
Guy Schalnat0d580581995-07-20 02:43:20 -0500414
415/* color types. Note that not all combinations are legal */
Guy Schalnate5a37791996-06-05 15:50:50 -0500416#define PNG_COLOR_TYPE_GRAY 0
Andreas Dilger47a0c421997-05-16 02:46:07 -0500417#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
418#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
419#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
Guy Schalnat0d580581995-07-20 02:43:20 -0500420#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
421
Andreas Dilger47a0c421997-05-16 02:46:07 -0500422/* This is for compression type. PNG 1.0 only defines the single type. */
423#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
424#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
425
426/* This is for filter type. PNG 1.0 only defines the single type. */
427#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
428#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
429
430/* These are for the interlacing type. These values should NOT be changed. */
431#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
432#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
433#define PNG_INTERLACE_LAST 2 /* Not a valid value */
434
435/* These are for the oFFs chunk. These values should NOT be changed. */
436#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
437#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
438#define PNG_OFFSET_LAST 2 /* Not a valid value */
439
440/* These are for the pCAL chunk. These values should NOT be changed. */
441#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
442#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
443#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
444#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
445#define PNG_EQUATION_LAST 4 /* Not a valid value */
446
447/* These are for the pHYs chunk. These values should NOT be changed. */
448#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
449#define PNG_RESOLUTION_METER 1 /* pixels/meter */
450#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
451
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600452/* These are for the sRGB chunk. These values should NOT be changed. */
453#define PNG_sRGB_INTENT_SATURATION 0
454#define PNG_sRGB_INTENT_PERCEPTUAL 1
455#define PNG_sRGB_INTENT_ABSOLUTE 2
456#define PNG_sRGB_INTENT_RELATIVE 3
457#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
458
459
460
Andreas Dilger47a0c421997-05-16 02:46:07 -0500461/* These determine if an ancillary chunk's data has been successfully read
462 * from the PNG header, or if the application has filled in the corresponding
463 * data in the info_struct to be written into the output file. The values
464 * of the PNG_INFO_<chunk> defines should NOT be changed.
465 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500466#define PNG_INFO_gAMA 0x0001
467#define PNG_INFO_sBIT 0x0002
468#define PNG_INFO_cHRM 0x0004
469#define PNG_INFO_PLTE 0x0008
470#define PNG_INFO_tRNS 0x0010
471#define PNG_INFO_bKGD 0x0020
472#define PNG_INFO_hIST 0x0040
473#define PNG_INFO_pHYs 0x0080
474#define PNG_INFO_oFFs 0x0100
475#define PNG_INFO_tIME 0x0200
Andreas Dilger47a0c421997-05-16 02:46:07 -0500476#define PNG_INFO_pCAL 0x0400
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600477#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
Guy Schalnat0d580581995-07-20 02:43:20 -0500478
Andreas Dilger47a0c421997-05-16 02:46:07 -0500479/* This is used for the transformation routines, as some of them
480 * change these values for the row. It also should enable using
481 * the routines for other purposes.
482 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500483typedef struct png_row_info_struct
484{
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600485 png_uint_32 width; /* width of row */
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600486 png_uint_32 rowbytes; /* number of bytes in row */
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600487 png_byte color_type; /* color type of row */
488 png_byte bit_depth; /* bit depth of row */
489 png_byte channels; /* number of channels (1, 2, 3, or 4) */
490 png_byte pixel_depth; /* bits per pixel (depth * channels) */
Guy Schalnat0d580581995-07-20 02:43:20 -0500491} png_row_info;
492
Andreas Dilger47a0c421997-05-16 02:46:07 -0500493typedef png_row_info FAR * png_row_infop;
494typedef png_row_info FAR * FAR * png_row_infopp;
Guy Schalnat0f716451995-11-28 11:22:13 -0600495
496/* These are the function types for the I/O functions, and the functions which
Guy Schalnate5a37791996-06-05 15:50:50 -0500497 * modify the default I/O functions to user I/O functions. The png_error_ptr
Guy Schalnat0f716451995-11-28 11:22:13 -0600498 * type should match that of user supplied warning and error functions, while
499 * the png_rw_ptr type should match that of the user read/write data functions.
500 */
Guy Schalnat6d764711995-12-19 03:22:19 -0600501typedef struct png_struct_def png_struct;
502typedef png_struct FAR * png_structp;
Guy Schalnat0f716451995-11-28 11:22:13 -0600503
Guy Schalnate5a37791996-06-05 15:50:50 -0500504typedef void (*png_error_ptr) PNGARG((png_structp, png_const_charp));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500505typedef void (*png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
Guy Schalnat6d764711995-12-19 03:22:19 -0600506typedef void (*png_flush_ptr) PNGARG((png_structp));
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600507typedef void (*png_read_status_ptr) PNGARG((png_structp, png_uint_32, int));
508typedef void (*png_write_status_ptr) PNGARG((png_structp, png_uint_32, int));
Guy Schalnat69b14481996-01-10 02:56:49 -0600509#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Guy Schalnat6d764711995-12-19 03:22:19 -0600510typedef void (*png_progressive_info_ptr) PNGARG((png_structp, png_infop));
511typedef void (*png_progressive_end_ptr) PNGARG((png_structp, png_infop));
512typedef void (*png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600513 png_uint_32, int));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500514#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
Guy Schalnat6d764711995-12-19 03:22:19 -0600515
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600516#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
517 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
518typedef void (*png_user_transform_ptr) PNGARG((png_structp,
519 png_row_infop, png_bytep));
520#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
521
Andreas Dilger47a0c421997-05-16 02:46:07 -0500522/* The structure that holds the information to read and write PNG files.
523 * The only people who need to care about what is inside of this are the
524 * people who will be modifying the library for their own special needs.
525 * It should NOT be accessed directly by an application, except to store
526 * the jmp_buf.
527 */
Guy Schalnat6d764711995-12-19 03:22:19 -0600528
Guy Schalnat69b14481996-01-10 02:56:49 -0600529struct png_struct_def
Guy Schalnat0d580581995-07-20 02:43:20 -0500530{
Andreas Dilger47a0c421997-05-16 02:46:07 -0500531 jmp_buf jmpbuf; /* used in png_error */
Guy Schalnate5a37791996-06-05 15:50:50 -0500532
Andreas Dilger47a0c421997-05-16 02:46:07 -0500533 png_error_ptr error_fn; /* function for printing errors and aborting */
534 png_error_ptr warning_fn; /* function for printing warnings */
Guy Schalnate5a37791996-06-05 15:50:50 -0500535 png_voidp error_ptr; /* user supplied struct for error functions */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500536 png_rw_ptr write_data_fn; /* function for writing output data */
537 png_rw_ptr read_data_fn; /* function for reading input data */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600538#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
539 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
540 png_user_transform_ptr read_user_transform_fn; /* user read transform */
541 png_user_transform_ptr write_user_transform_fn; /* user write transform */
542#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500543 png_voidp io_ptr; /* ptr to application struct for I/O functions*/
Guy Schalnate5a37791996-06-05 15:50:50 -0500544
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600545 png_uint_32 mode; /* tells us where we are in the PNG file */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500546 png_uint_32 flags; /* flags indicating various things to libpng */
Guy Schalnate5a37791996-06-05 15:50:50 -0500547 png_uint_32 transformations; /* which transformations to perform */
548
Andreas Dilger47a0c421997-05-16 02:46:07 -0500549 z_stream zstream; /* pointer to decompression structure (below) */
550 png_bytep zbuf; /* buffer for zlib */
551 png_size_t zbuf_size; /* size of zbuf */
552 int zlib_level; /* holds zlib compression level */
553 int zlib_method; /* holds zlib compression method */
554 int zlib_window_bits; /* holds zlib compression window bits */
555 int zlib_mem_level; /* holds zlib compression memory level */
556 int zlib_strategy; /* holds zlib compression strategy */
Guy Schalnate5a37791996-06-05 15:50:50 -0500557
Andreas Dilger47a0c421997-05-16 02:46:07 -0500558 png_uint_32 width; /* width of image in pixels */
559 png_uint_32 height; /* height of image in pixels */
560 png_uint_32 num_rows; /* number of rows in current pass */
561 png_uint_32 usr_width; /* width of row at start of write */
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600562 png_uint_32 rowbytes; /* size of row in bytes */
563 png_uint_32 irowbytes; /* size of current interlaced row in bytes */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500564 png_uint_32 iwidth; /* width of current interlaced row in pixels */
565 png_uint_32 row_number; /* current row in interlace pass */
566 png_bytep prev_row; /* buffer to save previous (unfiltered) row */
567 png_bytep row_buf; /* buffer to save current (unfiltered) row */
568 png_bytep sub_row; /* buffer to save "sub" row when filtering */
569 png_bytep up_row; /* buffer to save "up" row when filtering */
570 png_bytep avg_row; /* buffer to save "avg" row when filtering */
571 png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
572 png_row_info row_info; /* used for transformation routines */
Guy Schalnate5a37791996-06-05 15:50:50 -0500573
Andreas Dilger47a0c421997-05-16 02:46:07 -0500574 png_uint_32 idat_size; /* current IDAT size for read */
575 png_uint_32 crc; /* current chunk CRC value */
576 png_colorp palette; /* palette from the input file */
577 png_uint_16 num_palette; /* number of color entries in palette */
578 png_uint_16 num_trans; /* number of transparency values */
579 png_byte chunk_name[5]; /* null-terminated name of current chunk */
580 png_byte compression; /* file compression type (always 0) */
581 png_byte filter; /* file filter type (always 0) */
582 png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
583 png_byte pass; /* current interlace pass (0 - 6) */
584 png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
585 png_byte color_type; /* color type of file */
586 png_byte bit_depth; /* bit depth of file */
587 png_byte usr_bit_depth; /* bit depth of users row */
588 png_byte pixel_depth; /* number of bits per pixel */
589 png_byte channels; /* number of channels in file */
590 png_byte usr_channels; /* channels at start of write */
591 png_byte sig_bytes; /* magic bytes read/written from start of file */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600592
Guy Schalnate5a37791996-06-05 15:50:50 -0500593#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500594 png_uint_16 filler; /* filler bytes for pixel expansion */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500595#endif /* PNG_READ_FILLER_SUPPORTED */
596#if defined(PNG_READ_bKGD_SUPPORTED)
Guy Schalnate5a37791996-06-05 15:50:50 -0500597 png_byte background_gamma_type;
598 float background_gamma;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500599 png_color_16 background; /* background color in screen gamma space */
Guy Schalnate5a37791996-06-05 15:50:50 -0500600#if defined(PNG_READ_GAMMA_SUPPORTED)
601 png_color_16 background_1; /* background normalized to gamma 1.0 */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500602#endif /* PNG_READ_GAMMA && PNG_READ_bKGD_SUPPORTED */
603#endif /* PNG_READ_bKGD_SUPPORTED */
Guy Schalnat6d764711995-12-19 03:22:19 -0600604#if defined(PNG_WRITE_FLUSH_SUPPORTED)
Guy Schalnate5a37791996-06-05 15:50:50 -0500605 png_flush_ptr output_flush_fn;/* Function for flushing output */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500606 png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
607 png_uint_32 flush_rows; /* number of rows written since last flush */
Guy Schalnat6d764711995-12-19 03:22:19 -0600608#endif /* PNG_WRITE_FLUSH_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500609#if defined(PNG_READ_GAMMA_SUPPORTED)
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600610 int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
611 float gamma; /* file gamma value */
612 float screen_gamma; /* screen gamma value (display_gamma/viewing_gamma */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500613#endif /* PNG_READ_GAMMA_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500614#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500615 png_bytep gamma_table; /* gamma table for 8 bit depth files */
616 png_bytep gamma_from_1; /* converts from 1.0 to screen */
617 png_bytep gamma_to_1; /* converts from file to 1.0 */
Guy Schalnate5a37791996-06-05 15:50:50 -0500618 png_uint_16pp gamma_16_table; /* gamma table for 16 bit depth files */
619 png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
620 png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500621#endif /* PNG_READ_GAMMA_SUPPORTED || PNG_WRITE_GAMMA_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500622#if defined(PNG_READ_GAMMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500623 png_color_8 sig_bit; /* significant bits in each available channel */
624#endif /* PNG_READ_GAMMA_SUPPORTED || PNG_READ_sBIT_SUPPORTED */
Guy Schalnate5a37791996-06-05 15:50:50 -0500625#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500626 png_color_8 shift; /* shift for significant bit tranformation */
627#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
628#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
629 png_bytep trans; /* transparency values for paletted files */
630 png_color_16 trans_values; /* transparency values for non-paletted files */
631#endif /* PNG_READ_tRNS_SUPPORTED || PNG_READ_BACKGROUND_SUPPORTED */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600632 png_read_status_ptr read_row_fn; /* called after each row is decoded */
633 png_write_status_ptr write_row_fn; /* called after each row is encoded */
Guy Schalnat6d764711995-12-19 03:22:19 -0600634#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -0500635 png_progressive_info_ptr info_fn; /* called after header data fully read */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600636 png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500637 png_progressive_end_ptr end_fn; /* called after image is complete */
638 png_bytep save_buffer_ptr; /* current location in save_buffer */
639 png_bytep save_buffer; /* buffer for previously read data */
640 png_bytep current_buffer_ptr; /* current location in current_buffer */
641 png_bytep current_buffer; /* buffer for recently used data */
642 png_uint_32 push_length; /* size of current input chunk */
643 png_uint_32 skip_length; /* bytes to skip in input data */
644 png_size_t save_buffer_size; /* amount of data now in save_buffer */
645 png_size_t save_buffer_max; /* total size of save_buffer */
646 png_size_t buffer_size; /* total amount of available input data */
647 png_size_t current_buffer_size; /* amount of data now in current_buffer */
648 int process_mode; /* what push library is currently doing */
649 int cur_palette; /* current push library palette index */
Guy Schalnat6d764711995-12-19 03:22:19 -0600650#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500651 png_size_t current_text_size; /* current size of text input data */
652 png_size_t current_text_left; /* how much text left to read in input */
653 png_charp current_text; /* current text chunk buffer */
654 png_charp current_text_ptr; /* current location in current_text */
655#endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_tEXt/zTXt_SUPPORTED */
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600656#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600657#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
658/* for the Borland special 64K segment handler */
659 png_bytepp offset_table_ptr;
660 png_bytep offset_table;
661 png_uint_16 offset_table_number;
662 png_uint_16 offset_table_count;
663 png_uint_16 offset_table_count_free;
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600664#endif /* __TURBOC__&&!_Windows&&!__FLAT__ */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500665#if defined(PNG_READ_DITHER_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500666 png_bytep palette_lookup; /* lookup table for dithering */
667 png_bytep dither_index; /* index translation for palette files */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500668#endif /* PNG_READ_DITHER_SUPPORTED */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600669#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED)
670 png_uint_16p hist; /* histogram */
671#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500672#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
673 png_byte heuristic_method; /* heuristic for row filter selection */
674 png_byte num_prev_filters; /* number of weights for previous rows */
675 png_bytep prev_filters; /* filter type(s) of previous row(s) */
676 png_uint_16p filter_weights; /* weight(s) for previous line(s) */
677 png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
678 png_uint_16p filter_costs; /* relative filter calculation cost */
679 png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
680#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600681#if defined(PNG_TIME_RFC1123_SUPPORTED)
682 png_charp time_buffer; /* String to hold RFC 1123 time text */
683#endif /* PNG_TIME_RFC1123_SUPPORTED */
Guy Schalnat0f716451995-11-28 11:22:13 -0600684};
Guy Schalnat0d580581995-07-20 02:43:20 -0500685
Andreas Dilger47a0c421997-05-16 02:46:07 -0500686typedef png_struct FAR * FAR * png_structpp;
Guy Schalnat6d764711995-12-19 03:22:19 -0600687
Guy Schalnat0d580581995-07-20 02:43:20 -0500688/* Here are the function definitions most commonly used. This is not
Andreas Dilger47a0c421997-05-16 02:46:07 -0500689 * the place to find out how to use libpng. See libpng.txt for the
690 * full explanation, see example.c for the summary. This just provides
691 * a simple one line of the use of each function.
692 */
Guy Schalnat0d580581995-07-20 02:43:20 -0500693
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600694/* Tell lib we have already handled the first <num_bytes> magic bytes.
Andreas Dilger47a0c421997-05-16 02:46:07 -0500695 * Handling more than 8 bytes from the beginning of the file is an error.
696 */
697extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
698 int num_bytes));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600699
Andreas Dilger47a0c421997-05-16 02:46:07 -0500700/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
701 * PNG file. Returns zero if the supplied bytes match the 8-byte PNG
702 * signature, and non-zero otherwise. Having num_to_check == 0 or
703 * start > 7 will always fail (ie return non-zero).
704 */
705extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
706 png_size_t num_to_check));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600707
Andreas Dilger47a0c421997-05-16 02:46:07 -0500708/* Simple signature checking function. This is the same as calling
709 * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
710 */
711extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
Guy Schalnat0d580581995-07-20 02:43:20 -0500712
Andreas Dilger47a0c421997-05-16 02:46:07 -0500713/* Allocate and initialize png_ptr struct for reading, and any other memory. */
714extern PNG_EXPORT(png_structp,png_create_read_struct)
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -0500715 PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600716 png_error_ptr error_fn, png_error_ptr warn_fn));
Guy Schalnat0d580581995-07-20 02:43:20 -0500717
Andreas Dilger47a0c421997-05-16 02:46:07 -0500718/* Allocate and initialize png_ptr struct for reading, and any other memory */
719extern PNG_EXPORT(png_structp,png_create_write_struct)
Glenn Randers-Pehrsond0dce401998-05-09 10:02:29 -0500720 PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600721 png_error_ptr error_fn, png_error_ptr warn_fn));
Guy Schalnate5a37791996-06-05 15:50:50 -0500722
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600723/* Write a PNG chunk - size, type, (optional) data, CRC. */
724extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
725 png_bytep chunk_name, png_bytep data, png_size_t length));
726
727/* Write the start of a PNG chunk - length and chunk name. */
728extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
729 png_bytep chunk_name, png_uint_32 length));
730
731/* Write the data of a PNG chunk started with png_write_chunk_start(). */
732extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
733 png_bytep data, png_size_t length));
734
735/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
736extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
737
Andreas Dilger47a0c421997-05-16 02:46:07 -0500738/* Allocate and initialize the info structure */
739extern PNG_EXPORT(png_infop,png_create_info_struct)
740 PNGARG((png_structp png_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500741
Andreas Dilger47a0c421997-05-16 02:46:07 -0500742/* Initialize the info structure (old interface - NOT DLL EXPORTED) */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600743extern void png_info_init PNGARG((png_infop info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500744
Andreas Dilger47a0c421997-05-16 02:46:07 -0500745/* Writes all the PNG information before the image. */
746extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
747 png_infop info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500748
749/* read the information before the actual image data. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500750extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
751 png_infop info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500752
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600753#if defined(PNG_TIME_RFC1123_SUPPORTED)
754extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600755 PNGARG((png_structp png_ptr, png_timep ptime));
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600756#endif /* PNG_TIME_RFC1123_SUPPORTED */
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600757
Guy Schalnat0f716451995-11-28 11:22:13 -0600758#if defined(PNG_WRITE_tIME_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500759/* convert from a struct tm to png_time */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500760extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
Guy Schalnate5a37791996-06-05 15:50:50 -0500761 struct tm FAR * ttime));
Guy Schalnat0d580581995-07-20 02:43:20 -0500762
763/* convert from time_t to png_time. Uses gmtime() */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500764extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
765 time_t ttime));
766#endif /* PNG_WRITE_tIME_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500767
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500768#if defined(PNG_READ_EXPAND_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500769/* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha if available. */
770extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
771#endif /* PNG_READ_EXPAND_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500772
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500773#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500774/* Use blue, green, red order for pixels. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500775extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
776#endif /* PNG_READ_BGR_SUPPORTED || PNG_WRITE_BGR_SUPPORTED */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500777
Guy Schalnat69b14481996-01-10 02:56:49 -0600778#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
779/* Expand the grayscale to 24 bit RGB if necessary. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500780extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
781#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
Guy Schalnat69b14481996-01-10 02:56:49 -0600782
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600783#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
784/* Reduce RGB to grayscale. (Not yet implemented) */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500785extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr));
786#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600787
Andreas Dilger47a0c421997-05-16 02:46:07 -0500788extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600789 png_colorp palette));
790
Andreas Dilger47a0c421997-05-16 02:46:07 -0500791#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
792extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
793#endif /* PNG_READ_STRIP_ALPHA_SUPPORTED */
794
795#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
796 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
797extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
798#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED || PNG_WRITE_SWAP_ALPHA_SUPPORTED */
799
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600800#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
801 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
802extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
803#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED || PNG_WRITE_INVERT_ALPHA_SUPPORTED */
804
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500805#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500806/* Add a filler byte to 24-bit RGB images. */
807extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
808 png_uint_32 filler, int flags));
809
810/* The values of the PNG_FILLER_ defines should NOT be changed */
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500811#define PNG_FILLER_BEFORE 0
812#define PNG_FILLER_AFTER 1
Andreas Dilger47a0c421997-05-16 02:46:07 -0500813#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500814
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500815#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500816/* Swap bytes in 16 bit depth files. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500817extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
818#endif /* PNG_READ_SWAP_SUPPORTED || PNG_WRITE_SWAP_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500819
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500820#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500821/* Use 1 byte per pixel in 1, 2, or 4 bit depth files. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500822extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
823#endif /* PNG_READ_PACK_SUPPORTED || PNG_WRITE_PACK_SUPPORTED */
824
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -0600825#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500826/* Swap packing order of pixels in bytes. */
827extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
828#endif /* PNG_READ_PACKSWAP_SUPPORTED || PNG_WRITE_PACKSWAP_SUPPOR */
Guy Schalnat0d580581995-07-20 02:43:20 -0500829
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500830#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500831/* Converts files to legal bit depths. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500832extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
Guy Schalnat6d764711995-12-19 03:22:19 -0600833 png_color_8p true_bits));
Andreas Dilger47a0c421997-05-16 02:46:07 -0500834#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500835
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500836#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
837 defined(PNG_WRITE_INTERLACING_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500838/* Have the code handle the interlacing. Returns the number of passes. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500839extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
840#endif /* PNG_READ_INTERLACING_SUPPORTED || PNG_WRITE_INTERLACING_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500841
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500842#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500843/* Invert monocrome files */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500844extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
845#endif /* PNG_READ_INVERT_SUPPORTED || PNG_WRITE_INVERT_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500846
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500847#if defined(PNG_READ_BACKGROUND_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500848/* Handle alpha and tRNS by replacing with a background color. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500849extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
850 png_color_16p background_color, int background_gamma_code,
851 int need_expand, double background_gamma));
Guy Schalnate5a37791996-06-05 15:50:50 -0500852#define PNG_BACKGROUND_GAMMA_UNKNOWN 0
853#define PNG_BACKGROUND_GAMMA_SCREEN 1
854#define PNG_BACKGROUND_GAMMA_FILE 2
855#define PNG_BACKGROUND_GAMMA_UNIQUE 3
Andreas Dilger47a0c421997-05-16 02:46:07 -0500856#endif /* PNG_READ_BACKGROUND_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500857
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500858#if defined(PNG_READ_16_TO_8_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500859/* strip the second byte of information from a 16 bit depth file. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500860extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
861#endif /* PNG_READ_16_TO_8_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500862
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500863#if defined(PNG_READ_DITHER_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -0500864/* Turn on dithering, and reduce the palette to the number of colors available. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500865extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
866 png_colorp palette, int num_palette, int maximum_colors,
867 png_uint_16p histogram, int full_dither));
868#endif /* PNG_READ_DITHER_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500869
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500870#if defined(PNG_READ_GAMMA_SUPPORTED)
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600871/* Handle gamma correction. Screen_gamma=(display_gamma/viewing_gamma) */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500872extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
873 double screen_gamma, double default_file_gamma));
874#endif /* PNG_READ_GAMMA_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -0500875
Guy Schalnat0f716451995-11-28 11:22:13 -0600876#if defined(PNG_WRITE_FLUSH_SUPPORTED)
877/* Set how many lines between output flushes - 0 for no flushing */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500878extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
Guy Schalnat0f716451995-11-28 11:22:13 -0600879
880/* Flush the current PNG output buffer */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500881extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
Guy Schalnat0f716451995-11-28 11:22:13 -0600882#endif /* PNG_WRITE_FLUSH_SUPPORTED */
883
Guy Schalnat0d580581995-07-20 02:43:20 -0500884/* optional update palette with requested transformations */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500885extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500886
887/* optional call to update the users info structure */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500888extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600889 png_infop info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500890
891/* read a one or more rows of image data.*/
Andreas Dilger47a0c421997-05-16 02:46:07 -0500892extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
893 png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
Guy Schalnat0d580581995-07-20 02:43:20 -0500894
895/* read a row of data.*/
Andreas Dilger47a0c421997-05-16 02:46:07 -0500896extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600897 png_bytep row,
898 png_bytep display_row));
Guy Schalnat0d580581995-07-20 02:43:20 -0500899
900/* read the whole image into memory at once. */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500901extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600902 png_bytepp image));
Guy Schalnat0d580581995-07-20 02:43:20 -0500903
904/* write a row of image data */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500905extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -0600906 png_bytep row));
Guy Schalnat0d580581995-07-20 02:43:20 -0500907
908/* write a few rows of image data */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500909extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
910 png_bytepp row, png_uint_32 num_rows));
Guy Schalnat0d580581995-07-20 02:43:20 -0500911
912/* write the image data */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500913extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
914 png_bytepp image));
Guy Schalnat0d580581995-07-20 02:43:20 -0500915
Andreas Dilger47a0c421997-05-16 02:46:07 -0500916/* writes the end of the PNG file. */
917extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
918 png_infop info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500919
Andreas Dilger47a0c421997-05-16 02:46:07 -0500920/* read the end of the PNG file. */
921extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
922 png_infop info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500923
Andreas Dilger47a0c421997-05-16 02:46:07 -0500924/* free any memory associated with the png_info_struct */
925extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600926 png_infopp info_ptr_ptr));
Guy Schalnate5a37791996-06-05 15:50:50 -0500927
Andreas Dilger47a0c421997-05-16 02:46:07 -0500928/* free any memory associated with the png_struct and the png_info_structs */
929extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
930 png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
Guy Schalnate5a37791996-06-05 15:50:50 -0500931
Andreas Dilger47a0c421997-05-16 02:46:07 -0500932/* free all memory used by the read (old method - NOT DLL EXPORTED) */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600933extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
934 png_infop end_info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500935
Andreas Dilger47a0c421997-05-16 02:46:07 -0500936/* free any memory associated with the png_struct and the png_info_structs */
937extern PNG_EXPORT(void,png_destroy_write_struct)
938 PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
Guy Schalnate5a37791996-06-05 15:50:50 -0500939
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600940/* free any memory used in info_ptr struct (old method - NOT DLL EXPORTED) */
941extern void png_write_destroy_info PNGARG((png_infop info_ptr));
942
Andreas Dilger47a0c421997-05-16 02:46:07 -0500943/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
Guy Schalnat6d764711995-12-19 03:22:19 -0600944extern void png_write_destroy PNGARG((png_structp png_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -0500945
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600946/* set the libpng method of handling chunk CRC errors */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500947extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
948 int crit_action, int ancil_action));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600949
950/* Values for png_set_crc_action() to say how to handle CRC errors in
Andreas Dilger47a0c421997-05-16 02:46:07 -0500951 * ancillary and critical chunks, and whether to use the data contained
952 * therein. Note that it is impossible to "discard" data in a critical
953 * chunk. For versions prior to 0.90, the action was always error/quit,
954 * whereas in version 0.90 and later, the action for CRC errors in ancillary
955 * chunks is warn/discard. These values should NOT be changed.
956 *
957 * value action:critical action:ancillary
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600958 */
959#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
960#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
961#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
962#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
963#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
964#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
965
Andreas Dilger47a0c421997-05-16 02:46:07 -0500966/* These functions give the user control over the scan-line filtering in
967 * libpng and the compression methods used by zlib. These functions are
968 * mainly useful for testing, as the defaults should work with most users.
969 * Those users who are tight on memory or want faster performance at the
970 * expense of compression can modify them. See the compression library
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600971 * header file (zlib.h) for an explination of the compression functions.
972 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600973
Andreas Dilger47a0c421997-05-16 02:46:07 -0500974/* set the filtering method(s) used by libpng. Currently, the only valid
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600975 * value for "method" is 0.
976 */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500977extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
Guy Schalnate5a37791996-06-05 15:50:50 -0500978 int filters));
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500979
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600980/* Flags for png_set_filter() to say which filters to use. The flags
Andreas Dilger47a0c421997-05-16 02:46:07 -0500981 * are chosen so that they don't conflict with real filter types
982 * below, in case they are supplied instead of the #defined constants.
983 * These values should NOT be changed.
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600984 */
985#define PNG_NO_FILTERS 0x00
986#define PNG_FILTER_NONE 0x08
987#define PNG_FILTER_SUB 0x10
988#define PNG_FILTER_UP 0x20
989#define PNG_FILTER_AVG 0x40
990#define PNG_FILTER_PAETH 0x80
991#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
992 PNG_FILTER_AVG | PNG_FILTER_PAETH)
993
Andreas Dilger47a0c421997-05-16 02:46:07 -0500994/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
995 * These defines should NOT be changed.
996 */
997#define PNG_FILTER_VALUE_NONE 0
998#define PNG_FILTER_VALUE_SUB 1
999#define PNG_FILTER_VALUE_UP 2
1000#define PNG_FILTER_VALUE_AVG 3
1001#define PNG_FILTER_VALUE_PAETH 4
1002#define PNG_FILTER_VALUE_LAST 5
1003
1004#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
1005/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
1006 * defines, either the default (minimum-sum-of-absolute-differences), or
1007 * the experimental method (weighted-minimum-sum-of-absolute-differences).
1008 *
1009 * Weights are factors >= 1.0, indicating how important it is to keep the
1010 * filter type consistent between rows. Larger numbers mean the current
1011 * filter is that many times as likely to be the same as the "num_weights"
1012 * previous filters. This is cumulative for each previous row with a weight.
1013 * There needs to be "num_weights" values in "filter_weights", or it can be
1014 * NULL if the weights aren't being specified. Weights have no influence on
1015 * the selection of the first row filter. Well chosen weights can (in theory)
1016 * improve the compression for a given image.
1017 *
1018 * Costs are factors >= 1.0 indicating the relative decoding costs of a
1019 * filter type. Higher costs indicate more decoding expense, and are
1020 * therefore less likely to be selected over a filter with lower computational
1021 * costs. There needs to be a value in "filter_costs" for each valid filter
1022 * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't
1023 * setting the costs. Costs try to improve the speed of decompression without
1024 * unduly increasing the compressed image size.
1025 *
1026 * A negative weight or cost indicates the default value is to be used, and
1027 * values in the range [0.0, 1.0) indicate the value is to remain unchanged.
1028 * The default values for both weights and costs are currently 1.0, but may
1029 * change if good general weighting/cost heuristics can be found. If both
1030 * the weights and costs are set to 1.0, this degenerates the WEIGHTED method
1031 * to the UNWEIGHTED method, but with added encoding time/computation.
1032 */
1033extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
1034 int heuristic_method, int num_weights, png_doublep filter_weights,
1035 png_doublep filter_costs));
1036#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
1037
1038/* Heuristic used for row filter selection. These defines should NOT be
1039 * changed.
1040 */
1041#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
1042#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
1043#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
1044#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
1045
1046/* Set the library compression level. Currently, valid values range from
1047 * 0 - 9, corresponding directly to the zlib compression levels 0 - 9
1048 * (0 - no compression, 9 - "maximal" compression). Note that tests have
1049 * shown that zlib compression levels 3-6 usually perform as well as level 9
1050 * for PNG images, and do considerably fewer caclulations. In the future,
1051 * these values may not correspond directly to the zlib compression levels.
1052 */
1053extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001054 int level));
1055
Andreas Dilger47a0c421997-05-16 02:46:07 -05001056extern PNG_EXPORT(void,png_set_compression_mem_level)
1057 PNGARG((png_structp png_ptr, int mem_level));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001058
Andreas Dilger47a0c421997-05-16 02:46:07 -05001059extern PNG_EXPORT(void,png_set_compression_strategy)
1060 PNGARG((png_structp png_ptr, int strategy));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001061
Andreas Dilger47a0c421997-05-16 02:46:07 -05001062extern PNG_EXPORT(void,png_set_compression_window_bits)
1063 PNGARG((png_structp png_ptr, int window_bits));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001064
Andreas Dilger47a0c421997-05-16 02:46:07 -05001065extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001066 int method));
Guy Schalnat0d580581995-07-20 02:43:20 -05001067
Guy Schalnate5a37791996-06-05 15:50:50 -05001068/* These next functions are called for input/output, memory, and error
Andreas Dilger47a0c421997-05-16 02:46:07 -05001069 * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c,
1070 * and call standard C I/O routines such as fread(), fwrite(), and
1071 * fprintf(). These functions can be made to use other I/O routines
1072 * at run time for those applications that need to handle I/O in a
1073 * different manner by calling png_set_???_fn(). See libpng.txt for
1074 * more information.
1075 */
Guy Schalnat0d580581995-07-20 02:43:20 -05001076
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001077#if !defined(PNG_NO_STDIO)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001078/* Initialize the input/output for the PNG file to the default functions. */
1079extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, FILE *fp));
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001080#endif
Guy Schalnat6d764711995-12-19 03:22:19 -06001081
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001082/* Replace the (error and abort), and warning functions with user
Andreas Dilger47a0c421997-05-16 02:46:07 -05001083 * supplied functions. If no messages are to be printed you must still
1084 * write and use replacement functions. The replacement error_fn should
1085 * still do a longjmp to the last setjmp location if you are using this
1086 * method of error handling. If error_fn or warning_fn is NULL, the
1087 * default function will be used.
1088 */
1089extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
1090 png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
Guy Schalnat6d764711995-12-19 03:22:19 -06001091
Guy Schalnate5a37791996-06-05 15:50:50 -05001092/* Return the user pointer associated with the error functions */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001093extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
Guy Schalnat6d764711995-12-19 03:22:19 -06001094
1095/* Replace the default data output functions with a user supplied one(s).
Andreas Dilger47a0c421997-05-16 02:46:07 -05001096 * If buffered output is not used, then output_flush_fn can be set to NULL.
1097 * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
1098 * output_flush_fn will be ignored (and thus can be NULL).
1099 */
1100extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
1101 png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
Guy Schalnat6d764711995-12-19 03:22:19 -06001102
1103/* Replace the default data input function with a user supplied one. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001104extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
1105 png_voidp io_ptr, png_rw_ptr read_data_fn));
Guy Schalnat6d764711995-12-19 03:22:19 -06001106
1107/* Return the user pointer associated with the I/O functions */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001108extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
Guy Schalnat6d764711995-12-19 03:22:19 -06001109
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001110extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
1111 png_read_status_ptr read_row_fn));
1112
1113extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
1114 png_write_status_ptr write_row_fn));
1115
1116#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1117extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
1118 png_ptr, png_user_transform_ptr read_user_transform_fn));
1119#endif
1120
1121#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1122extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
1123 png_ptr, png_user_transform_ptr write_user_transform_fn));
1124#endif
1125
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001126#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -05001127/* Sets the function callbacks for the push reader, and a pointer to a
1128 * user-defined structure available to the callback functions.
1129 */
1130extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
1131 png_voidp progressive_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001132 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
1133 png_progressive_end_ptr end_fn));
Guy Schalnat6d764711995-12-19 03:22:19 -06001134
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001135/* returns the user pointer associated with the push read functions */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001136extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
1137 PNGARG((png_structp png_ptr));
1138
1139/* function to be called when data becomes available */
1140extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
1141 png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
1142
1143/* function which combines rows. Not very much different than the
1144 * png_combine_row() call. Is this even used?????
1145 */
1146extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
1147 png_bytep old_row, png_bytep new_row));
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001148#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
Guy Schalnat6d764711995-12-19 03:22:19 -06001149
Andreas Dilger47a0c421997-05-16 02:46:07 -05001150extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001151 png_uint_32 size));
Guy Schalnat0d580581995-07-20 02:43:20 -05001152
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001153/* frees a pointer allocated by png_malloc() */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001154extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
Guy Schalnate5a37791996-06-05 15:50:50 -05001155
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001156extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06001157 png_voidp s1, png_voidp s2, png_uint_32 size));
1158
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001159extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06001160 png_voidp s1, int value, png_uint_32 size));
1161
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001162#ifdef PNGTEST_MEMORY_DEBUG
1163/* debugging versions of png_malloc() and png_free() */
1164extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
1165 png_uint_32 size));
1166extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
1167 png_voidp ptr));
1168#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -05001169#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001170extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
1171 int check));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001172#endif /* USE_FAR_KEYWORD */
1173
1174/* Fatal error in PNG image of libpng - can't continue */
1175extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
1176 png_const_charp error));
Guy Schalnat0d580581995-07-20 02:43:20 -05001177
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001178/* The same, but the chunk name is prepended to the error string. */
1179extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
1180 png_const_charp error));
1181
Guy Schalnat6d764711995-12-19 03:22:19 -06001182/* Non-fatal error in libpng. Can continue, but may have a problem. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001183extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
1184 png_const_charp message));
Guy Schalnat0d580581995-07-20 02:43:20 -05001185
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001186/* Non-fatal error in libpng, chunk name is prepended to message. */
1187extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
1188 png_const_charp message));
1189
Andreas Dilger47a0c421997-05-16 02:46:07 -05001190/* The png_set_<chunk> functions are for storing values in the png_info_struct.
1191 * Similarly, the png_get_<chunk> calls are used to read values from the
1192 * png_info_struct, either storing the parameters in the passed variables, or
1193 * setting pointers into the png_info_struct where the data is stored. The
1194 * png_get_<chunk> functions return a non-zero value if the data was available
1195 * in info_ptr, or return zero and do not change any of the parameters if the
1196 * data was not available.
1197 *
1198 * These functions should be used instead of directly accessing png_info
1199 * to avoid problems with future changes in the size and internal layout of
1200 * png_info_struct.
1201 */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001202/* Returns "flag" if chunk data is valid in info_ptr. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001203extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
1204png_infop info_ptr, png_uint_32 flag));
1205
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001206/* Returns number of bytes needed to hold a transformed row. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001207extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
1208png_infop info_ptr));
1209
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001210/* Returns number of color channels in image. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001211extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
1212png_infop info_ptr));
1213
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001214#ifdef PNG_EASY_ACCESS_SUPPORTED
1215/* Returns image width in pixels. */
1216extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
1217png_ptr, png_infop info_ptr));
1218
1219/* Returns image height in pixels. */
1220extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
1221png_ptr, png_infop info_ptr));
1222
1223/* Returns image bit_depth. */
1224extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
1225png_ptr, png_infop info_ptr));
1226
1227/* Returns image color_type. */
1228extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
1229png_ptr, png_infop info_ptr));
1230
1231/* Returns image filter_type. */
1232extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
1233png_ptr, png_infop info_ptr));
1234
1235/* Returns image interlace_type. */
1236extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
1237png_ptr, png_infop info_ptr));
1238
1239/* Returns image compression_type. */
1240extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
1241png_ptr, png_infop info_ptr));
1242
1243/* Returns image resolution in pixels per meter, from pHYs chunk data. */
1244extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
1245png_ptr, png_infop info_ptr));
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001246extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
1247png_ptr, png_infop info_ptr));
1248extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
1249png_ptr, png_infop info_ptr));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001250
1251/* Returns pixel aspect ratio, computed from pHYs chunk data. */
1252extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
1253png_ptr, png_infop info_ptr));
1254
1255/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
1256extern PNG_EXPORT(png_uint_32, png_get_x_offset_pixels) PNGARG((png_structp
1257png_ptr, png_infop info_ptr));
1258extern PNG_EXPORT(png_uint_32, png_get_y_offset_pixels) PNGARG((png_structp
1259png_ptr, png_infop info_ptr));
1260extern PNG_EXPORT(png_uint_32, png_get_x_offset_microns) PNGARG((png_structp
1261png_ptr, png_infop info_ptr));
1262extern PNG_EXPORT(png_uint_32, png_get_y_offset_microns) PNGARG((png_structp
1263png_ptr, png_infop info_ptr));
1264
1265#endif /* PNG_EASY_ACCESS_SUPPORTED */
1266
Andreas Dilger47a0c421997-05-16 02:46:07 -05001267/* Returns pointer to signature string read from PNG header */
1268extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
1269png_infop info_ptr));
1270
1271#if defined(PNG_READ_bKGD_SUPPORTED)
1272extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
1273 png_infop info_ptr, png_color_16p *background));
1274#endif /* PNG_READ_bKGD_SUPPORTED */
1275
1276#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
1277extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
1278 png_infop info_ptr, png_color_16p background));
1279#endif /* PNG_READ_bKGD_SUPPORTED || PNG_WRITE_bKGD_SUPPORTED */
1280
1281#if defined(PNG_READ_cHRM_SUPPORTED)
1282extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
1283 png_infop info_ptr, double *white_x, double *white_y, double *red_x,
1284 double *red_y, double *green_x, double *green_y, double *blue_x,
1285 double *blue_y));
1286#endif /* PNG_READ_cHRM_SUPPORTED */
1287
1288#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
1289extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
1290 png_infop info_ptr, double white_x, double white_y, double red_x,
1291 double red_y, double green_x, double green_y, double blue_x, double blue_y));
1292#endif /* PNG_READ_cHRM_SUPPORTED || PNG_WRITE_cHRM_SUPPORTED */
1293
1294#if defined(PNG_READ_gAMA_SUPPORTED)
1295extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
1296 png_infop info_ptr, double *file_gamma));
1297#endif /* PNG_READ_gAMA_SUPPORTED */
1298
1299#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
1300extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
1301 png_infop info_ptr, double file_gamma));
1302#endif /* PNG_READ_gAMA_SUPPORTED || PNG_WRITE_gAMA_SUPPORTED */
1303
1304#if defined(PNG_READ_hIST_SUPPORTED)
1305extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
1306 png_infop info_ptr, png_uint_16p *hist));
1307#endif /* PNG_READ_hIST_SUPPORTED */
1308
1309#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
1310extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
1311 png_infop info_ptr, png_uint_16p hist));
1312#endif /* PNG_READ_hIST_SUPPORTED || PNG_WRITE_hIST_SUPPORTED */
1313
1314extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
1315 png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
1316 int *bit_depth, int *color_type, int *interlace_type,
1317 int *compression_type, int *filter_type));
1318
1319extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
1320 png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
1321 int color_type, int interlace_type, int compression_type, int filter_type));
1322
1323#if defined(PNG_READ_oFFs_SUPPORTED)
1324extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
1325 png_infop info_ptr, png_uint_32 *offset_x, png_uint_32 *offset_y,
1326 int *unit_type));
1327#endif /* PNG_READ_oFFs_SUPPORTED */
1328
1329#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
1330extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
1331 png_infop info_ptr, png_uint_32 offset_x, png_uint_32 offset_y,
1332 int unit_type));
1333#endif /* PNG_READ_oFFs_SUPPORTED || PNG_WRITE_oFFs_SUPPORTED */
1334
1335#if defined(PNG_READ_pCAL_SUPPORTED)
1336extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
1337 png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
1338 int *type, int *nparams, png_charp *units, png_charpp *params));
1339#endif /* PNG_READ_pCAL_SUPPORTED */
1340
1341#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
1342extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
1343 png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
1344 int type, int nparams, png_charp units, png_charpp params));
1345#endif /* PNG_READ_pCAL_SUPPORTED || PNG_WRITE_pCAL_SUPPORTED */
1346
1347#if defined(PNG_READ_pHYs_SUPPORTED)
1348extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
1349 png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
1350#endif /* PNG_READ_pHYs_SUPPORTED */
1351
1352#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
1353extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
1354 png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
1355#endif /* PNG_READ_pHYs_SUPPORTED || PNG_WRITE_pHYs_SUPPORTED */
1356
1357extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
1358 png_infop info_ptr, png_colorp *palette, int *num_palette));
1359
1360extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
1361 png_infop info_ptr, png_colorp palette, int num_palette));
1362
1363#if defined(PNG_READ_sBIT_SUPPORTED)
1364extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
1365 png_infop info_ptr, png_color_8p *sig_bit));
1366#endif /* PNG_READ_sBIT_SUPPORTED */
1367
1368#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
1369extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
1370 png_infop info_ptr, png_color_8p sig_bit));
1371#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
1372
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001373#if defined(PNG_READ_sRGB_SUPPORTED)
1374extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001375 png_infop info_ptr, int *intent));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001376#endif /* PNG_READ_sRGB_SUPPORTED */
1377
1378#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
1379extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001380 png_infop info_ptr, int intent));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001381extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001382 png_infop info_ptr, int intent));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001383#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
1384
Andreas Dilger47a0c421997-05-16 02:46:07 -05001385#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
1386/* png_get_text also returns the number of text chunks in text_ptr */
1387extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
1388 png_infop info_ptr, png_textp *text_ptr, int *num_text));
1389#endif /* PNG_READ_tEXt_SUPPORTED || PNG_READ_zTXt_SUPPORTED */
1390
1391#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
1392 defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
1393extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
1394 png_infop info_ptr, png_textp text_ptr, int num_text));
1395#endif /* PNG_READ_tEXt_SUPPORTED || PNG_WRITE_tEXt_SUPPORTED ||
1396 PNG_READ_zTXt_SUPPORTED || PNG_WRITE_zTXt_SUPPORTED */
1397
1398#if defined(PNG_READ_tIME_SUPPORTED)
1399extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
1400 png_infop info_ptr, png_timep *mod_time));
1401#endif /* PNG_READ_tIME_SUPPORTED */
1402
1403#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
1404extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
1405 png_infop info_ptr, png_timep mod_time));
1406#endif /* PNG_READ_tIME_SUPPORTED || PNG_WRITE_tIME_SUPPORTED */
1407
1408#if defined(PNG_READ_tRNS_SUPPORTED)
1409extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
1410 png_infop info_ptr, png_bytep *trans, int *num_trans,
1411 png_color_16p *trans_values));
1412#endif /* PNG_READ_tRNS_SUPPORTED */
1413
1414#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
1415extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
1416 png_infop info_ptr, png_bytep trans, int num_trans,
1417 png_color_16p trans_values));
1418#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
1419
1420/* Define PNG_DEBUG at compile time for debugging information. Higher
1421 * numbers for PNG_DEBUG mean more debugging information. This has
1422 * only been added since version 0.95 so it is not implemented throughout
1423 * libpng yet, but more support will be added as needed.
1424 */
1425#if (PNG_DEBUG > 0)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001426#ifdef PNG_NO_STDIO
1427#include <stdio.h>
1428#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -05001429#ifndef PNG_DEBUG_FILE
1430#define PNG_DEBUG_FILE stderr
1431#endif /* PNG_DEBUG_FILE */
1432
1433#define png_debug(l,m) if (PNG_DEBUG > l) \
1434 fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
1435 (l==2 ? "\t\t":(l==3 ? "\t\t\t":""))))
1436#define png_debug1(l,m,p1) if (PNG_DEBUG > l) \
1437 fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
1438 (l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1)
1439#define png_debug2(l,m,p1,p2) if (PNG_DEBUG > l) \
1440 fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
1441 (l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1,p2)
1442#else
1443#define png_debug(l, m)
1444#define png_debug1(l, m, p1)
1445#define png_debug2(l, m, p1, p2)
1446#endif /* (PNG_DEBUG > 0) */
1447
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001448#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
1449/* With these routines, we avoid an integer divide, which will be slower on
1450 * many machines. However, it does take more operations than the corresponding
1451 * divide method, so it may be slower on some RISC systems. There are two
1452 * shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
1453 *
1454 * Note that the rounding factors are NOT supposed to be the same! 128 and
1455 * 32768 are correct for the NODIV code; 127 and 32767 are correct for the
1456 * standard method.
1457 *
1458 * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
1459 */
1460
1461 /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
1462# define png_composite(composite, fg, alpha, bg) \
1463 { png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
1464 (png_uint_16)(bg)*(png_uint_16)(255 - \
1465 (png_uint_16)(alpha)) + (png_uint_16)128); \
1466 (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
1467# define png_composite_16(composite, fg, alpha, bg) \
1468 { png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
1469 (png_uint_32)(bg)*(png_uint_32)(65535L - \
1470 (png_uint_32)(alpha)) + (png_uint_32)32768L); \
1471 (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
1472
1473#else /* standard method using integer division */
1474
1475 /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
1476# define png_composite(composite, fg, alpha, bg) \
1477 (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
1478 (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
1479 (png_uint_16)127) / 255)
1480# define png_composite_16(composite, fg, alpha, bg) \
1481 (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
1482 (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
1483 (png_uint_32)32767) / (png_uint_32)65535L)
1484
1485#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
1486
Andreas Dilger47a0c421997-05-16 02:46:07 -05001487/* These next functions are used internally in the code. They generally
1488 * shouldn't be used unless you are writing code to add or replace some
1489 * functionality in libpng. More information about most functions can
1490 * be found in the files where the functions are located.
1491 */
Guy Schalnat0d580581995-07-20 02:43:20 -05001492
Guy Schalnate5a37791996-06-05 15:50:50 -05001493#if defined(PNG_INTERNAL)
Guy Schalnat0d580581995-07-20 02:43:20 -05001494
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001495/* Various modes of operation. Note that after an init, mode is set to
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001496 * zero automatically when the structure is created.
1497 */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001498#define PNG_BEFORE_IHDR 0x00
1499#define PNG_HAVE_IHDR 0x01
1500#define PNG_HAVE_PLTE 0x02
1501#define PNG_HAVE_IDAT 0x04
1502#define PNG_AFTER_IDAT 0x08
1503#define PNG_HAVE_IEND 0x10
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001504#define PNG_HAVE_gAMA 0x20
1505#define PNG_HAVE_cHRM 0x40
1506#define PNG_HAVE_sRGB 0x80
Guy Schalnat0d580581995-07-20 02:43:20 -05001507
Guy Schalnat6d764711995-12-19 03:22:19 -06001508/* push model modes */
Guy Schalnate5a37791996-06-05 15:50:50 -05001509#define PNG_READ_SIG_MODE 0
Guy Schalnat6d764711995-12-19 03:22:19 -06001510#define PNG_READ_CHUNK_MODE 1
Guy Schalnate5a37791996-06-05 15:50:50 -05001511#define PNG_READ_IDAT_MODE 2
Andreas Dilger47a0c421997-05-16 02:46:07 -05001512#define PNG_SKIP_MODE 3
1513#define PNG_READ_tEXt_MODE 4
1514#define PNG_READ_zTXt_MODE 5
1515#define PNG_READ_DONE_MODE 6
1516#define PNG_ERROR_MODE 7
Guy Schalnat6d764711995-12-19 03:22:19 -06001517
Andreas Dilger47a0c421997-05-16 02:46:07 -05001518/* flags for the transformations the PNG library does on the image data */
Guy Schalnate5a37791996-06-05 15:50:50 -05001519#define PNG_BGR 0x0001
1520#define PNG_INTERLACE 0x0002
1521#define PNG_PACK 0x0004
1522#define PNG_SHIFT 0x0008
1523#define PNG_SWAP_BYTES 0x0010
1524#define PNG_INVERT_MONO 0x0020
1525#define PNG_DITHER 0x0040
1526#define PNG_BACKGROUND 0x0080
1527#define PNG_BACKGROUND_EXPAND 0x0100
Andreas Dilger47a0c421997-05-16 02:46:07 -05001528#define PNG_RGB_TO_GRAY 0x0200 /* Not currently implemented */
Guy Schalnate5a37791996-06-05 15:50:50 -05001529#define PNG_16_TO_8 0x0400
1530#define PNG_RGBA 0x0800
1531#define PNG_EXPAND 0x1000
1532#define PNG_GAMMA 0x2000
1533#define PNG_GRAY_TO_RGB 0x4000
1534#define PNG_FILLER 0x8000
Glenn Randers-Pehrson397100e1998-03-07 19:45:37 -06001535#define PNG_PACKSWAP 0x10000L
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06001536#define PNG_SWAP_ALPHA 0x20000L
1537#define PNG_STRIP_ALPHA 0x40000L
1538#define PNG_INVERT_ALPHA 0x80000L
Glenn Randers-Pehrson397100e1998-03-07 19:45:37 -06001539#define PNG_USER_TRANSFORM 0x100000L
Guy Schalnate5a37791996-06-05 15:50:50 -05001540
Guy Schalnate5a37791996-06-05 15:50:50 -05001541/* flags for png_create_struct */
1542#define PNG_STRUCT_PNG 0x0001
1543#define PNG_STRUCT_INFO 0x0002
1544
Andreas Dilger47a0c421997-05-16 02:46:07 -05001545/* Scaling factor for filter heuristic weighting calculations */
1546#define PNG_WEIGHT_SHIFT 8
1547#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
1548#define PNG_COST_SHIFT 3
1549#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
1550
1551/* flags for the png_ptr->flags rather than declaring a byte for each one */
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001552#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
1553#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
1554#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
1555#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
1556#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
1557#define PNG_FLAG_ZLIB_FINISHED 0x0020
1558#define PNG_FLAG_ROW_INIT 0x0040
1559#define PNG_FLAG_FILLER_AFTER 0x0080
1560#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
1561#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
1562#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
1563#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
1564#define PNG_FLAG_FREE_PALETTE 0x1000
1565#define PNG_FLAG_FREE_TRANS 0x2000
1566#define PNG_FLAG_FREE_HIST 0x4000
Glenn Randers-Pehrsona357b991998-02-08 20:56:40 -06001567#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
Glenn Randers-Pehrson397100e1998-03-07 19:45:37 -06001568#define PNG_FLAG_WROTE_tIME 0x10000L
Glenn Randers-Pehrson1d963611998-05-02 12:52:25 -05001569#define PNG_FLAG_BACKGROUND_IS_GRAY 0x20000L
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001570
1571#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
1572 PNG_FLAG_CRC_ANCILLARY_NOWARN)
1573
1574#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
1575 PNG_FLAG_CRC_CRITICAL_IGNORE)
1576
1577#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
1578 PNG_FLAG_CRC_CRITICAL_MASK)
Guy Schalnat0d580581995-07-20 02:43:20 -05001579
1580/* save typing and make code easier to understand */
1581#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
1582 abs((int)((c1).green) - (int)((c2).green)) + \
1583 abs((int)((c1).blue) - (int)((c2).blue)))
1584
Andreas Dilger47a0c421997-05-16 02:46:07 -05001585/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06001586#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001587/* place to hold the signature string for a PNG file. */
1588extern png_byte FARDATA png_sig[8];
Guy Schalnat0d580581995-07-20 02:43:20 -05001589
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001590/* Constant strings for known chunk types. If you need to add a chunk,
1591 * add a string holding the name here. See png.c for more details. We
1592 * can't selectively include these, since we still check for chunk in the
1593 * wrong locations with these labels.
1594 */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001595extern png_byte FARDATA png_IHDR[5];
1596extern png_byte FARDATA png_IDAT[5];
1597extern png_byte FARDATA png_IEND[5];
1598extern png_byte FARDATA png_PLTE[5];
1599extern png_byte FARDATA png_bKGD[5];
1600extern png_byte FARDATA png_cHRM[5];
1601extern png_byte FARDATA png_gAMA[5];
1602extern png_byte FARDATA png_hIST[5];
1603extern png_byte FARDATA png_oFFs[5];
1604extern png_byte FARDATA png_pCAL[5];
1605extern png_byte FARDATA png_pHYs[5];
1606extern png_byte FARDATA png_sBIT[5];
1607extern png_byte FARDATA png_sRGB[5];
1608extern png_byte FARDATA png_tEXt[5];
1609extern png_byte FARDATA png_tIME[5];
1610extern png_byte FARDATA png_tRNS[5];
1611extern png_byte FARDATA png_zTXt[5];
Guy Schalnat0d580581995-07-20 02:43:20 -05001612
1613#endif /* PNG_NO_EXTERN */
1614
Andreas Dilger47a0c421997-05-16 02:46:07 -05001615/* Inline macros to do direct reads of bytes from the input buffer. These
1616 * require that you are using an architecture that uses PNG byte ordering
1617 * (MSB first) and supports unaligned data storage. I think that PowerPC
1618 * in big-endian mode and 680x0 are the only ones that will support this.
1619 * The x86 line of processors definitely do not. The png_get_int_32()
1620 * routine also assumes we are using two's complement format for negative
1621 * values, which is almost certainly true.
1622 */
1623#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
1624#if defined(PNG_READ_pCAL_SUPPORTED)
1625#define png_get_int_32(buf) ( *((png_int_32p) (buf)))
1626#endif /* PNG_READ_pCAL_SUPPORTED */
1627#define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
1628#define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
1629#else
1630#if defined(PNG_READ_pCAL_SUPPORTED)
1631PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
1632#endif /* PNG_READ_pCAL_SUPPORTED */
1633PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
1634PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -05001635#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001636
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001637/* Initialize png_ptr struct for reading, and allocate any other memory.
1638 * (old interface - NOT DLL EXPORTED).
1639 */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001640extern void png_read_init PNGARG((png_structp png_ptr));
1641
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001642/* Initialize png_ptr struct for writing, and allocate any other memory.
1643 * (old interface - NOT DLL EXPORTED).
1644 */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001645extern void png_write_init PNGARG((png_structp png_ptr));
1646
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001647/* allocate memory for an internal libpng struct */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001648PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001649
1650/* free memory from internal libpng struct */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001651PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001652
1653/* free any memory that info_ptr points to and reset struct. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001654PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001655 png_infop info_ptr));
1656
Guy Schalnat0d580581995-07-20 02:43:20 -05001657/* Function to allocate memory for zlib. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001658PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
Guy Schalnat0d580581995-07-20 02:43:20 -05001659
1660/* function to free memory for zlib */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001661PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -05001662
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001663/* reset the CRC variable */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001664PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
1665
1666/* Write the "data" buffer to whatever output you are using. */
1667PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
1668 png_size_t length));
1669
1670/* Read data from whatever input you are using into the "data" buffer */
1671PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
1672 png_size_t length));
Guy Schalnat0d580581995-07-20 02:43:20 -05001673
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001674/* read bytes into buf, and update png_ptr->crc */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001675PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
1676 png_size_t length));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001677
1678/* read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001679PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001680
1681/* read the CRC from the file and compare it to the libpng calculated CRC */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001682PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001683
Andreas Dilger47a0c421997-05-16 02:46:07 -05001684/* Calculate the CRC over a section of data. Note that we are only
1685 * passing a maximum of 64K on systems that have this as a memory limit,
1686 * since this is the maximum buffer size we can specify.
1687 */
1688PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
1689 png_size_t length));
Guy Schalnat6d764711995-12-19 03:22:19 -06001690
Guy Schalnat6d764711995-12-19 03:22:19 -06001691#if defined(PNG_WRITE_FLUSH_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001692PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
Guy Schalnat6d764711995-12-19 03:22:19 -06001693#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001694
Andreas Dilger47a0c421997-05-16 02:46:07 -05001695/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001696 * The only currently known PNG chunk that uses signed numbers is
Andreas Dilger47a0c421997-05-16 02:46:07 -05001697 * the ancillary extension chunk, pCAL.
1698 */
1699PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
Guy Schalnat0d580581995-07-20 02:43:20 -05001700
Andreas Dilger47a0c421997-05-16 02:46:07 -05001701#if defined(PNG_WRITE_pCAL_SUPPORTED)
1702PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
1703#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001704
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001705/* Place a 16 bit number into a buffer in PNG byte order.
1706 * The parameter is declared unsigned int, not png_uint_16,
1707 * just to avoid potential problems on pre-ANSI C compilers.
1708 */
1709PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
Guy Schalnat0d580581995-07-20 02:43:20 -05001710
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001711/* simple function to write the signature */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001712PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -05001713
1714/* write various chunks */
1715
1716/* Write the IHDR chunk, and update the png_struct with the necessary
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001717 * information.
1718 */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001719PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001720 png_uint_32 height,
1721 int bit_depth, int color_type, int compression_type, int filter_type,
1722 int interlace_type));
Guy Schalnat0d580581995-07-20 02:43:20 -05001723
Andreas Dilger47a0c421997-05-16 02:46:07 -05001724PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
1725 png_uint_32 num_pal));
Guy Schalnat0d580581995-07-20 02:43:20 -05001726
Andreas Dilger47a0c421997-05-16 02:46:07 -05001727PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
1728 png_size_t length));
Guy Schalnat0d580581995-07-20 02:43:20 -05001729
Andreas Dilger47a0c421997-05-16 02:46:07 -05001730PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -05001731
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001732#if defined(PNG_WRITE_gAMA_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001733PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001734#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001735
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001736#if defined(PNG_WRITE_sBIT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001737PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001738 int color_type));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001739#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001740
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001741#if defined(PNG_WRITE_cHRM_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001742PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001743 double white_x, double white_y,
1744 double red_x, double red_y, double green_x, double green_y,
1745 double blue_x, double blue_y));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001746#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001747
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001748#if defined(PNG_WRITE_sRGB_SUPPORTED)
1749PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001750 int intent));
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001751#endif
1752
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001753#if defined(PNG_WRITE_tRNS_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001754PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001755 png_color_16p values, int number, int color_type));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001756#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001757
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001758#if defined(PNG_WRITE_bKGD_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001759PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
1760 png_color_16p values, int color_type));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001761#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001762
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001763#if defined(PNG_WRITE_hIST_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001764PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06001765 int num_hist));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001766#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001767
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001768#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001769PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001770 png_charp key, png_charpp new_key));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001771#endif
1772
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001773#if defined(PNG_WRITE_tEXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001774PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
1775 png_charp text, png_size_t text_len));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001776#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001777
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001778#if defined(PNG_WRITE_zTXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001779PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
1780 png_charp text, png_size_t text_len, int compression));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001781#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001782
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001783#if defined(PNG_WRITE_oFFs_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001784PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
1785 png_uint_32 x_offset, png_uint_32 y_offset, int unit_type));
1786#endif
1787
1788#if defined(PNG_WRITE_pCAL_SUPPORTED)
1789PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
1790 png_int_32 X0, png_int_32 X1, int type, int nparams,
1791 png_charp units, png_charpp params));
1792#endif
1793
1794#if defined(PNG_WRITE_pHYs_SUPPORTED)
1795PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
1796 png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
Guy Schalnat0d580581995-07-20 02:43:20 -05001797 int unit_type));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001798#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001799
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001800#if defined(PNG_WRITE_tIME_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001801PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001802 png_timep mod_time));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001803#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001804
Andreas Dilger47a0c421997-05-16 02:46:07 -05001805/* Called when finished processing a row of data */
1806PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001807
Andreas Dilger47a0c421997-05-16 02:46:07 -05001808/* Internal use only. Called before first row of data */
1809PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001810
1811#if defined(PNG_READ_GAMMA_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001812PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001813#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001814
1815/* combine a row of data, dealing with alpha, etc. if requested */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001816PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
Guy Schalnat0d580581995-07-20 02:43:20 -05001817 int mask));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001818
1819#if defined(PNG_READ_INTERLACING_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -05001820/* expand an interlaced row */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001821PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
1822 png_bytep row, int pass, png_uint_32 transformations));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001823#endif
1824
1825#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
Guy Schalnat0d580581995-07-20 02:43:20 -05001826/* grab pixels out of a row for an interlaced pass */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001827PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001828 png_bytep row, int pass));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001829#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001830
1831/* unfilter a row */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001832PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
Guy Schalnate5a37791996-06-05 15:50:50 -05001833 png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001834
1835/* Choose the best filter to use and filter the row data */
1836PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
Guy Schalnate5a37791996-06-05 15:50:50 -05001837 png_row_infop row_info));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001838
1839/* Write out the filtered row. */
1840PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
Guy Schalnate5a37791996-06-05 15:50:50 -05001841 png_bytep filtered_row));
Guy Schalnat0d580581995-07-20 02:43:20 -05001842/* finish a row while reading, dealing with interlacing passes, etc. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001843PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
1844
Guy Schalnat0d580581995-07-20 02:43:20 -05001845/* initialize the row buffers, etc. */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001846PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001847/* optional call to update the users info structure */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001848PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001849 png_infop info_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -05001850
1851/* these are the functions that do the transformations */
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001852#if defined(PNG_READ_FILLER_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001853PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
1854 png_bytep row, png_uint_32 filler, png_uint_32 flags));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001855#endif
1856
Andreas Dilger47a0c421997-05-16 02:46:07 -05001857#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
1858PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
1859 png_bytep row));
1860#endif
1861
1862#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
1863PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
1864 png_bytep row));
1865#endif
1866
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001867#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
1868PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
1869 png_bytep row));
1870#endif
1871
1872#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
1873PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
1874 png_bytep row));
1875#endif
1876
Andreas Dilger47a0c421997-05-16 02:46:07 -05001877#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
1878 defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
1879PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
1880 png_bytep row, png_uint_32 flags));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001881#endif
1882
1883#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001884PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
1885#endif
1886
Glenn Randers-Pehrson8f8fb6a1998-03-09 23:02:06 -06001887#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001888PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001889#endif
1890
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001891#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001892PNG_EXTERN void png_do_rgb_to_gray PNGARG((png_row_infop row_info,
1893 png_bytep row));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001894#endif
1895
1896#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001897PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
1898 png_bytep row));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001899#endif
1900
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001901#if defined(PNG_READ_PACK_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001902PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001903#endif
1904
1905#if defined(PNG_READ_SHIFT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001906PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
Guy Schalnat6d764711995-12-19 03:22:19 -06001907 png_color_8p sig_bits));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001908#endif
1909
1910#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001911PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001912#endif
1913
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001914#if defined(PNG_READ_16_TO_8_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001915PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001916#endif
1917
1918#if defined(PNG_READ_DITHER_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001919PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001920 png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001921
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001922# if defined(PNG_CORRECT_PALETTE_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001923PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
Guy Schalnate5a37791996-06-05 15:50:50 -05001924 png_colorp palette, int num_palette));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001925# endif
Guy Schalnate5a37791996-06-05 15:50:50 -05001926#endif
1927
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001928#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001929PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001930#endif
1931
1932#if defined(PNG_WRITE_PACK_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001933PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
1934 png_bytep row, png_uint_32 bit_depth));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001935#endif
1936
1937#if defined(PNG_WRITE_SHIFT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001938PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
Guy Schalnat6d764711995-12-19 03:22:19 -06001939 png_color_8p bit_depth));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001940#endif
1941
1942#if defined(PNG_READ_BACKGROUND_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001943PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
Guy Schalnat6d764711995-12-19 03:22:19 -06001944 png_color_16p trans_values, png_color_16p background,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001945 png_color_16p background_1,
1946 png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
1947 png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
1948 png_uint_16pp gamma_16_to_1, int gamma_shift));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001949#endif
1950
1951#if defined(PNG_READ_GAMMA_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001952PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001953 png_bytep gamma_table, png_uint_16pp gamma_16_table,
Guy Schalnat0d580581995-07-20 02:43:20 -05001954 int gamma_shift));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001955#endif
1956
1957#if defined(PNG_READ_EXPAND_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001958PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001959 png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001960PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001961 png_bytep row, png_color_16p trans_value));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001962#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001963
Andreas Dilger47a0c421997-05-16 02:46:07 -05001964/* The following decodes the appropriate chunks, and does error correction,
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001965 * then calls the appropriate callback for the chunk if it is valid.
1966 */
Guy Schalnat0d580581995-07-20 02:43:20 -05001967
1968/* decode the IHDR chunk */
Andreas Dilger47a0c421997-05-16 02:46:07 -05001969PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06001970 png_uint_32 length));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001971PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001972 png_uint_32 length));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001973PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05001974 png_uint_32 length));
Andreas Dilger47a0c421997-05-16 02:46:07 -05001975
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001976#if defined(PNG_READ_gAMA_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001977PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05001978 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001979#endif
1980
1981#if defined(PNG_READ_sBIT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001982PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05001983 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001984#endif
1985
1986#if defined(PNG_READ_cHRM_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001987PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05001988 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001989#endif
1990
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06001991#if defined(PNG_READ_sRGB_SUPPORTED)
1992PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
1993 png_uint_32 length));
1994#endif
1995
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001996#if defined(PNG_READ_tRNS_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05001997PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05001998 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001999#endif
2000
2001#if defined(PNG_READ_bKGD_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05002002PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05002003 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05002004#endif
2005
2006#if defined(PNG_READ_hIST_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05002007PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05002008 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05002009#endif
2010
2011#if defined(PNG_READ_oFFs_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05002012PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
2013 png_uint_32 length));
2014#endif
2015
2016#if defined(PNG_READ_pCAL_SUPPORTED)
2017PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
2018 png_uint_32 length));
2019#endif
2020
2021#if defined(PNG_READ_pHYs_SUPPORTED)
2022PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05002023 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05002024#endif
2025
2026#if defined(PNG_READ_tIME_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05002027PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05002028 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05002029#endif
2030
2031#if defined(PNG_READ_tEXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05002032PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05002033 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05002034#endif
2035
2036#if defined(PNG_READ_zTXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05002037PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
Guy Schalnat0d580581995-07-20 02:43:20 -05002038 png_uint_32 length));
Guy Schalnat51f0eb41995-09-26 05:22:39 -05002039#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05002040
Andreas Dilger47a0c421997-05-16 02:46:07 -05002041PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
2042 png_infop info_ptr, png_uint_32 length));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06002043
Andreas Dilger47a0c421997-05-16 02:46:07 -05002044PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06002045 png_bytep chunk_name));
2046
Guy Schalnat0d580581995-07-20 02:43:20 -05002047/* handle the transformations for reading and writing */
Andreas Dilger47a0c421997-05-16 02:46:07 -05002048PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
2049PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -05002050
Andreas Dilger47a0c421997-05-16 02:46:07 -05002051PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
Guy Schalnat0d580581995-07-20 02:43:20 -05002052
Guy Schalnat6d764711995-12-19 03:22:19 -06002053#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Andreas Dilger47a0c421997-05-16 02:46:07 -05002054PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06002055 png_infop info_ptr));
Andreas Dilger47a0c421997-05-16 02:46:07 -05002056PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
2057 png_infop info_ptr));
2058PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
2059PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
Guy Schalnat4ee97b01996-01-16 01:51:56 -06002060 png_uint_32 length));
Andreas Dilger47a0c421997-05-16 02:46:07 -05002061PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
2062PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
2063 png_bytep buffer, png_size_t length));
2064PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
2065PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
2066 png_bytep buffer, png_size_t buffer_length));
2067PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
2068PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
2069 png_bytep buffer, png_size_t buffer_length));
2070PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
2071PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
2072 png_infop info_ptr, png_uint_32 length));
2073PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
2074 png_infop info_ptr));
2075PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
2076 png_infop info_ptr));
2077PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
2078PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
2079 png_infop info_ptr));
2080PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
2081 png_infop info_ptr));
2082PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
2083#if defined(PNG_READ_tEXt_SUPPORTED)
2084PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
2085 png_infop info_ptr, png_uint_32 length));
2086PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
2087 png_infop info_ptr));
Guy Schalnat6d764711995-12-19 03:22:19 -06002088#endif
2089#if defined(PNG_READ_zTXt_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -05002090PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
2091 png_infop info_ptr, png_uint_32 length));
2092PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
2093 png_infop info_ptr));
Guy Schalnat6d764711995-12-19 03:22:19 -06002094#endif
2095
2096#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
Guy Schalnat0d580581995-07-20 02:43:20 -05002097
2098#endif /* PNG_INTERNAL */
2099
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06002100#ifdef __cplusplus
2101}
2102#endif
2103
Guy Schalnat0d580581995-07-20 02:43:20 -05002104/* do not put anything past this line */
2105#endif /* _PNG_H */