source: svn/newcon3bcm2_21bu/dst/dlib/src/PNG/png.h

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 95.7 KB
Line 
1/*
2 * $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/PNG/lpng102/png.h#1 $
3 * $Revision: #1 $
4 * $DateTime: 2006/02/24 17:51:46 $
5 * $Change: 42566 $
6 * $Author: pryush.sharma $
7 */
8
9
10/* png.h - header file for PNG reference library
11 *
12 * libpng 1.0.2 - June 14, 1998
13 * For conditions of distribution and use, see the COPYRIGHT NOTICE below.
14 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
15 * Copyright (c) 1996, 1997 Andreas Dilger
16 * Copyright (c) 1998 Glenn Randers-Pehrson
17 *
18 * Note about libpng version numbers:
19 *
20 *    Due to various miscommunications, unforeseen code incompatibilities
21 *    and occasional factors outside the authors' control, version numbering
22 *    on the library has not always been consistent and straightforward.
23 *    The following table summarizes matters since version 0.89c, which was
24 *    the first widely used release:
25 *
26 *    source                    png.h    png.h   shared-lib
27 *    version                   string     int   version
28 *    -------                   ------   -----  ----------
29 *    0.89c ("1.0 beta 3")      0.89        89  1.0.89
30 *    0.90  ("1.0 beta 4")      0.90        90  0.90  [should have been 2.0.90]
31 *    0.95  ("1.0 beta 5")      0.95        95  0.95  [should have been 2.0.95]
32 *    0.96  ("1.0 beta 6")      0.96        96  0.96  [should have been 2.0.96]
33 *    0.97b ("1.00.97 beta 7")  1.00.97     97  1.0.1 [should have been 2.0.97]
34 *    0.97c                     0.97        97  2.0.97
35 *    0.98                      0.98        98  2.0.98
36 *    0.99                      0.99        98  2.0.99
37 *    0.99a-m                   0.99        99  2.0.99
38 *    1.00                      1.00       100  2.1.0 [int should be 10000]
39 *    1.0.0                     1.0.0      100  2.1.0 [int should be 10000]
40 *    1.0.1                     1.0.1    10001  2.1.0
41 *    1.0.1a-e                  1.0.1a-e 10002  2.1.0.1a-e
42 *
43 *    Henceforth the source version will match the shared-library minor
44 *    and patch numbers; the shared-library major version number will be
45 *    used for changes in backward compatibility, as it is intended.  The
46 *    PNG_PNGLIB_VER macro, which is not used within libpng but is available
47 *    for applications, is an unsigned integer of the form xyyzz corresponding
48 *    to the source version x.y.z (leading zeros in y and z).
49 *
50 * See libpng.txt or libpng.3 for more information.  The PNG specification
51 * is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
52 * and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
53 *
54 * Contributing Authors:
55 *    John Bowler
56 *    Kevin Bracey
57 *    Sam Bushell
58 *    Andreas Dilger
59 *    Magnus Holmgren
60 *    Tom Lane
61 *    Dave Martindale
62 *    Glenn Randers-Pehrson
63 *    Greg Roelofs
64 *    Guy Eric Schalnat
65 *    Paul Schmidt
66 *    Tom Tanner
67 *    Willem van Schaik
68 *    Tim Wegner
69 *
70 * The contributing authors would like to thank all those who helped
71 * with testing, bug fixes, and patience.  This wouldn't have been
72 * possible without all of you.
73 *
74 * Thanks to Frank J. T. Wojcik for helping with the documentation.
75 *
76 * COPYRIGHT NOTICE:
77 *
78 * The PNG Reference Library is supplied "AS IS".  The Contributing Authors
79 * and Group 42, Inc. disclaim all warranties, expressed or implied,
80 * including, without limitation, the warranties of merchantability and of
81 * fitness for any purpose.  The Contributing Authors and Group 42, Inc.
82 * assume no liability for direct, indirect, incidental, special, exemplary,
83 * or consequential damages, which may result from the use of the PNG
84 * Reference Library, even if advised of the possibility of such damage.
85 *
86 * Permission is hereby granted to use, copy, modify, and distribute this
87 * source code, or portions hereof, for any purpose, without fee, subject
88 * to the following restrictions:
89 * 1. The origin of this source code must not be misrepresented.
90 * 2. Altered versions must be plainly marked as such and must not be
91 *    misrepresented as being the original source.
92 * 3. This Copyright notice may not be removed or altered from any source or
93 *    altered source distribution.
94 *
95 * The Contributing Authors and Group 42, Inc. specifically permit, without
96 * fee, and encourage the use of this source code as a component to
97 * supporting the PNG file format in commercial products.  If you use this
98 * source code in a product, acknowledgment is not required but would be
99 * appreciated.
100 */
101
102#ifndef _PNG_H
103#define _PNG_H
104
105#ifdef __cplusplus
106extern "C" {
107#endif /* __cplusplus */
108
109/* This is not the place to learn how to use libpng.  The file libpng.txt
110 * describes how to use libpng, and the file example.c summarizes it
111 * with some code on which to build.  This file is useful for looking
112 * at the actual function definitions and structure components.
113 */
114
115/* include the compression library's header */
116#include "zlib.h"
117
118/* include all user configurable info */
119#include "pngconf.h"
120
121/* This file is arranged in several sections.  The first section contains
122 * structure and type definitions.  The second section contains the external
123 * library functions, while the third has the internal library functions,
124 * which applications aren't expected to use directly.
125 */
126
127/* Version information for png.h - this should match the version in png.c */
128#define PNG_LIBPNG_VER_STRING "1.0.2"
129
130/* Careful here.  At one time, Guy wanted to use 082, but that would be octal.
131 * We must not include leading zeros.
132 * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
133 * version 1.0.0 was mis-numbered 100 instead of 10000).  From
134 * version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=bugfix */
135#define PNG_LIBPNG_VER    10002  /* 1.0.2 */
136
137/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
138#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
139/* Version information for C files, stored in png.c.  This had better match
140 * the version above.
141 */
142extern char png_libpng_ver[12];   /* need room for 99.99.99aa */
143
144/* Structures to facilitate easy interlacing.  See png.c for more details */
145extern int FARDATA png_pass_start[7];
146extern int FARDATA png_pass_inc[7];
147extern int FARDATA png_pass_ystart[7];
148extern int FARDATA png_pass_yinc[7];
149extern int FARDATA png_pass_mask[7];
150extern int FARDATA png_pass_dsp_mask[7];
151/* These aren't currently used.  If you need them, see png.c for more details
152extern int FARDATA png_pass_width[7];
153extern int FARDATA png_pass_height[7];
154*/
155#endif /* PNG_NO_EXTERN */
156
157/* Three color definitions.  The order of the red, green, and blue, (and the
158 * exact size) is not important, although the size of the fields need to
159 * be png_byte or png_uint_16 (as defined below).
160 */
161typedef struct png_color_struct
162{
163   png_byte red;
164   png_byte green;
165   png_byte blue;
166} png_color;
167typedef png_color FAR * png_colorp;
168typedef png_color FAR * FAR * png_colorpp;
169
170typedef struct png_color_16_struct
171{
172   png_byte index;    /* used for palette files */
173   png_uint_16 red;   /* for use in red green blue files */
174   png_uint_16 green;
175   png_uint_16 blue;
176   png_uint_16 gray;  /* for use in grayscale files */
177} png_color_16;
178typedef png_color_16 FAR * png_color_16p;
179typedef png_color_16 FAR * FAR * png_color_16pp;
180
181typedef struct png_color_8_struct
182{
183   png_byte red;   /* for use in red green blue files */
184   png_byte green;
185   png_byte blue;
186   png_byte gray;  /* for use in grayscale files */
187   png_byte alpha; /* for alpha channel files */
188} png_color_8;
189typedef png_color_8 FAR * png_color_8p;
190typedef png_color_8 FAR * FAR * png_color_8pp;
191
192/* png_text holds the text in a PNG file, and whether they are compressed
193   in the PNG file or not.  The "text" field points to a regular C string. */
194typedef struct png_text_struct
195{
196   int compression;        /* compression value, see PNG_TEXT_COMPRESSION_ */
197   png_charp key;          /* keyword, 1-79 character description of "text" */
198   png_charp text;         /* comment, may be an empty string (ie "") */
199   png_size_t text_length; /* length of "text" field */
200} png_text;
201typedef png_text FAR * png_textp;
202typedef png_text FAR * FAR * png_textpp;
203
204/* Supported compression types for text in PNG files (tEXt, and zTXt).
205 * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */
206#define PNG_TEXT_COMPRESSION_NONE_WR -3
207#define PNG_TEXT_COMPRESSION_zTXt_WR -2
208#define PNG_TEXT_COMPRESSION_NONE    -1
209#define PNG_TEXT_COMPRESSION_zTXt     0
210#define PNG_TEXT_COMPRESSION_LAST     1  /* Not a valid value */
211
212/* png_time is a way to hold the time in an machine independent way.
213 * Two conversions are provided, both from time_t and struct tm.  There
214 * is no portable way to convert to either of these structures, as far
215 * as I know.  If you know of a portable way, send it to me.  As a side
216 * note - PNG is Year 2000 compliant!
217 */
218typedef struct png_time_struct
219{
220   png_uint_16 year; /* full year, as in, 1995 */
221   png_byte month;   /* month of year, 1 - 12 */
222   png_byte day;     /* day of month, 1 - 31 */
223   png_byte hour;    /* hour of day, 0 - 23 */
224   png_byte minute;  /* minute of hour, 0 - 59 */
225   png_byte second;  /* second of minute, 0 - 60 (for leap seconds) */
226} png_time;
227typedef png_time FAR * png_timep;
228typedef png_time FAR * FAR * png_timepp;
229
230/* png_info is a structure that holds the information in a PNG file so
231 * that the application can find out the characteristics of the image.
232 * If you are reading the file, this structure will tell you what is
233 * in the PNG file.  If you are writing the file, fill in the information
234 * you want to put into the PNG file, then call png_write_info().
235 * The names chosen should be very close to the PNG specification, so
236 * consult that document for information about the meaning of each field.
237 *
238 * With libpng < 0.95, it was only possible to directly set and read the
239 * the values in the png_info_struct, which meant that the contents and
240 * order of the values had to remain fixed.  With libpng 0.95 and later,
241 * however, there are now functions that abstract the contents of
242 * png_info_struct from the application, so this makes it easier to use
243 * libpng with dynamic libraries, and even makes it possible to use
244 * libraries that don't have all of the libpng ancillary chunk-handing
245 * functionality.
246 *
247 * In any case, the order of the parameters in png_info_struct should NOT
248 * be changed for as long as possible to keep compatibility with applications
249 * that use the old direct-access method with png_info_struct.
250 */
251typedef struct png_info_struct
252{
253   /* the following are necessary for every PNG file */
254   png_uint_32 width;       /* width of image in pixels (from IHDR) */
255   png_uint_32 height;      /* height of image in pixels (from IHDR) */
256   png_uint_32 valid;       /* valid chunk data (see PNG_INFO_ below) */
257   png_uint_32 rowbytes;    /* bytes needed to hold an untransformed row */
258   png_colorp palette;      /* array of color values (valid & PNG_INFO_PLTE) */
259   png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
260   png_uint_16 num_trans;   /* number of transparent palette color (tRNS) */
261   png_byte bit_depth;      /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
262   png_byte color_type;     /* see PNG_COLOR_TYPE_ below (from IHDR) */
263   png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
264   png_byte filter_type;    /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
265   png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
266
267   /* The following is informational only on read, and not used on writes. */
268   png_byte channels;       /* number of data channels per pixel (1, 3, 4)*/
269   png_byte pixel_depth;    /* number of bits per pixel */
270   png_byte spare_byte;     /* to align the data, and for future use */
271   png_byte signature[8];   /* magic bytes read by libpng from start of file */
272
273   /* The rest of the data is optional.  If you are reading, check the
274    * valid field to see if the information in these are valid.  If you
275    * are writing, set the valid field to those chunks you want written,
276    * and initialize the appropriate fields below.
277    */
278
279#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) || \
280    defined(PNG_READ_GAMMA_SUPPORTED)
281   /* The gAMA chunk describes the gamma characteristics of the system
282    * on which the image was created, normally in the range [1.0, 2.5].
283    * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
284    */
285   float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
286#endif /* PNG_READ_gAMA_SUPPORTED || PNG_WRITE_gAMA_SUPPORTED */
287
288#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
289    /* GR-P, 0.96a */
290    /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
291   png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
292#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
293
294#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
295    defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
296   /* The tEXt and zTXt chunks contain human-readable textual data in
297    * uncompressed and compressed forms, respectively.  The data in "text"
298    * is an array of pointers to uncompressed, null-terminated C strings.
299    * Each chunk has a keyword that describes the textual data contained
300    * in that chunk.  Keywords are not required to be unique, and the text
301    * string may be empty.  Any number of text chunks may be in an image.
302    */
303   int num_text; /* number of comments read/to write */
304   int max_text; /* current size of text array */
305   png_textp text; /* array of comments read/to write */
306#endif /* PNG_READ_OR_WRITE_tEXt_OR_zTXt_SUPPORTED */
307#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
308   /* The tIME chunk holds the last time the displayed image data was
309    * modified.  See the png_time struct for the contents of this struct.
310    */
311   png_time mod_time;
312#endif /* PNG_READ_tIME_SUPPORTED || PNG_WRITE_tIME_SUPPORTED */
313#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
314   /* The sBIT chunk specifies the number of significant high-order bits
315    * in the pixel data.  Values are in the range [1, bit_depth], and are
316    * only specified for the channels in the pixel data.  The contents of
317    * the low-order bits is not specified.  Data is valid if
318    * (valid & PNG_INFO_sBIT) is non-zero.
319    */
320   png_color_8 sig_bit; /* significant bits in color channels */
321#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
322#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) || \
323    defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
324   /* The tRNS chunk supplies transparency data for paletted images and
325    * other image types that don't need a full alpha channel.  There are
326    * "num_trans" transparency values for a paletted image, stored in the
327    * same order as the palette colors, starting from index 0.  Values
328    * for the data are in the range [0, 255], ranging from fully transparent
329    * to fully opaque, respectively.  For non-paletted images, there is a
330    * single color specified that should be treated as fully transparent.
331    * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
332    */
333   png_bytep trans; /* transparent values for paletted image */
334   png_color_16 trans_values; /* transparent color for non-palette image */
335#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
336#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED) || \
337    defined(PNG_READ_BACKGROUND_SUPPORTED)
338   /* The bKGD chunk gives the suggested image background color if the
339    * display program does not have its own background color and the image
340    * is needs to composited onto a background before display.  The colors
341    * in "background" are normally in the same color space/depth as the
342    * pixel data.  Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
343    */
344   png_color_16 background;
345#endif /* PNG_READ_bKGD_SUPPORTED || PNG_WRITE_bKGD_SUPPORTED */
346#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
347   /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
348    * and downwards from the top-left corner of the display, page, or other
349    * application-specific co-ordinate space.  See the PNG_OFFSET_ defines
350    * below for the unit types.  Valid if (valid & PNG_INFO_oFFs) non-zero.
351    */
352   png_uint_32 x_offset; /* x offset on page */
353   png_uint_32 y_offset; /* y offset on page */
354   png_byte offset_unit_type; /* offset units type */
355#endif /* PNG_READ_oFFs_SUPPORTED || PNG_WRITE_oFFs_SUPPORTED */
356#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
357   /* The pHYs chunk gives the physical pixel density of the image for
358    * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
359    * defines below).  Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
360    */
361   png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
362   png_uint_32 y_pixels_per_unit; /* vertical pixel density */
363   png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
364#endif /* PNG_READ_pHYs_SUPPORTED || PNG_WRITE_pHYs_SUPPORTED */
365#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
366   /* The hIST chunk contains the relative frequency or importance of the
367    * various palette entries, so that a viewer can intelligently select a
368    * reduced-color palette, if required.  Data is an array of "num_palette"
369    * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
370    * is non-zero.
371    */
372   png_uint_16p hist;
373#endif /* PNG_READ_hIST_SUPPORTED || PNG_WRITE_hIST_SUPPORTED */
374#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
375   /* The cHRM chunk describes the CIE color characteristics of the monitor
376    * on which the PNG was created.  This data allows the viewer to do gamut
377    * mapping of the input image to ensure that the viewer sees the same
378    * colors in the image as the creator.  Values are in the range
379    * [0.0, 0.8].  Data valid if (valid & PNG_INFO_cHRM) non-zero.
380    */
381   float x_white;
382   float y_white;
383   float x_red;
384   float y_red;
385   float x_green;
386   float y_green;
387   float x_blue;
388   float y_blue;
389#endif /* PNG_READ_cHRM_SUPPORTED || PNG_WRITE_cHRM_SUPPORTED */
390#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
391   /* The pCAL chunk describes a transformation between the stored pixel
392    * values and original physcical data values used to create the image.
393    * The integer range [0, 2^bit_depth - 1] maps to the floating-point
394    * range given by [pcal_X0, pcal_X1], and are further transformed by a
395    * (possibly non-linear) transformation function given by "pcal_type"
396    * and "pcal_params" into "pcal_units".  Please see the PNG_EQUATION_
397    * defines below, and the PNG-Group's Scientific Visualization extension
398    * chunks document png-scivis-19970203 for a complete description of the
399    * transformations and how they should be implemented, as well as the
400    * png-extensions document for a description of the ASCII parameter
401    * strings.  Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
402    */
403   png_charp pcal_purpose;  /* pCAL chunk description string */
404   png_int_32 pcal_X0;      /* minimum value */
405   png_int_32 pcal_X1;      /* maximum value */
406   png_charp pcal_units;    /* Latin-1 string giving physical units */
407   png_charpp pcal_params;  /* ASCII strings containing parameter values */
408   png_byte pcal_type;      /* equation type (see PNG_EQUATION_ below) */
409   png_byte pcal_nparams;   /* number of parameters given in pcal_params */
410#endif /* PNG_READ_pCAL_SUPPORTED || PNG_WRITE_pCAL_SUPPORTED */
411} png_info;
412typedef png_info FAR * png_infop;
413typedef png_info FAR * FAR * png_infopp;
414
415/* These describe the color_type field in png_info. */
416/* color type masks */
417#define PNG_COLOR_MASK_PALETTE    1
418#define PNG_COLOR_MASK_COLOR      2
419#define PNG_COLOR_MASK_ALPHA      4
420
421/* color types.  Note that not all combinations are legal */
422#define PNG_COLOR_TYPE_GRAY 0
423#define PNG_COLOR_TYPE_PALETTE  (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
424#define PNG_COLOR_TYPE_RGB        (PNG_COLOR_MASK_COLOR)
425#define PNG_COLOR_TYPE_RGB_ALPHA  (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
426#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
427
428/* This is for compression type. PNG 1.0 only defines the single type. */
429#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
430#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
431
432/* This is for filter type. PNG 1.0 only defines the single type. */
433#define PNG_FILTER_TYPE_BASE      0 /* Single row per-byte filtering */
434#define PNG_FILTER_TYPE_DEFAULT   PNG_FILTER_TYPE_BASE
435
436/* These are for the interlacing type.  These values should NOT be changed. */
437#define PNG_INTERLACE_NONE        0 /* Non-interlaced image */
438#define PNG_INTERLACE_ADAM7       1 /* Adam7 interlacing */
439#define PNG_INTERLACE_LAST        2 /* Not a valid value */
440
441/* These are for the oFFs chunk.  These values should NOT be changed. */
442#define PNG_OFFSET_PIXEL          0 /* Offset in pixels */
443#define PNG_OFFSET_MICROMETER     1 /* Offset in micrometers (1/10^6 meter) */
444#define PNG_OFFSET_LAST           2 /* Not a valid value */
445
446/* These are for the pCAL chunk.  These values should NOT be changed. */
447#define PNG_EQUATION_LINEAR       0 /* Linear transformation */
448#define PNG_EQUATION_BASE_E       1 /* Exponential base e transform */
449#define PNG_EQUATION_ARBITRARY    2 /* Arbitrary base exponential transform */
450#define PNG_EQUATION_HYPERBOLIC   3 /* Hyperbolic sine transformation */
451#define PNG_EQUATION_LAST         4 /* Not a valid value */
452
453/* These are for the pHYs chunk.  These values should NOT be changed. */
454#define PNG_RESOLUTION_UNKNOWN    0 /* pixels/unknown unit (aspect ratio) */
455#define PNG_RESOLUTION_METER      1 /* pixels/meter */
456#define PNG_RESOLUTION_LAST       2 /* Not a valid value */
457
458/* These are for the sRGB chunk.  These values should NOT be changed. */
459#define PNG_sRGB_INTENT_SATURATION 0
460#define PNG_sRGB_INTENT_PERCEPTUAL 1
461#define PNG_sRGB_INTENT_ABSOLUTE   2
462#define PNG_sRGB_INTENT_RELATIVE   3
463#define PNG_sRGB_INTENT_LAST       4 /* Not a valid value */
464                       
465
466
467/* These determine if an ancillary chunk's data has been successfully read
468 * from the PNG header, or if the application has filled in the corresponding
469 * data in the info_struct to be written into the output file.  The values
470 * of the PNG_INFO_<chunk> defines should NOT be changed.
471 */
472#define PNG_INFO_gAMA 0x0001
473#define PNG_INFO_sBIT 0x0002
474#define PNG_INFO_cHRM 0x0004
475#define PNG_INFO_PLTE 0x0008
476#define PNG_INFO_tRNS 0x0010
477#define PNG_INFO_bKGD 0x0020
478#define PNG_INFO_hIST 0x0040
479#define PNG_INFO_pHYs 0x0080
480#define PNG_INFO_oFFs 0x0100
481#define PNG_INFO_tIME 0x0200
482#define PNG_INFO_pCAL 0x0400
483#define PNG_INFO_sRGB 0x0800   /* GR-P, 0.96a */
484
485/* This is used for the transformation routines, as some of them
486 * change these values for the row.  It also should enable using
487 * the routines for other purposes.
488 */
489typedef struct png_row_info_struct
490{
491   png_uint_32 width; /* width of row */
492   png_uint_32 rowbytes; /* number of bytes in row */
493   png_byte color_type; /* color type of row */
494   png_byte bit_depth; /* bit depth of row */
495   png_byte channels; /* number of channels (1, 2, 3, or 4) */
496   png_byte pixel_depth; /* bits per pixel (depth * channels) */
497} png_row_info;
498
499typedef png_row_info FAR * png_row_infop;
500typedef png_row_info FAR * FAR * png_row_infopp;
501
502/* These are the function types for the I/O functions and for the functions
503 * that allow the user to override the default I/O functions with his or her
504 * own.  The png_error_ptr type should match that of user-supplied warning
505 * and error functions, while the png_rw_ptr type should match that of the
506 * user read/write data functions.
507 */
508typedef struct png_struct_def png_struct;
509typedef png_struct FAR * png_structp;
510
511typedef void (*png_error_ptr) PNGARG((png_structp, png_const_charp));
512typedef void (*png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
513typedef void (*png_flush_ptr) PNGARG((png_structp));
514typedef void (*png_read_status_ptr) PNGARG((png_structp, png_uint_32, int));
515typedef void (*png_write_status_ptr) PNGARG((png_structp, png_uint_32, int));
516#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
517typedef void (*png_progressive_info_ptr) PNGARG((png_structp, png_infop));
518typedef void (*png_progressive_end_ptr) PNGARG((png_structp, png_infop));
519typedef void (*png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
520   png_uint_32, int));
521#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
522
523#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
524    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
525typedef void (*png_user_transform_ptr) PNGARG((png_structp,
526    png_row_infop, png_bytep));
527#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
528
529typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
530typedef void (*png_free_ptr) PNGARG((png_structp, png_structp));
531
532/* The structure that holds the information to read and write PNG files.
533 * The only people who need to care about what is inside of this are the
534 * people who will be modifying the library for their own special needs.
535 * It should NOT be accessed directly by an application, except to store
536 * the jmp_buf.
537 */
538
539struct png_struct_def
540{
541   jmp_buf jmpbuf;            /* used in png_error */
542
543   png_error_ptr error_fn;    /* function for printing errors and aborting */
544   png_error_ptr warning_fn;  /* function for printing warnings */
545   png_voidp error_ptr;       /* user supplied struct for error functions */
546   png_rw_ptr write_data_fn;  /* function for writing output data */
547   png_rw_ptr read_data_fn;   /* function for reading input data */
548#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
549    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
550   png_user_transform_ptr read_user_transform_fn; /* user read transform */
551   png_user_transform_ptr write_user_transform_fn; /* user write transform */
552#endif
553   png_voidp io_ptr;          /* ptr to application struct for I/O functions*/
554
555   png_uint_32 mode;          /* tells us where we are in the PNG file */
556   png_uint_32 flags;         /* flags indicating various things to libpng */
557   png_uint_32 transformations; /* which transformations to perform */
558
559   z_stream zstream;          /* pointer to decompression structure (below) */
560   png_bytep zbuf;            /* buffer for zlib */
561   png_size_t zbuf_size;      /* size of zbuf */
562   int zlib_level;            /* holds zlib compression level */
563   int zlib_method;           /* holds zlib compression method */
564   int zlib_window_bits;      /* holds zlib compression window bits */
565   int zlib_mem_level;        /* holds zlib compression memory level */
566   int zlib_strategy;         /* holds zlib compression strategy */
567
568   png_uint_32 width;         /* width of image in pixels */
569   png_uint_32 height;        /* height of image in pixels */
570   png_uint_32 num_rows;      /* number of rows in current pass */
571   png_uint_32 usr_width;     /* width of row at start of write */
572   png_uint_32 rowbytes;      /* size of row in bytes */
573   png_uint_32 irowbytes;     /* size of current interlaced row in bytes */
574   png_uint_32 iwidth;        /* width of current interlaced row in pixels */
575   png_uint_32 row_number;    /* current row in interlace pass */
576   png_bytep prev_row;        /* buffer to save previous (unfiltered) row */
577   png_bytep row_buf;         /* buffer to save current (unfiltered) row */
578   png_bytep sub_row;         /* buffer to save "sub" row when filtering */
579   png_bytep up_row;          /* buffer to save "up" row when filtering */
580   png_bytep avg_row;         /* buffer to save "avg" row when filtering */
581   png_bytep paeth_row;       /* buffer to save "Paeth" row when filtering */
582   png_row_info row_info;     /* used for transformation routines */
583
584   png_uint_32 idat_size;     /* current IDAT size for read */
585   png_uint_32 crc;           /* current chunk CRC value */
586   png_colorp palette;        /* palette from the input file */
587   png_uint_16 num_palette;   /* number of color entries in palette */
588   png_uint_16 num_trans;     /* number of transparency values */
589   png_byte chunk_name[5];    /* null-terminated name of current chunk */
590   png_byte compression;      /* file compression type (always 0) */
591   png_byte filter;           /* file filter type (always 0) */
592   png_byte interlaced;       /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
593   png_byte pass;             /* current interlace pass (0 - 6) */
594   png_byte do_filter;        /* row filter flags (see PNG_FILTER_ below ) */
595   png_byte color_type;       /* color type of file */
596   png_byte bit_depth;        /* bit depth of file */
597   png_byte usr_bit_depth;    /* bit depth of users row */
598   png_byte pixel_depth;      /* number of bits per pixel */
599   png_byte channels;         /* number of channels in file */
600   png_byte usr_channels;     /* channels at start of write */
601   png_byte sig_bytes;        /* magic bytes read/written from start of file */
602
603#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
604   png_uint_16 filler;           /* filler bytes for pixel expansion */
605#endif /* PNG_READ_FILLER_SUPPORTED */
606#if defined(PNG_READ_bKGD_SUPPORTED)
607   png_byte background_gamma_type;
608   float background_gamma;
609   png_color_16 background;   /* background color in screen gamma space */
610#if defined(PNG_READ_GAMMA_SUPPORTED)
611   png_color_16 background_1; /* background normalized to gamma 1.0 */
612#endif /* PNG_READ_GAMMA && PNG_READ_bKGD_SUPPORTED */
613#endif /* PNG_READ_bKGD_SUPPORTED */
614#if defined(PNG_WRITE_FLUSH_SUPPORTED)
615   png_flush_ptr output_flush_fn;/* Function for flushing output */
616   png_uint_32 flush_dist;    /* how many rows apart to flush, 0 - no flush */
617   png_uint_32 flush_rows;    /* number of rows written since last flush */
618#endif /* PNG_WRITE_FLUSH_SUPPORTED */
619#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
620   int gamma_shift;      /* number of "insignificant" bits 16-bit gamma */
621   float gamma;          /* file gamma value */
622   float screen_gamma;   /* screen gamma value (display_gamma/viewing_gamma */
623#endif /* PNG_READ_GAMMA_SUPPORTED */
624#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
625   png_bytep gamma_table;     /* gamma table for 8 bit depth files */
626   png_bytep gamma_from_1;    /* converts from 1.0 to screen */
627   png_bytep gamma_to_1;      /* converts from file to 1.0 */
628   png_uint_16pp gamma_16_table; /* gamma table for 16 bit depth files */
629   png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
630   png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
631#endif /* PNG_READ_GAMMA_SUPPORTED || PNG_WRITE_GAMMA_SUPPORTED */
632#if defined(PNG_READ_GAMMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED)
633   png_color_8 sig_bit;       /* significant bits in each available channel */
634#endif /* PNG_READ_GAMMA_SUPPORTED || PNG_READ_sBIT_SUPPORTED */
635#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
636   png_color_8 shift;         /* shift for significant bit tranformation */
637#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
638#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
639 || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
640   png_bytep trans;           /* transparency values for paletted files */
641   png_color_16 trans_values; /* transparency values for non-paletted files */
642#endif /* PNG_READ|WRITE_tRNS_SUPPORTED||PNG_READ_EXPAND|BACKGROUND_SUPPORTED */
643   png_read_status_ptr read_row_fn;   /* called after each row is decoded */
644   png_write_status_ptr write_row_fn; /* called after each row is encoded */
645#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
646   png_progressive_info_ptr info_fn; /* called after header data fully read */
647   png_progressive_row_ptr row_fn;   /* called after each prog. row is decoded */
648   png_progressive_end_ptr end_fn;   /* called after image is complete */
649   png_bytep save_buffer_ptr;        /* current location in save_buffer */
650   png_bytep save_buffer;            /* buffer for previously read data */
651   png_bytep current_buffer_ptr;     /* current location in current_buffer */
652   png_bytep current_buffer;         /* buffer for recently used data */
653   png_uint_32 push_length;          /* size of current input chunk */
654   png_uint_32 skip_length;          /* bytes to skip in input data */
655   png_size_t save_buffer_size;      /* amount of data now in save_buffer */
656   png_size_t save_buffer_max;       /* total size of save_buffer */
657   png_size_t buffer_size;           /* total amount of available input data */
658   png_size_t current_buffer_size;   /* amount of data now in current_buffer */
659   int process_mode;                 /* what push library is currently doing */
660   int cur_palette;                  /* current push library palette index */
661#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
662   png_size_t current_text_size;     /* current size of text input data */
663   png_size_t current_text_left;     /* how much text left to read in input */
664   png_charp current_text;           /* current text chunk buffer */
665   png_charp current_text_ptr;       /* current location in current_text */
666#endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_tEXt/zTXt_SUPPORTED */
667#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
668#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
669/* for the Borland special 64K segment handler */
670   png_bytepp offset_table_ptr;
671   png_bytep offset_table;
672   png_uint_16 offset_table_number;
673   png_uint_16 offset_table_count;
674   png_uint_16 offset_table_count_free;
675#endif /* __TURBOC__&&!_Windows&&!__FLAT__ */
676#if defined(PNG_READ_DITHER_SUPPORTED)
677   png_bytep palette_lookup;         /* lookup table for dithering */
678   png_bytep dither_index;           /* index translation for palette files */
679#endif /* PNG_READ_DITHER_SUPPORTED */
680#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED)
681   png_uint_16p hist;                /* histogram */
682#endif
683#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
684   png_byte heuristic_method;        /* heuristic for row filter selection */
685   png_byte num_prev_filters;        /* number of weights for previous rows */
686   png_bytep prev_filters;           /* filter type(s) of previous row(s) */
687   png_uint_16p filter_weights;      /* weight(s) for previous line(s) */
688   png_uint_16p inv_filter_weights;  /* 1/weight(s) for previous line(s) */
689   png_uint_16p filter_costs;        /* relative filter calculation cost */
690   png_uint_16p inv_filter_costs;    /* 1/relative filter calculation cost */
691#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
692#if defined(PNG_TIME_RFC1123_SUPPORTED)
693   png_charp time_buffer;            /* String to hold RFC 1123 time text */
694#endif /* PNG_TIME_RFC1123_SUPPORTED */
695#ifdef PNG_USER_MEM_SUPPORTED
696   png_voidp mem_ptr;                /* user supplied struct for mem functions */
697   png_malloc_ptr malloc_fn;         /* function for allocating memory */
698   png_free_ptr free_fn;             /* function for freeing memory */
699#endif /* PNG_USER_MEM_SUPPORTED */
700};
701
702typedef png_struct FAR * FAR * png_structpp;
703
704/* Here are the function definitions most commonly used.  This is not
705 * the place to find out how to use libpng.  See libpng.txt for the
706 * full explanation, see example.c for the summary.  This just provides
707 * a simple one line of the use of each function.
708 */
709
710/* Tell lib we have already handled the first <num_bytes> magic bytes.
711 * Handling more than 8 bytes from the beginning of the file is an error.
712 */
713extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
714   int num_bytes));
715
716/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
717 * PNG file.  Returns zero if the supplied bytes match the 8-byte PNG
718 * signature, and non-zero otherwise.  Having num_to_check == 0 or
719 * start > 7 will always fail (ie return non-zero).
720 */
721extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
722   png_size_t num_to_check));
723
724/* Simple signature checking function.  This is the same as calling
725 * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
726 */
727extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
728
729/* Allocate and initialize png_ptr struct for reading, and any other memory. */
730extern PNG_EXPORT(png_structp,png_create_read_struct)
731   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
732   png_error_ptr error_fn, png_error_ptr warn_fn));
733
734/* Allocate and initialize png_ptr struct for writing, and any other memory */
735extern PNG_EXPORT(png_structp,png_create_write_struct)
736   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
737   png_error_ptr error_fn, png_error_ptr warn_fn));
738
739#ifdef PNG_USER_MEM_SUPPORTED
740extern PNG_EXPORT(png_structp,png_create_read_struct_2)
741   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
742   png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
743   png_malloc_ptr malloc_fn, png_free_ptr free_fn));
744extern PNG_EXPORT(png_structp,png_create_write_struct_2)
745   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, 
746   png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
747   png_malloc_ptr malloc_fn, png_free_ptr free_fn));
748#endif
749
750/* Write a PNG chunk - size, type, (optional) data, CRC. */
751extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
752   png_bytep chunk_name, png_bytep data, png_size_t length));
753
754/* Write the start of a PNG chunk - length and chunk name. */
755extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
756   png_bytep chunk_name, png_uint_32 length));
757
758/* Write the data of a PNG chunk started with png_write_chunk_start(). */
759extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
760   png_bytep data, png_size_t length));
761
762/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
763extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
764
765/* Allocate and initialize the info structure */
766extern PNG_EXPORT(png_infop,png_create_info_struct)
767   PNGARG((png_structp png_ptr));
768
769/* Initialize the info structure (old interface - NOT DLL EXPORTED) */
770extern void png_info_init PNGARG((png_infop info_ptr));
771
772/* Writes all the PNG information before the image. */
773extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
774   png_infop info_ptr));
775
776/* read the information before the actual image data. */
777extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
778   png_infop info_ptr));
779
780#if defined(PNG_TIME_RFC1123_SUPPORTED)
781extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
782   PNGARG((png_structp png_ptr, png_timep ptime));
783#endif /* PNG_TIME_RFC1123_SUPPORTED */
784
785#if defined(PNG_WRITE_tIME_SUPPORTED)
786/* convert from a struct tm to png_time */
787extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
788   struct tm FAR * ttime));
789
790/* convert from time_t to png_time.  Uses gmtime() */
791extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
792   time_t ttime));
793#endif /* PNG_WRITE_tIME_SUPPORTED */
794
795#if defined(PNG_READ_EXPAND_SUPPORTED)
796/* Expand data to 24 bit RGB, or 8 bit grayscale, with alpha if available. */
797extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
798#endif /* PNG_READ_EXPAND_SUPPORTED */
799
800#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
801/* Use blue, green, red order for pixels. */
802extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
803#endif /* PNG_READ_BGR_SUPPORTED || PNG_WRITE_BGR_SUPPORTED */
804
805#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
806/* Expand the grayscale to 24 bit RGB if necessary. */
807extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
808#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
809
810#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
811/* Reduce RGB to grayscale. (Not yet implemented) */
812extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr));
813#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */
814
815extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
816   png_colorp palette));
817
818#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
819extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
820#endif /* PNG_READ_STRIP_ALPHA_SUPPORTED */
821
822#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
823    defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
824extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
825#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED || PNG_WRITE_SWAP_ALPHA_SUPPORTED */
826
827#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
828    defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
829extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
830#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED || PNG_WRITE_INVERT_ALPHA_SUPPORTED */
831
832#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
833/* Add a filler byte to 24-bit RGB images. */
834extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
835   png_uint_32 filler, int flags));
836
837/* The values of the PNG_FILLER_ defines should NOT be changed */
838#define PNG_FILLER_BEFORE 0
839#define PNG_FILLER_AFTER 1
840#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
841
842#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
843/* Swap bytes in 16 bit depth files. */
844extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
845#endif /* PNG_READ_SWAP_SUPPORTED || PNG_WRITE_SWAP_SUPPORTED */
846
847#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
848/* Use 1 byte per pixel in 1, 2, or 4 bit depth files. */
849extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
850#endif /* PNG_READ_PACK_SUPPORTED || PNG_WRITE_PACK_SUPPORTED */
851
852#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
853/* Swap packing order of pixels in bytes. */
854extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
855#endif /* PNG_READ_PACKSWAP_SUPPORTED || PNG_WRITE_PACKSWAP_SUPPOR */
856
857#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
858/* Converts files to legal bit depths. */
859extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
860   png_color_8p true_bits));
861#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
862
863#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
864    defined(PNG_WRITE_INTERLACING_SUPPORTED)
865/* Have the code handle the interlacing.  Returns the number of passes. */
866extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
867#endif /* PNG_READ_INTERLACING_SUPPORTED || PNG_WRITE_INTERLACING_SUPPORTED */
868
869#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
870/* Invert monocrome files */
871extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
872#endif /* PNG_READ_INVERT_SUPPORTED || PNG_WRITE_INVERT_SUPPORTED */
873
874#if defined(PNG_READ_BACKGROUND_SUPPORTED)
875/* Handle alpha and tRNS by replacing with a background color. */
876extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
877   png_color_16p background_color, int background_gamma_code,
878   int need_expand, double background_gamma));
879#define PNG_BACKGROUND_GAMMA_UNKNOWN 0
880#define PNG_BACKGROUND_GAMMA_SCREEN  1
881#define PNG_BACKGROUND_GAMMA_FILE    2
882#define PNG_BACKGROUND_GAMMA_UNIQUE  3
883#endif /* PNG_READ_BACKGROUND_SUPPORTED */
884
885#if defined(PNG_READ_16_TO_8_SUPPORTED)
886/* strip the second byte of information from a 16 bit depth file. */
887extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
888#endif /* PNG_READ_16_TO_8_SUPPORTED */
889
890#if defined(PNG_READ_DITHER_SUPPORTED)
891/* Turn on dithering, and reduce the palette to the number of colors available. */
892extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
893   png_colorp palette, int num_palette, int maximum_colors,
894   png_uint_16p histogram, int full_dither));
895#endif /* PNG_READ_DITHER_SUPPORTED */
896
897#if defined(PNG_READ_GAMMA_SUPPORTED)
898/* Handle gamma correction. Screen_gamma=(display_gamma/viewing_gamma) */
899extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
900   double screen_gamma, double default_file_gamma));
901#endif /* PNG_READ_GAMMA_SUPPORTED */
902
903#if defined(PNG_WRITE_FLUSH_SUPPORTED)
904/* Set how many lines between output flushes - 0 for no flushing */
905extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
906
907/* Flush the current PNG output buffer */
908extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
909#endif /* PNG_WRITE_FLUSH_SUPPORTED */
910
911/* optional update palette with requested transformations */
912extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
913
914/* optional call to update the users info structure */
915extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
916   png_infop info_ptr));
917
918/* read a one or more rows of image data.*/
919extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
920   png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
921
922/* read a row of data.*/
923extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
924   png_bytep row,
925   png_bytep display_row));
926
927/* read the whole image into memory at once. */
928extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
929   png_bytepp image));
930
931/* write a row of image data */
932extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
933   png_bytep row));
934
935/* write a few rows of image data */
936extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
937   png_bytepp row, png_uint_32 num_rows));
938
939/* write the image data */
940extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
941   png_bytepp image));
942
943/* writes the end of the PNG file. */
944extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
945   png_infop info_ptr));
946
947/* read the end of the PNG file. */
948extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
949   png_infop info_ptr));
950
951/* free any memory associated with the png_info_struct */
952extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
953   png_infopp info_ptr_ptr));
954
955/* free any memory associated with the png_struct and the png_info_structs */
956extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
957   png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
958
959/* free all memory used by the read (old method - NOT DLL EXPORTED) */
960extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
961   png_infop end_info_ptr));
962
963/* free any memory associated with the png_struct and the png_info_structs */
964extern PNG_EXPORT(void,png_destroy_write_struct)
965   PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
966
967/* free any memory used in info_ptr struct (old method - NOT DLL EXPORTED) */
968extern void png_write_destroy_info PNGARG((png_infop info_ptr));
969
970/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
971extern void png_write_destroy PNGARG((png_structp png_ptr));
972
973/* set the libpng method of handling chunk CRC errors */
974extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
975   int crit_action, int ancil_action));
976
977/* Values for png_set_crc_action() to say how to handle CRC errors in
978 * ancillary and critical chunks, and whether to use the data contained
979 * therein.  Note that it is impossible to "discard" data in a critical
980 * chunk.  For versions prior to 0.90, the action was always error/quit,
981 * whereas in version 0.90 and later, the action for CRC errors in ancillary
982 * chunks is warn/discard.  These values should NOT be changed.
983 *
984 *      value                       action:critical     action:ancillary
985 */
986#define PNG_CRC_DEFAULT       0  /* error/quit          warn/discard data */
987#define PNG_CRC_ERROR_QUIT    1  /* error/quit          error/quit        */
988#define PNG_CRC_WARN_DISCARD  2  /* (INVALID)           warn/discard data */
989#define PNG_CRC_WARN_USE      3  /* warn/use data       warn/use data     */
990#define PNG_CRC_QUIET_USE     4  /* quiet/use data      quiet/use data    */
991#define PNG_CRC_NO_CHANGE     5  /* use current value   use current value */
992
993/* These functions give the user control over the scan-line filtering in
994 * libpng and the compression methods used by zlib.  These functions are
995 * mainly useful for testing, as the defaults should work with most users.
996 * Those users who are tight on memory or want faster performance at the
997 * expense of compression can modify them.  See the compression library
998 * header file (zlib.h) for an explination of the compression functions.
999 */
1000
1001/* set the filtering method(s) used by libpng.  Currently, the only valid
1002 * value for "method" is 0.
1003 */
1004extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
1005   int filters));
1006
1007/* Flags for png_set_filter() to say which filters to use.  The flags
1008 * are chosen so that they don't conflict with real filter types
1009 * below, in case they are supplied instead of the #defined constants.
1010 * These values should NOT be changed.
1011 */
1012#define PNG_NO_FILTERS     0x00
1013#define PNG_FILTER_NONE    0x08
1014#define PNG_FILTER_SUB     0x10
1015#define PNG_FILTER_UP      0x20
1016#define PNG_FILTER_AVG     0x40
1017#define PNG_FILTER_PAETH   0x80
1018#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
1019                         PNG_FILTER_AVG | PNG_FILTER_PAETH)
1020
1021/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
1022 * These defines should NOT be changed.
1023 */
1024#define PNG_FILTER_VALUE_NONE  0
1025#define PNG_FILTER_VALUE_SUB   1
1026#define PNG_FILTER_VALUE_UP    2
1027#define PNG_FILTER_VALUE_AVG   3
1028#define PNG_FILTER_VALUE_PAETH 4
1029#define PNG_FILTER_VALUE_LAST  5
1030
1031#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
1032/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
1033 * defines, either the default (minimum-sum-of-absolute-differences), or
1034 * the experimental method (weighted-minimum-sum-of-absolute-differences).
1035 *
1036 * Weights are factors >= 1.0, indicating how important it is to keep the
1037 * filter type consistent between rows.  Larger numbers mean the current
1038 * filter is that many times as likely to be the same as the "num_weights"
1039 * previous filters.  This is cumulative for each previous row with a weight.
1040 * There needs to be "num_weights" values in "filter_weights", or it can be
1041 * NULL if the weights aren't being specified.  Weights have no influence on
1042 * the selection of the first row filter.  Well chosen weights can (in theory)
1043 * improve the compression for a given image.
1044 *
1045 * Costs are factors >= 1.0 indicating the relative decoding costs of a
1046 * filter type.  Higher costs indicate more decoding expense, and are
1047 * therefore less likely to be selected over a filter with lower computational
1048 * costs.  There needs to be a value in "filter_costs" for each valid filter
1049 * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't
1050 * setting the costs.  Costs try to improve the speed of decompression without
1051 * unduly increasing the compressed image size.
1052 *
1053 * A negative weight or cost indicates the default value is to be used, and
1054 * values in the range [0.0, 1.0) indicate the value is to remain unchanged.
1055 * The default values for both weights and costs are currently 1.0, but may
1056 * change if good general weighting/cost heuristics can be found.  If both
1057 * the weights and costs are set to 1.0, this degenerates the WEIGHTED method
1058 * to the UNWEIGHTED method, but with added encoding time/computation.
1059 */
1060extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
1061   int heuristic_method, int num_weights, png_doublep filter_weights,
1062   png_doublep filter_costs));
1063#endif /*  PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
1064
1065/* Heuristic used for row filter selection.  These defines should NOT be
1066 * changed.
1067 */
1068#define PNG_FILTER_HEURISTIC_DEFAULT    0  /* Currently "UNWEIGHTED" */
1069#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1  /* Used by libpng < 0.95 */
1070#define PNG_FILTER_HEURISTIC_WEIGHTED   2  /* Experimental feature */
1071#define PNG_FILTER_HEURISTIC_LAST       3  /* Not a valid value */
1072
1073/* Set the library compression level.  Currently, valid values range from
1074 * 0 - 9, corresponding directly to the zlib compression levels 0 - 9
1075 * (0 - no compression, 9 - "maximal" compression).  Note that tests have
1076 * shown that zlib compression levels 3-6 usually perform as well as level 9
1077 * for PNG images, and do considerably fewer caclulations.  In the future,
1078 * these values may not correspond directly to the zlib compression levels.
1079 */
1080extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
1081   int level));
1082
1083extern PNG_EXPORT(void,png_set_compression_mem_level)
1084   PNGARG((png_structp png_ptr, int mem_level));
1085
1086extern PNG_EXPORT(void,png_set_compression_strategy)
1087   PNGARG((png_structp png_ptr, int strategy));
1088
1089extern PNG_EXPORT(void,png_set_compression_window_bits)
1090   PNGARG((png_structp png_ptr, int window_bits));
1091
1092extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
1093   int method));
1094
1095/* These next functions are called for input/output, memory, and error
1096 * handling.  They are in the file pngrio.c, pngwio.c, and pngerror.c,
1097 * and call standard C I/O routines such as fread(), fwrite(), and
1098 * fprintf().  These functions can be made to use other I/O routines
1099 * at run time for those applications that need to handle I/O in a
1100 * different manner by calling png_set_???_fn().  See libpng.txt for
1101 * more information.
1102 */
1103
1104#if !defined(PNG_NO_STDIO)
1105/* Initialize the input/output for the PNG file to the default functions. */
1106extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, FILE *fp));
1107#endif
1108
1109/* Replace the (error and abort), and warning functions with user
1110 * supplied functions.  If no messages are to be printed you must still
1111 * write and use replacement functions. The replacement error_fn should
1112 * still do a longjmp to the last setjmp location if you are using this
1113 * method of error handling.  If error_fn or warning_fn is NULL, the
1114 * default function will be used.
1115 */
1116extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
1117   png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
1118
1119/* Return the user pointer associated with the error functions */
1120extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
1121
1122/* Replace the default data output functions with a user supplied one(s).
1123 * If buffered output is not used, then output_flush_fn can be set to NULL.
1124 * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
1125 * output_flush_fn will be ignored (and thus can be NULL).
1126 */
1127extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
1128   png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
1129
1130/* Replace the default data input function with a user supplied one. */
1131extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
1132   png_voidp io_ptr, png_rw_ptr read_data_fn));
1133
1134/* Return the user pointer associated with the I/O functions */
1135extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
1136
1137extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
1138   png_read_status_ptr read_row_fn));
1139
1140extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
1141   png_write_status_ptr write_row_fn));
1142
1143#ifdef PNG_USER_MEM_SUPPORTED
1144/* Replace the default memory allocation functions with user supplied one(s). */
1145extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
1146   png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
1147
1148/* Return the user pointer associated with the memory functions */
1149extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
1150#endif /* PNG_USER_MEM_SUPPORTED */
1151
1152#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1153extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
1154   png_ptr, png_user_transform_ptr read_user_transform_fn));
1155#endif
1156
1157#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1158extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
1159   png_ptr, png_user_transform_ptr write_user_transform_fn));
1160#endif
1161
1162#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1163/* Sets the function callbacks for the push reader, and a pointer to a
1164 * user-defined structure available to the callback functions.
1165 */
1166extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
1167   png_voidp progressive_ptr,
1168   png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
1169   png_progressive_end_ptr end_fn));
1170
1171/* returns the user pointer associated with the push read functions */
1172extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
1173   PNGARG((png_structp png_ptr));
1174
1175/* function to be called when data becomes available */
1176extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
1177   png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
1178
1179/* function that combines rows.  Not very much different than the
1180 * png_combine_row() call.  Is this even used?????
1181 */
1182extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
1183   png_bytep old_row, png_bytep new_row));
1184#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
1185
1186extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
1187   png_uint_32 size));
1188
1189/* frees a pointer allocated by png_malloc() */
1190extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
1191
1192#ifdef PNG_USER_MEM_SUPPORTED
1193extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
1194   png_uint_32 size));
1195extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
1196   png_voidp ptr));
1197#endif /* PNG_USER_MEM_SUPPORTED */
1198
1199extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
1200   png_voidp s1, png_voidp s2, png_uint_32 size));
1201
1202extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
1203   png_voidp s1, int value, png_uint_32 size));
1204
1205#if defined(USE_FAR_KEYWORD)  /* memory model conversion function */
1206extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
1207   int check));
1208#endif /* USE_FAR_KEYWORD */
1209
1210/* Fatal error in PNG image of libpng - can't continue */
1211extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
1212   png_const_charp error));
1213
1214/* The same, but the chunk name is prepended to the error string. */
1215extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
1216   png_const_charp error));
1217
1218/* Non-fatal error in libpng.  Can continue, but may have a problem. */
1219extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
1220   png_const_charp message));
1221
1222/* Non-fatal error in libpng, chunk name is prepended to message. */
1223extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
1224   png_const_charp message));
1225
1226/* The png_set_<chunk> functions are for storing values in the png_info_struct.
1227 * Similarly, the png_get_<chunk> calls are used to read values from the
1228 * png_info_struct, either storing the parameters in the passed variables, or
1229 * setting pointers into the png_info_struct where the data is stored.  The
1230 * png_get_<chunk> functions return a non-zero value if the data was available
1231 * in info_ptr, or return zero and do not change any of the parameters if the
1232 * data was not available.
1233 *
1234 * These functions should be used instead of directly accessing png_info
1235 * to avoid problems with future changes in the size and internal layout of
1236 * png_info_struct.
1237 */
1238/* Returns "flag" if chunk data is valid in info_ptr. */
1239extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
1240png_infop info_ptr, png_uint_32 flag));
1241
1242/* Returns number of bytes needed to hold a transformed row. */
1243extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
1244png_infop info_ptr));
1245
1246/* Returns number of color channels in image. */
1247extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
1248png_infop info_ptr));
1249
1250#ifdef PNG_EASY_ACCESS_SUPPORTED
1251/* Returns image width in pixels. */
1252extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
1253png_ptr, png_infop info_ptr));
1254
1255/* Returns image height in pixels. */
1256extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
1257png_ptr, png_infop info_ptr));
1258
1259/* Returns image bit_depth. */
1260extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
1261png_ptr, png_infop info_ptr));
1262
1263/* Returns image color_type. */
1264extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
1265png_ptr, png_infop info_ptr));
1266
1267/* Returns image filter_type. */
1268extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
1269png_ptr, png_infop info_ptr));
1270
1271/* Returns image interlace_type. */
1272extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
1273png_ptr, png_infop info_ptr));
1274
1275/* Returns image compression_type. */
1276extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
1277png_ptr, png_infop info_ptr));
1278
1279/* Returns image resolution in pixels per meter, from pHYs chunk data. */
1280extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
1281png_ptr, png_infop info_ptr));
1282extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
1283png_ptr, png_infop info_ptr));
1284extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
1285png_ptr, png_infop info_ptr));
1286
1287/* Returns pixel aspect ratio, computed from pHYs chunk data.  */
1288extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
1289png_ptr, png_infop info_ptr));
1290
1291/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
1292extern PNG_EXPORT(png_uint_32, png_get_x_offset_pixels) PNGARG((png_structp
1293png_ptr, png_infop info_ptr));
1294extern PNG_EXPORT(png_uint_32, png_get_y_offset_pixels) PNGARG((png_structp
1295png_ptr, png_infop info_ptr));
1296extern PNG_EXPORT(png_uint_32, png_get_x_offset_microns) PNGARG((png_structp
1297png_ptr, png_infop info_ptr));
1298extern PNG_EXPORT(png_uint_32, png_get_y_offset_microns) PNGARG((png_structp
1299png_ptr, png_infop info_ptr));
1300
1301#endif /* PNG_EASY_ACCESS_SUPPORTED */
1302
1303/* Returns pointer to signature string read from PNG header */
1304extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
1305png_infop info_ptr));
1306
1307#if defined(PNG_READ_bKGD_SUPPORTED)
1308extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
1309   png_infop info_ptr, png_color_16p *background));
1310#endif /* PNG_READ_bKGD_SUPPORTED */
1311
1312#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
1313extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
1314   png_infop info_ptr, png_color_16p background));
1315#endif /* PNG_READ_bKGD_SUPPORTED || PNG_WRITE_bKGD_SUPPORTED */
1316
1317#if defined(PNG_READ_cHRM_SUPPORTED)
1318extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
1319   png_infop info_ptr, double *white_x, double *white_y, double *red_x,
1320   double *red_y, double *green_x, double *green_y, double *blue_x,
1321   double *blue_y));
1322#endif /* PNG_READ_cHRM_SUPPORTED */
1323
1324#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
1325extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
1326   png_infop info_ptr, double white_x, double white_y, double red_x,
1327   double red_y, double green_x, double green_y, double blue_x, double blue_y));
1328#endif /* PNG_READ_cHRM_SUPPORTED || PNG_WRITE_cHRM_SUPPORTED */
1329
1330#if defined(PNG_READ_gAMA_SUPPORTED)
1331extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
1332   png_infop info_ptr, double *file_gamma));
1333#endif /* PNG_READ_gAMA_SUPPORTED */
1334
1335#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
1336extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
1337   png_infop info_ptr, double file_gamma));
1338#endif /* PNG_READ_gAMA_SUPPORTED || PNG_WRITE_gAMA_SUPPORTED */
1339
1340#if defined(PNG_READ_hIST_SUPPORTED)
1341extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
1342   png_infop info_ptr, png_uint_16p *hist));
1343#endif /* PNG_READ_hIST_SUPPORTED */
1344
1345#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
1346extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
1347   png_infop info_ptr, png_uint_16p hist));
1348#endif /* PNG_READ_hIST_SUPPORTED || PNG_WRITE_hIST_SUPPORTED */
1349
1350extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
1351   png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
1352   int *bit_depth, int *color_type, int *interlace_type,
1353   int *compression_type, int *filter_type));
1354 
1355extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
1356   png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
1357   int color_type, int interlace_type, int compression_type, int filter_type));
1358
1359#if defined(PNG_READ_oFFs_SUPPORTED)
1360extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
1361   png_infop info_ptr, png_uint_32 *offset_x, png_uint_32 *offset_y,
1362   int *unit_type));
1363#endif /* PNG_READ_oFFs_SUPPORTED */
1364
1365#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
1366extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
1367   png_infop info_ptr, png_uint_32 offset_x, png_uint_32 offset_y,
1368   int unit_type));
1369#endif /* PNG_READ_oFFs_SUPPORTED || PNG_WRITE_oFFs_SUPPORTED */
1370
1371#if defined(PNG_READ_pCAL_SUPPORTED)
1372extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
1373   png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
1374   int *type, int *nparams, png_charp *units, png_charpp *params));
1375#endif /* PNG_READ_pCAL_SUPPORTED */
1376
1377#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
1378extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
1379   png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
1380   int type, int nparams, png_charp units, png_charpp params));
1381#endif /* PNG_READ_pCAL_SUPPORTED || PNG_WRITE_pCAL_SUPPORTED */
1382
1383#if defined(PNG_READ_pHYs_SUPPORTED)
1384extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
1385   png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
1386#endif /* PNG_READ_pHYs_SUPPORTED */
1387
1388#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
1389extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
1390   png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
1391#endif /* PNG_READ_pHYs_SUPPORTED || PNG_WRITE_pHYs_SUPPORTED */
1392
1393extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
1394   png_infop info_ptr, png_colorp *palette, int *num_palette));
1395
1396extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
1397   png_infop info_ptr, png_colorp palette, int num_palette));
1398
1399#if defined(PNG_READ_sBIT_SUPPORTED)
1400extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
1401   png_infop info_ptr, png_color_8p *sig_bit));
1402#endif /* PNG_READ_sBIT_SUPPORTED */
1403
1404#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
1405extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
1406   png_infop info_ptr, png_color_8p sig_bit));
1407#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
1408
1409#if defined(PNG_READ_sRGB_SUPPORTED)
1410extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
1411   png_infop info_ptr, int *intent));
1412#endif /* PNG_READ_sRGB_SUPPORTED */
1413
1414#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
1415extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
1416   png_infop info_ptr, int intent));
1417extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
1418   png_infop info_ptr, int intent));
1419#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
1420
1421#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
1422/* png_get_text also returns the number of text chunks in text_ptr */
1423extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
1424   png_infop info_ptr, png_textp *text_ptr, int *num_text));
1425#endif /* PNG_READ_tEXt_SUPPORTED || PNG_READ_zTXt_SUPPORTED */
1426
1427#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
1428    defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
1429extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
1430   png_infop info_ptr, png_textp text_ptr, int num_text));
1431#endif /* PNG_READ_OR_WRITE_tEXt_OR_zTXt_SUPPORTED */
1432
1433#if defined(PNG_READ_tIME_SUPPORTED)
1434extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
1435   png_infop info_ptr, png_timep *mod_time));
1436#endif /* PNG_READ_tIME_SUPPORTED */
1437
1438#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
1439extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
1440   png_infop info_ptr, png_timep mod_time));
1441#endif /* PNG_READ_tIME_SUPPORTED || PNG_WRITE_tIME_SUPPORTED */
1442
1443#if defined(PNG_READ_tRNS_SUPPORTED)
1444extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
1445   png_infop info_ptr, png_bytep *trans, int *num_trans,
1446   png_color_16p *trans_values));
1447#endif /* PNG_READ_tRNS_SUPPORTED */
1448
1449#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
1450extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
1451   png_infop info_ptr, png_bytep trans, int num_trans,
1452   png_color_16p trans_values));
1453#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
1454
1455/* Define PNG_DEBUG at compile time for debugging information.  Higher
1456 * numbers for PNG_DEBUG mean more debugging information.  This has
1457 * only been added since version 0.95 so it is not implemented throughout
1458 * libpng yet, but more support will be added as needed.
1459 */
1460 
1461#if (PNG_DEBUG > 0)
1462#ifdef PNG_NO_STDIO
1463#include <stdio.h>
1464#endif
1465#ifndef PNG_DEBUG_FILE
1466#define PNG_DEBUG_FILE stderr
1467#endif /* PNG_DEBUG_FILE */
1468
1469#define png_debug(l,m)        if (PNG_DEBUG > l) \
1470                                 DHL_OS_Printf("%s"m,(l==1 ? "\t" : \
1471                                    (l==2 ? "\t\t":(l==3 ? "\t\t\t":""))))
1472#define png_debug1(l,m,p1)    if (PNG_DEBUG > l) \
1473                                 DHL_OS_Printf("%s"m,(l==1 ? "\t" : \
1474                                    (l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1)
1475#define png_debug2(l,m,p1,p2) if (PNG_DEBUG > l) \
1476                                 DHL_OS_Printf("%s"m,(l==1 ? "\t" : \
1477                                    (l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1,p2)
1478#else
1479#define png_debug(l, m)
1480#define png_debug1(l, m, p1)
1481#define png_debug2(l, m, p1, p2)
1482#endif /* (PNG_DEBUG > 0) */
1483
1484#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
1485/* With these routines we avoid an integer divide, which will be slower on
1486 * most machines.  However, it does take more operations than the corresponding
1487 * divide method, so it may be slower on a few RISC systems.  There are two
1488 * shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
1489 *
1490 * Note that the rounding factors are NOT supposed to be the same!  128 and
1491 * 32768 are correct for the NODIV code; 127 and 32767 are correct for the
1492 * standard method.
1493 *
1494 * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
1495 */
1496
1497   /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
1498#  define png_composite(composite, fg, alpha, bg) \
1499     { png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
1500                        (png_uint_16)(bg)*(png_uint_16)(255 - \
1501                        (png_uint_16)(alpha)) + (png_uint_16)128); \
1502       (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
1503#  define png_composite_16(composite, fg, alpha, bg) \
1504     { png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
1505                        (png_uint_32)(bg)*(png_uint_32)(65535L - \
1506                        (png_uint_32)(alpha)) + (png_uint_32)32768L); \
1507       (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
1508
1509#else  /* standard method using integer division */
1510
1511   /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
1512#  define png_composite(composite, fg, alpha, bg) \
1513     (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
1514       (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
1515       (png_uint_16)127) / 255)
1516#  define png_composite_16(composite, fg, alpha, bg) \
1517     (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
1518       (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
1519       (png_uint_32)32767) / (png_uint_32)65535L)
1520
1521#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
1522
1523/* These next functions are used internally in the code.  They generally
1524 * shouldn't be used unless you are writing code to add or replace some
1525 * functionality in libpng.  More information about most functions can
1526 * be found in the files where the functions are located.
1527 */
1528
1529#if defined(PNG_INTERNAL)
1530
1531/* Various modes of operation.  Note that after an init, mode is set to
1532 * zero automatically when the structure is created.
1533 */
1534#define PNG_BEFORE_IHDR       0x00
1535#define PNG_HAVE_IHDR         0x01
1536#define PNG_HAVE_PLTE         0x02
1537#define PNG_HAVE_IDAT         0x04
1538#define PNG_AFTER_IDAT        0x08
1539#define PNG_HAVE_IEND         0x10
1540#define PNG_HAVE_gAMA         0x20
1541#define PNG_HAVE_cHRM         0x40
1542#define PNG_HAVE_sRGB         0x80
1543
1544/* push model modes */
1545#define PNG_READ_SIG_MODE   0
1546#define PNG_READ_CHUNK_MODE 1
1547#define PNG_READ_IDAT_MODE  2
1548#define PNG_SKIP_MODE       3
1549#define PNG_READ_tEXt_MODE  4
1550#define PNG_READ_zTXt_MODE  5
1551#define PNG_READ_DONE_MODE  6
1552#define PNG_ERROR_MODE      7
1553
1554/* flags for the transformations the PNG library does on the image data */
1555#define PNG_BGR                0x0001
1556#define PNG_INTERLACE          0x0002
1557#define PNG_PACK               0x0004
1558#define PNG_SHIFT              0x0008
1559#define PNG_SWAP_BYTES         0x0010
1560#define PNG_INVERT_MONO        0x0020
1561#define PNG_DITHER             0x0040
1562#define PNG_BACKGROUND         0x0080
1563#define PNG_BACKGROUND_EXPAND  0x0100
1564#define PNG_RGB_TO_GRAY        0x0200 /* Not currently implemented */
1565#define PNG_16_TO_8            0x0400
1566#define PNG_RGBA               0x0800
1567#define PNG_EXPAND             0x1000
1568#define PNG_GAMMA              0x2000
1569#define PNG_GRAY_TO_RGB        0x4000
1570#define PNG_FILLER             0x8000
1571#define PNG_PACKSWAP          0x10000L
1572#define PNG_SWAP_ALPHA        0x20000L
1573#define PNG_STRIP_ALPHA       0x40000L
1574#define PNG_INVERT_ALPHA      0x80000L
1575#define PNG_USER_TRANSFORM   0x100000L
1576
1577/* flags for png_create_struct */
1578#define PNG_STRUCT_PNG   0x0001
1579#define PNG_STRUCT_INFO  0x0002
1580
1581/* Scaling factor for filter heuristic weighting calculations */
1582#define PNG_WEIGHT_SHIFT 8
1583#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
1584#define PNG_COST_SHIFT 3
1585#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
1586
1587/* flags for the png_ptr->flags rather than declaring a byte for each one */
1588#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY     0x0001
1589#define PNG_FLAG_ZLIB_CUSTOM_LEVEL        0x0002
1590#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL    0x0004
1591#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS  0x0008
1592#define PNG_FLAG_ZLIB_CUSTOM_METHOD       0x0010
1593#define PNG_FLAG_ZLIB_FINISHED            0x0020
1594#define PNG_FLAG_ROW_INIT                 0x0040
1595#define PNG_FLAG_FILLER_AFTER             0x0080
1596#define PNG_FLAG_CRC_ANCILLARY_USE        0x0100
1597#define PNG_FLAG_CRC_ANCILLARY_NOWARN     0x0200
1598#define PNG_FLAG_CRC_CRITICAL_USE         0x0400
1599#define PNG_FLAG_CRC_CRITICAL_IGNORE      0x0800
1600#define PNG_FLAG_FREE_PALETTE             0x1000
1601#define PNG_FLAG_FREE_TRANS               0x2000
1602#define PNG_FLAG_FREE_HIST                0x4000
1603#define PNG_FLAG_HAVE_CHUNK_HEADER        0x8000L
1604#define PNG_FLAG_WROTE_tIME              0x10000L
1605#define PNG_FLAG_BACKGROUND_IS_GRAY      0x20000L
1606
1607#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
1608                                     PNG_FLAG_CRC_ANCILLARY_NOWARN)
1609
1610#define PNG_FLAG_CRC_CRITICAL_MASK  (PNG_FLAG_CRC_CRITICAL_USE | \
1611                                     PNG_FLAG_CRC_CRITICAL_IGNORE)
1612
1613#define PNG_FLAG_CRC_MASK           (PNG_FLAG_CRC_ANCILLARY_MASK | \
1614                                     PNG_FLAG_CRC_CRITICAL_MASK)
1615
1616/* save typing and make code easier to understand */
1617#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
1618   abs((int)((c1).green) - (int)((c2).green)) + \
1619   abs((int)((c1).blue) - (int)((c2).blue)))
1620
1621/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
1622#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
1623/* place to hold the signature string for a PNG file. */
1624extern png_byte FARDATA png_sig[8];
1625
1626/* Constant strings for known chunk types.  If you need to add a chunk,
1627 * add a string holding the name here.  See png.c for more details.  We
1628 * can't selectively include these, since we still check for chunk in the
1629 * wrong locations with these labels.
1630 */
1631extern png_byte FARDATA png_IHDR[5];
1632extern png_byte FARDATA png_IDAT[5];
1633extern png_byte FARDATA png_IEND[5];
1634extern png_byte FARDATA png_PLTE[5];
1635extern png_byte FARDATA png_bKGD[5];
1636extern png_byte FARDATA png_cHRM[5];
1637extern png_byte FARDATA png_gAMA[5];
1638extern png_byte FARDATA png_hIST[5];
1639extern png_byte FARDATA png_oFFs[5];
1640extern png_byte FARDATA png_pCAL[5];
1641extern png_byte FARDATA png_pHYs[5];
1642extern png_byte FARDATA png_sBIT[5];
1643extern png_byte FARDATA png_sRGB[5];
1644extern png_byte FARDATA png_tEXt[5];
1645extern png_byte FARDATA png_tIME[5];
1646extern png_byte FARDATA png_tRNS[5];
1647extern png_byte FARDATA png_zTXt[5];
1648
1649#endif /* PNG_NO_EXTERN */
1650
1651/* Inline macros to do direct reads of bytes from the input buffer.  These
1652 * require that you are using an architecture that uses PNG byte ordering
1653 * (MSB first) and supports unaligned data storage.  I think that PowerPC
1654 * in big-endian mode and 680x0 are the only ones that will support this.
1655 * The x86 line of processors definitely do not.  The png_get_int_32()
1656 * routine also assumes we are using two's complement format for negative
1657 * values, which is almost certainly true.
1658 */
1659#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
1660#if defined(PNG_READ_pCAL_SUPPORTED)
1661#define png_get_int_32(buf) ( *((png_int_32p) (buf)))
1662#endif /* PNG_READ_pCAL_SUPPORTED */
1663#define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
1664#define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
1665#else
1666#if defined(PNG_READ_pCAL_SUPPORTED)
1667PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
1668#endif /* PNG_READ_pCAL_SUPPORTED */
1669PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
1670PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
1671#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
1672
1673/* Initialize png_ptr struct for reading, and allocate any other memory.
1674 * (old interface - NOT DLL EXPORTED).
1675 */
1676extern void png_read_init PNGARG((png_structp png_ptr));
1677
1678/* Initialize png_ptr struct for writing, and allocate any other memory.
1679 * (old interface - NOT DLL EXPORTED).
1680 */
1681extern void png_write_init PNGARG((png_structp png_ptr));
1682
1683/* allocate memory for an internal libpng struct */
1684PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
1685
1686/* free memory from internal libpng struct */
1687PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
1688
1689PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
1690  malloc_fn));
1691PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
1692   png_free_ptr free_fn));
1693
1694/* free any memory that info_ptr points to and reset struct. */
1695PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
1696   png_infop info_ptr));
1697
1698/* Function to allocate memory for zlib. */
1699PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
1700
1701/* function to free memory for zlib */
1702PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
1703
1704/* reset the CRC variable */
1705PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
1706
1707/* Write the "data" buffer to whatever output you are using. */
1708PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
1709   png_size_t length));
1710
1711/* Read data from whatever input you are using into the "data" buffer */
1712PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
1713   png_size_t length));
1714
1715/* read bytes into buf, and update png_ptr->crc */
1716PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
1717   png_size_t length));
1718
1719/* read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
1720PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
1721
1722/* read the CRC from the file and compare it to the libpng calculated CRC */
1723PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
1724
1725/* Calculate the CRC over a section of data.  Note that we are only
1726 * passing a maximum of 64K on systems that have this as a memory limit,
1727 * since this is the maximum buffer size we can specify.
1728 */
1729PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
1730   png_size_t length));
1731
1732#if defined(PNG_WRITE_FLUSH_SUPPORTED)
1733PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
1734#endif
1735
1736/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
1737 * The only currently known PNG chunk that uses signed numbers is
1738 * the ancillary extension chunk, pCAL.
1739 */
1740PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
1741
1742#if defined(PNG_WRITE_pCAL_SUPPORTED)
1743PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
1744#endif
1745
1746/* Place a 16 bit number into a buffer in PNG byte order.
1747 * The parameter is declared unsigned int, not png_uint_16,
1748 * just to avoid potential problems on pre-ANSI C compilers.
1749 */
1750PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
1751
1752/* simple function to write the signature */
1753PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
1754
1755/* write various chunks */
1756
1757/* Write the IHDR chunk, and update the png_struct with the necessary
1758 * information.
1759 */
1760PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
1761   png_uint_32 height,
1762   int bit_depth, int color_type, int compression_type, int filter_type,
1763   int interlace_type));
1764
1765PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
1766   png_uint_32 num_pal));
1767
1768PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
1769   png_size_t length));
1770
1771PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
1772
1773#if defined(PNG_WRITE_gAMA_SUPPORTED)
1774PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
1775#endif
1776
1777#if defined(PNG_WRITE_sBIT_SUPPORTED)
1778PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
1779   int color_type));
1780#endif
1781
1782#if defined(PNG_WRITE_cHRM_SUPPORTED)
1783PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
1784   double white_x, double white_y,
1785   double red_x, double red_y, double green_x, double green_y,
1786   double blue_x, double blue_y));
1787#endif
1788
1789#if defined(PNG_WRITE_sRGB_SUPPORTED)
1790PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
1791   int intent));
1792#endif
1793
1794#if defined(PNG_WRITE_tRNS_SUPPORTED)
1795PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
1796   png_color_16p values, int number, int color_type));
1797#endif
1798
1799#if defined(PNG_WRITE_bKGD_SUPPORTED)
1800PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
1801   png_color_16p values, int color_type));
1802#endif
1803
1804#if defined(PNG_WRITE_hIST_SUPPORTED)
1805PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
1806   int num_hist));
1807#endif
1808
1809#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
1810    defined(PNG_WRITE_pCAL_SUPPORTED)
1811PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
1812   png_charp key, png_charpp new_key));
1813#endif
1814
1815#if defined(PNG_WRITE_tEXt_SUPPORTED)
1816PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
1817   png_charp text, png_size_t text_len));
1818#endif
1819
1820#if defined(PNG_WRITE_zTXt_SUPPORTED)
1821PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
1822   png_charp text, png_size_t text_len, int compression));
1823#endif
1824
1825#if defined(PNG_WRITE_oFFs_SUPPORTED)
1826PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
1827   png_uint_32 x_offset, png_uint_32 y_offset, int unit_type));
1828#endif
1829
1830#if defined(PNG_WRITE_pCAL_SUPPORTED)
1831PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
1832   png_int_32 X0, png_int_32 X1, int type, int nparams,
1833   png_charp units, png_charpp params));
1834#endif
1835
1836#if defined(PNG_WRITE_pHYs_SUPPORTED)
1837PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
1838   png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
1839   int unit_type));
1840#endif
1841
1842#if defined(PNG_WRITE_tIME_SUPPORTED)
1843PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
1844   png_timep mod_time));
1845#endif
1846
1847/* Called when finished processing a row of data */
1848PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
1849
1850/* Internal use only.   Called before first row of data */
1851PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
1852
1853#if defined(PNG_READ_GAMMA_SUPPORTED)
1854PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
1855#endif
1856
1857/* combine a row of data, dealing with alpha, etc. if requested */
1858PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
1859   int mask));
1860
1861#if defined(PNG_READ_INTERLACING_SUPPORTED)
1862/* expand an interlaced row */
1863PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
1864   png_bytep row, int pass, png_uint_32 transformations));
1865#endif
1866
1867#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
1868/* grab pixels out of a row for an interlaced pass */
1869PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
1870   png_bytep row, int pass));
1871#endif
1872
1873/* unfilter a row */
1874PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
1875   png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
1876
1877/* Choose the best filter to use and filter the row data */
1878PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
1879   png_row_infop row_info));
1880
1881/* Write out the filtered row. */
1882PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
1883   png_bytep filtered_row));
1884/* finish a row while reading, dealing with interlacing passes, etc. */
1885PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
1886
1887/* initialize the row buffers, etc. */
1888PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
1889/* optional call to update the users info structure */
1890PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
1891   png_infop info_ptr));
1892
1893/* these are the functions that do the transformations */
1894#if defined(PNG_READ_FILLER_SUPPORTED)
1895PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
1896   png_bytep row, png_uint_32 filler, png_uint_32 flags));
1897#endif
1898
1899#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
1900PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
1901   png_bytep row));
1902#endif
1903
1904#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
1905PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
1906   png_bytep row));
1907#endif
1908
1909#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
1910PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
1911   png_bytep row));
1912#endif
1913
1914#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
1915PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
1916   png_bytep row));
1917#endif
1918
1919#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
1920    defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
1921PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
1922   png_bytep row, png_uint_32 flags));
1923#endif
1924
1925#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
1926PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
1927#endif
1928
1929#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
1930PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
1931#endif
1932
1933#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
1934PNG_EXTERN void png_do_rgb_to_gray PNGARG((png_row_infop row_info,
1935   png_bytep row));
1936#endif
1937
1938#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
1939PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
1940   png_bytep row));
1941#endif
1942
1943#if defined(PNG_READ_PACK_SUPPORTED)
1944PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
1945#endif
1946
1947#if defined(PNG_READ_SHIFT_SUPPORTED)
1948PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
1949   png_color_8p sig_bits));
1950#endif
1951
1952#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
1953PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
1954#endif
1955
1956#if defined(PNG_READ_16_TO_8_SUPPORTED)
1957PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
1958#endif
1959
1960#if defined(PNG_READ_DITHER_SUPPORTED)
1961PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
1962   png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
1963
1964#  if defined(PNG_CORRECT_PALETTE_SUPPORTED)
1965PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
1966   png_colorp palette, int num_palette));
1967#  endif
1968#endif
1969
1970#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
1971PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
1972#endif
1973
1974#if defined(PNG_WRITE_PACK_SUPPORTED)
1975PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
1976   png_bytep row, png_uint_32 bit_depth));
1977#endif
1978
1979#if defined(PNG_WRITE_SHIFT_SUPPORTED)
1980PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
1981   png_color_8p bit_depth));
1982#endif
1983
1984#if defined(PNG_READ_BACKGROUND_SUPPORTED)
1985PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
1986   png_color_16p trans_values, png_color_16p background,
1987   png_color_16p background_1,
1988   png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
1989   png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
1990   png_uint_16pp gamma_16_to_1, int gamma_shift));
1991#endif
1992
1993#if defined(PNG_READ_GAMMA_SUPPORTED)
1994PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
1995   png_bytep gamma_table, png_uint_16pp gamma_16_table,
1996   int gamma_shift));
1997#endif
1998
1999#if defined(PNG_READ_EXPAND_SUPPORTED)
2000PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
2001   png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
2002PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
2003   png_bytep row, png_color_16p trans_value));
2004#endif
2005
2006/* The following decodes the appropriate chunks, and does error correction,
2007 * then calls the appropriate callback for the chunk if it is valid.
2008 */
2009
2010/* decode the IHDR chunk */
2011PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
2012   png_uint_32 length));
2013PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
2014   png_uint_32 length));
2015PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
2016   png_uint_32 length));
2017
2018#if defined(PNG_READ_gAMA_SUPPORTED)
2019PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
2020   png_uint_32 length));
2021#endif
2022
2023#if defined(PNG_READ_sBIT_SUPPORTED)
2024PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
2025   png_uint_32 length));
2026#endif
2027
2028#if defined(PNG_READ_cHRM_SUPPORTED)
2029PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
2030   png_uint_32 length));
2031#endif
2032
2033#if defined(PNG_READ_sRGB_SUPPORTED)
2034PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
2035   png_uint_32 length));
2036#endif
2037
2038#if defined(PNG_READ_tRNS_SUPPORTED)
2039PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
2040   png_uint_32 length));
2041#endif
2042
2043#if defined(PNG_READ_bKGD_SUPPORTED)
2044PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
2045   png_uint_32 length));
2046#endif
2047
2048#if defined(PNG_READ_hIST_SUPPORTED)
2049PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
2050   png_uint_32 length));
2051#endif
2052
2053#if defined(PNG_READ_oFFs_SUPPORTED)
2054PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
2055   png_uint_32 length));
2056#endif
2057
2058#if defined(PNG_READ_pCAL_SUPPORTED)
2059PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
2060   png_uint_32 length));
2061#endif
2062
2063#if defined(PNG_READ_pHYs_SUPPORTED)
2064PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
2065   png_uint_32 length));
2066#endif
2067
2068#if defined(PNG_READ_tIME_SUPPORTED)
2069PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
2070   png_uint_32 length));
2071#endif
2072
2073#if defined(PNG_READ_tEXt_SUPPORTED)
2074PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
2075   png_uint_32 length));
2076#endif
2077
2078#if defined(PNG_READ_zTXt_SUPPORTED)
2079PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
2080   png_uint_32 length));
2081#endif
2082
2083PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
2084   png_infop info_ptr, png_uint_32 length));
2085
2086PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
2087   png_bytep chunk_name));
2088
2089/* handle the transformations for reading and writing */
2090PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
2091PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
2092
2093PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
2094
2095#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
2096PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
2097   png_infop info_ptr));
2098PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
2099   png_infop info_ptr));
2100PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
2101PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
2102   png_uint_32 length));
2103PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
2104PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
2105   png_bytep buffer, png_size_t length));
2106PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
2107PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
2108   png_bytep buffer, png_size_t buffer_length));
2109PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
2110PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
2111   png_bytep buffer, png_size_t buffer_length));
2112PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
2113PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
2114   png_infop info_ptr, png_uint_32 length));
2115PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
2116   png_infop info_ptr));
2117PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
2118   png_infop info_ptr));
2119PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
2120PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
2121   png_infop info_ptr));
2122PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
2123   png_infop info_ptr));
2124PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
2125#if defined(PNG_READ_tEXt_SUPPORTED)
2126PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
2127   png_infop info_ptr, png_uint_32 length));
2128PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
2129   png_infop info_ptr));
2130#endif
2131#if defined(PNG_READ_zTXt_SUPPORTED)
2132PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
2133   png_infop info_ptr, png_uint_32 length));
2134PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
2135   png_infop info_ptr));
2136#endif
2137
2138#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
2139
2140#endif /* PNG_INTERNAL */
2141
2142#ifdef __cplusplus
2143}
2144#endif
2145
2146/* do not put anything past this line */
2147#endif /* _PNG_H */
Note: See TracBrowser for help on using the repository browser.