png.h 50.6 KB
Newer Older
G
Guy Schalnat 已提交
1 2

/* png.h - header file for png reference library
G
Guy Schalnat 已提交
3

G
Guy Schalnat 已提交
4 5
   libpng 1.0 beta 2 - version 0.87
   Jan 15, 1996
G
Guy Schalnat 已提交
6

G
Guy Schalnat 已提交
7 8 9 10 11 12 13 14
   Note: This is a beta version.  It reads and writes valid files
   on the platforms I have, but it has had limited portability
   testing.  Furthermore, you may have to modify the
   includes below to get it to work on your system, and you
   may have to supply the correct compiler flags in the makefile.
   Read the readme.txt for more information, and how to contact
   me if you have any problems, or if you want your compiler/
   platform to be supported in the next official libpng release.
G
Guy Schalnat 已提交
15

G
Guy Schalnat 已提交
16
   See readme.txt for more information
G
Guy Schalnat 已提交
17

G
Guy Schalnat 已提交
18
   Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
G
Guy Schalnat 已提交
19
   Contributing Authors:
G
Guy Schalnat 已提交
20
      Andreas Dilger
G
Guy Schalnat 已提交
21
      Dave Martindale
G
Guy Schalnat 已提交
22 23 24
      Guy Eric Schalnat
      Paul Schmidt
      Tim Wegner
G
Guy Schalnat 已提交
25

G
Guy Schalnat 已提交
26 27 28
   The contributing authors would like to thank all those who helped
   with testing, bug fixes, and patience.  You know who you are.  This
   wouldn't have been possible without all of you.
G
Guy Schalnat 已提交
29 30

   Thanks to Frank J. T. Wojcik for reviewing the documentation
G
Guy Schalnat 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43

   The PNG Reference Library is supplied "AS IS". The Contributing Authors
   and Group 42, Inc. disclaim all warranties, expressed or implied,
   including, without limitation, the warranties of merchantability and of
   fitness for any purpose. The Contributing Authors and Group 42, Inc.
   assume no liability for damages, direct or consequential, which may
   result from the use of the PNG Reference Library.

   Permission is hereby granted to use, copy, modify, and distribute this
   source code, or portions hereof, for any purpose, without fee, subject
   to the following restrictions:
   1. The origin of this source code must not be misrepresented.
   2. Altered versions must be plainly marked as such and must not be
G
Guy Schalnat 已提交
44 45 46
      misrepresented as being the original source.
   3. This Copyright notice may not be removed or altered from any source or
      altered source distribution.
G
Guy Schalnat 已提交
47

G
Guy Schalnat 已提交
48 49 50 51 52 53
   The Contributing Authors and Group 42, Inc. specifically permit, without
   fee, and encourage the use of this source code as a component to
   supporting the PNG file format in commercial products. If you use this
   source code in a product, acknowledgment is not required but would be
   appreciated.
   */
G
Guy Schalnat 已提交
54 55 56 57 58 59 60 61 62 63 64 65

#ifndef _PNG_H
#define _PNG_H

/* This is not the place to learn how to use libpng.  The file libpng.txt
   describes how to use libpng, and the file example.c summarizes it
   with some code to build around.  This file is useful for looking
   at the actual function definitions and structure components. */

/* include the compression library's header */
#include "zlib.h"

G
Guy Schalnat 已提交
66 67
/* include all user configurable info */
#include "pngconf.h"
G
Guy Schalnat 已提交
68

G
Guy Schalnat 已提交
69 70 71 72
/* This file is arranged in several sections.  The first section details
   the functions most users will use.  The third section describes the
   stub files that users will most likely need to change.  The last
   section contains functions used internally by the code.
G
Guy Schalnat 已提交
73
   */
G
Guy Schalnat 已提交
74

G
Guy Schalnat 已提交
75 76
/* version information for png.h - this should match the version
   number in png.c */
G
Guy Schalnat 已提交
77 78 79 80
#define PNG_LIBPNG_VER_STRING "0.87"
/* careful here.  I wanted to use 087, but that would be octal.  Version
   1.0 will be 100 here, etc. */
#define PNG_LIBPNG_VER 87
G
Guy Schalnat 已提交
81

G
Guy Schalnat 已提交
82 83 84 85 86
/* variables defined in png.c - only it needs to define PNG_NO_EXTERN */
#ifndef PNG_NO_EXTERN
/* version information for c files, stored in png.c. This better match
   the version above. */
extern char png_libpng_ver[];
G
Guy Schalnat 已提交
87 88 89 90 91 92
#endif

/* three color definitions.  The order of the red, green, and blue, (and the
   exact size) is not important, although the size of the fields need to
   be png_byte or png_uint_16 (as defined below).  While png_color_8 and
   png_color_16 have more fields then they need, they are never used in
G
Guy Schalnat 已提交
93
   arrays, so the size isn't that important.  I thought about using
G
Guy Schalnat 已提交
94
   unions, but it looked too clumsy, so I left it. If you're using C++,
G
Guy Schalnat 已提交
95
   you can union red, index, and gray, if you really want too. */
G
Guy Schalnat 已提交
96 97
typedef struct png_color_struct
{
G
Guy Schalnat 已提交
98
   png_byte red;
G
Guy Schalnat 已提交
99 100 101
   png_byte green;
   png_byte blue;
} png_color;
G
Guy Schalnat 已提交
102
typedef png_color       FAR *      png_colorp;
G
Guy Schalnat 已提交
103
typedef png_color       FAR * FAR * png_colorpp;
G
Guy Schalnat 已提交
104 105 106 107 108 109 110

typedef struct png_color_16_struct
{
   png_byte index; /* used for palette files */
   png_uint_16 red; /* for use in red green blue files */
   png_uint_16 green;
   png_uint_16 blue;
G
Guy Schalnat 已提交
111
   png_uint_16 gray; /* for use in grayscale files */
G
Guy Schalnat 已提交
112
} png_color_16;
G
Guy Schalnat 已提交
113
typedef png_color_16    FAR *      png_color_16p;
G
Guy Schalnat 已提交
114
typedef png_color_16    FAR * FAR * png_color_16pp;
G
Guy Schalnat 已提交
115 116 117 118 119 120 121 122 123

typedef struct png_color_8_struct
{
   png_byte red; /* for use in red green blue files */
   png_byte green;
   png_byte blue;
   png_byte gray; /* for use in grayscale files */
   png_byte alpha; /* for alpha channel files */
} png_color_8;
G
Guy Schalnat 已提交
124
typedef png_color_8     FAR *      png_color_8p;
G
Guy Schalnat 已提交
125
typedef png_color_8     FAR * FAR * png_color_8pp;
G
Guy Schalnat 已提交
126 127 128 129 130 131

/* png_text holds the text in a png file, and whether they are compressed
   or not.  If compression is -1, the text is not compressed.  */
typedef struct png_text_struct
{
   int compression; /* compression value, -1 if uncompressed */
G
Guy Schalnat 已提交
132 133 134
   png_charp key; /* keyword */
   png_charp text; /* comment */
   png_uint_32 text_length; /* length of text field */
G
Guy Schalnat 已提交
135
} png_text;
G
Guy Schalnat 已提交
136
typedef png_text        FAR *      png_textp;
G
Guy Schalnat 已提交
137
typedef png_text        FAR * FAR * png_textpp;
G
Guy Schalnat 已提交
138 139 140 141 142 143 144 145 146

/* png_time is a way to hold the time in an machine independent way.
   Two conversions are provided, both from time_t and struct tm.  There
   is no portable way to convert to either of these structures, as far
   as I know.  If you know of a portable way, send it to me. */
typedef struct png_time_struct
{
   png_uint_16 year; /* full year, as in, 1995 */
   png_byte month; /* month of year, 1 - 12 */
G
Guy Schalnat 已提交
147

G
Guy Schalnat 已提交
148 149 150
   png_byte day; /* day of month, 1 - 31 */
   png_byte hour; /* hour of day, 0 - 23 */
   png_byte minute; /* minute of hour, 0 - 59 */
G
Guy Schalnat 已提交
151
   png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
G
Guy Schalnat 已提交
152
} png_time;
G
Guy Schalnat 已提交
153
typedef png_time        FAR *      png_timep;
G
Guy Schalnat 已提交
154
typedef png_time        FAR * FAR * png_timepp;
G
Guy Schalnat 已提交
155 156 157 158 159 160 161 162 163 164

/* png_info is a structure that holds the information in a png file.
   If you are reading the file, This structure will tell you what is
   in the png file.  If you are writing the file, fill in the information
   you want to put into the png file, then call png_write_info().
   The names chosen should be very close to the PNG
   specification, so consult that document for information
   about the meaning of each field. */
typedef struct png_info_struct
{
G
Guy Schalnat 已提交
165
   /* the following are necessary for every png file */
G
Guy Schalnat 已提交
166 167 168
   png_uint_32 width; /* with of file */
   png_uint_32 height; /* height of file */
   png_byte bit_depth; /* 1, 2, 4, 8, or 16 */
G
Guy Schalnat 已提交
169 170
   png_byte color_type; /* use the PNG_COLOR_TYPE_ defines */
   png_byte compression_type; /* must be 0 */
G
Guy Schalnat 已提交
171 172 173 174 175 176 177
   png_byte filter_type; /* must be 0 */
   png_byte interlace_type; /* 0 for non-interlaced, 1 for interlaced */
   png_uint_32 valid; /* the PNG_INFO_ defines, OR'd together */
   /* the following is informational only on read, and not used on
      writes */
   png_byte channels; /* number of channels of data per pixel */
   png_byte pixel_depth; /* number of bits per pixel */
G
Guy Schalnat 已提交
178

G
Guy Schalnat 已提交
179 180 181 182
   png_uint_32 rowbytes; /* bytes needed for untransformed row */
   /* the rest are optional.  If you are reading, check the valid
      field to see if the information in these are valid.  If you
      are writing, set the valid field to those chunks you want
G
Guy Schalnat 已提交
183
      written, and initialize the appropriate fields below */
G
Guy Schalnat 已提交
184
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
G
Guy Schalnat 已提交
185
   float gamma; /* gamma value of file, if gAMA chunk is valid */
G
Guy Schalnat 已提交
186 187
#endif
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
G
Guy Schalnat 已提交
188
   png_color_8 sig_bit; /* significant bits */
G
Guy Schalnat 已提交
189 190
#endif
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
G
Guy Schalnat 已提交
191
   float x_white; /* cHRM chunk values */
G
Guy Schalnat 已提交
192 193 194 195 196 197 198
   float y_white;
   float x_red;
   float y_red;
   float x_green;
   float y_green;
   float x_blue;
   float y_blue;
G
Guy Schalnat 已提交
199
#endif
G
Guy Schalnat 已提交
200
   png_colorp palette; /* palette of file */
G
Guy Schalnat 已提交
201
   png_uint_16 num_palette; /* number of values in palette */
G
Guy Schalnat 已提交
202 203
   png_uint_16 num_trans; /* number of trans values */
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
G
Guy Schalnat 已提交
204
   png_bytep trans; /* tRNS values for palette image */
G
Guy Schalnat 已提交
205
   png_color_16 trans_values; /* tRNS values for non-palette image */
G
Guy Schalnat 已提交
206 207 208
#endif
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)

G
Guy Schalnat 已提交
209
   png_color_16 background; /* background color of image */
G
Guy Schalnat 已提交
210 211
#endif
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
G
Guy Schalnat 已提交
212
   png_uint_16p hist; /* histogram of palette usage */
G
Guy Schalnat 已提交
213 214
#endif
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
G
Guy Schalnat 已提交
215
   png_uint_32 x_pixels_per_unit; /* x resolution */
G
Guy Schalnat 已提交
216 217
   png_uint_32 y_pixels_per_unit; /* y resolution */
   png_byte phys_unit_type; /* resolution type */
G
Guy Schalnat 已提交
218 219
#endif
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
G
Guy Schalnat 已提交
220 221 222
   png_uint_32 x_offset; /* x offset on page */
   png_uint_32 y_offset; /* y offset on page */
   png_byte offset_unit_type; /* offset units type */
G
Guy Schalnat 已提交
223 224
#endif
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
G
Guy Schalnat 已提交
225
   png_time mod_time; /* modification time */
G
Guy Schalnat 已提交
226 227
#endif
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
G
Guy Schalnat 已提交
228 229
    defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
   int num_text; /* number of comments */
G
Guy Schalnat 已提交
230
   int max_text; /* size of text array */
G
Guy Schalnat 已提交
231
   png_textp text; /* array of comments */
G
Guy Schalnat 已提交
232
#endif
G
Guy Schalnat 已提交
233
} png_info;
G
Guy Schalnat 已提交
234
typedef png_info        FAR *      png_infop;
G
Guy Schalnat 已提交
235
typedef png_info        FAR * FAR * png_infopp;
G
Guy Schalnat 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259

#define PNG_RESOLUTION_UNKNOWN 0
#define PNG_RESOLUTION_METER 1

#define PNG_OFFSET_PIXEL 0
#define PNG_OFFSET_MICROMETER 1

/* these describe the color_type field in png_info */

/* color type masks */
#define PNG_COLOR_MASK_PALETTE 1
#define PNG_COLOR_MASK_COLOR 2
#define PNG_COLOR_MASK_ALPHA 4

/* color types.  Note that not all combinations are legal */
#define PNG_COLOR_TYPE_PALETTE \
   (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
#define PNG_COLOR_TYPE_GRAY 0
#define PNG_COLOR_TYPE_RGB_ALPHA \
   (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)

/* These determine if a chunks information is present in a read operation, or
G
Guy Schalnat 已提交
260
   if the chunk should be written in a write operation.  */
G
Guy Schalnat 已提交
261 262 263 264 265 266 267 268 269 270 271
#define PNG_INFO_gAMA 0x0001
#define PNG_INFO_sBIT 0x0002
#define PNG_INFO_cHRM 0x0004
#define PNG_INFO_PLTE 0x0008
#define PNG_INFO_tRNS 0x0010
#define PNG_INFO_bKGD 0x0020
#define PNG_INFO_hIST 0x0040
#define PNG_INFO_pHYs 0x0080
#define PNG_INFO_oFFs 0x0100
#define PNG_INFO_tIME 0x0200

G
Guy Schalnat 已提交
272
/* these determine if a function in the info needs to be freed */
G
Guy Schalnat 已提交
273 274
#define PNG_FREE_PALETTE 0x0001
#define PNG_FREE_HIST 0x0002
G
Guy Schalnat 已提交
275
#define PNG_FREE_TRANS 0x0004
G
Guy Schalnat 已提交
276

G
Guy Schalnat 已提交
277
/* this is used for the transformation routines, as some of them
G
Guy Schalnat 已提交
278
   change these values for the row.  It also should enable using
G
Guy Schalnat 已提交
279 280 281
   the routines for other uses. */
typedef struct png_row_info_struct
{
G
Guy Schalnat 已提交
282 283 284 285 286 287
   png_uint_32 width; /* width of row */
   png_uint_32 rowbytes; /* number of bytes in row */
   png_byte color_type; /* color type of row */
   png_byte bit_depth; /* bit depth of row */
   png_byte channels; /* number of channels (1, 2, 3, or 4) */
   png_byte pixel_depth; /* bits per pixel (depth * channels) */
G
Guy Schalnat 已提交
288 289
} png_row_info;

G
Guy Schalnat 已提交
290
typedef png_row_info    FAR *      png_row_infop;
G
Guy Schalnat 已提交
291
typedef png_row_info    FAR * FAR * png_row_infopp;
G
Guy Schalnat 已提交
292 293 294 295 296 297

/* These are the function types for the I/O functions, and the functions which
 * modify the default I/O functions to user I/O functions.  The png_msg_ptr
 * type should match that of user supplied warning and error functions, while
 * the png_rw_ptr type should match that of the user read/write data functions.
 */
G
Guy Schalnat 已提交
298 299 300 301 302 303
typedef struct png_struct_def png_struct;
typedef png_struct FAR * png_structp;

typedef void (*png_msg_ptr) PNGARG((png_structp, png_const_charp));
typedef void (*png_rw_ptr) PNGARG((png_structp, png_bytep, png_uint_32));
typedef void (*png_flush_ptr) PNGARG((png_structp));
G
Guy Schalnat 已提交
304
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
G
Guy Schalnat 已提交
305 306 307
typedef void (*png_progressive_info_ptr) PNGARG((png_structp, png_infop));
typedef void (*png_progressive_end_ptr) PNGARG((png_structp, png_infop));
typedef void (*png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
G
Guy Schalnat 已提交
308
   png_uint_32, int));
G
Guy Schalnat 已提交
309 310 311
#endif

/* The structure that holds the information to read and write png files.
G
Guy Schalnat 已提交
312 313 314
   The only people who need to care about what is inside of this are the
   people who will be modifying the library for their own special needs.
   */
G
Guy Schalnat 已提交
315

G
Guy Schalnat 已提交
316
struct png_struct_def
G
Guy Schalnat 已提交
317
{
G
Guy Schalnat 已提交
318 319
   jmp_buf jmpbuf; /* used in png_error */
   png_byte mode; /* used to determine where we are in the png file */
G
Guy Schalnat 已提交
320
   png_byte read_mode;
G
Guy Schalnat 已提交
321 322 323 324 325
   png_byte color_type; /* color type of file */
   png_byte bit_depth; /* bit depth of file */
   png_byte interlaced; /* interlace type of file */
   png_byte compession; /* compression type of file */
   png_byte filter; /* filter type */
G
Guy Schalnat 已提交
326
   png_byte channels; /* number of channels in file */
G
Guy Schalnat 已提交
327 328 329
   png_byte pixel_depth; /* number of bits per pixel */
   png_byte usr_bit_depth; /* bit depth of users row */
   png_byte usr_channels; /* channels at start of write */
G
Guy Schalnat 已提交
330
#if defined(PNG_READ_GAMMA_SUPPORTED)
G
Guy Schalnat 已提交
331
   png_byte gamma_shift; /* amount of shift for 16 bit gammas */
G
Guy Schalnat 已提交
332
#endif
G
Guy Schalnat 已提交
333
   png_byte pass; /* current pass (0 - 6) */
G
Guy Schalnat 已提交
334
   png_byte row_init; /* 1 if png_read_start_row() has been called */
G
Guy Schalnat 已提交
335
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
336
   png_byte background_gamma_type;
G
Guy Schalnat 已提交
337
   png_byte background_expand;
G
Guy Schalnat 已提交
338
#endif
G
Guy Schalnat 已提交
339 340
   png_byte zlib_finished;
   png_byte user_palette;
G
Guy Schalnat 已提交
341 342
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
   png_byte filler;
G
Guy Schalnat 已提交
343 344 345 346 347 348 349 350 351
   png_byte filler_loc;
#endif
   png_byte zlib_custom_level; /* one if custom compression level */
   png_byte zlib_custom_method; /* one if custom compression method */
   png_byte zlib_custom_window_bits; /* one if custom compression window bits */
   png_byte zlib_custom_mem_level; /* one if custom compression memory level */
   png_byte zlib_custom_strategy; /* one if custom compression strategy */
   png_byte do_filter; /* one if filtering, zero if not */
   png_byte do_custom_filter; /* one if filtering, zero if not */
G
Guy Schalnat 已提交
352
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
G
Guy Schalnat 已提交
353
   png_byte have_chunk_header;
G
Guy Schalnat 已提交
354
#endif
G
Guy Schalnat 已提交
355 356
   png_uint_16 num_palette; /* number of entries in palette */
   png_uint_16 num_trans; /* number of transparency values */
G
Guy Schalnat 已提交
357 358
   int zlib_level; /* holds zlib compression level */
   int zlib_method; /* holds zlib compression method */
G
Guy Schalnat 已提交
359
   int zlib_window_bits; /* holds zlib compression window bits */
G
Guy Schalnat 已提交
360
   int zlib_mem_level; /* holds zlib compression memory level */
G
Guy Schalnat 已提交
361
   int zlib_strategy; /* holds zlib compression strategy */
G
Guy Schalnat 已提交
362
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
G
Guy Schalnat 已提交
363 364 365 366 367 368 369 370 371 372 373
   int process_mode;
   int cur_palette;
#endif
   png_uint_32 transformations; /* which transformations to perform */
   png_uint_32 crc; /* current crc value */
   png_uint_32 width; /* width of file */
   png_uint_32 height; /* height of file */
   png_uint_32 num_rows; /* number of rows in current pass */
   png_uint_32 rowbytes; /* size of row in bytes */
   png_uint_32 usr_width; /* width of row at start of write */
   png_uint_32 iwidth; /* interlaced width */
G
Guy Schalnat 已提交
374 375
   png_uint_32 irowbytes; /* interlaced rowbytes */
   png_uint_32 row_number; /* current row in pass */
G
Guy Schalnat 已提交
376 377 378
   png_uint_32 idat_size; /* current idat size for read */
   png_uint_32 zbuf_size; /* size of zbuf */
   png_uint_32 do_free; /* flags indicating if libpng should free memory */
G
Guy Schalnat 已提交
379
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
G
Guy Schalnat 已提交
380 381
   png_uint_32 flush_dist;  /* how many rows apart to flush, 0 for no flush */
   png_uint_32 flush_rows;  /* number of rows written since last flush */
G
Guy Schalnat 已提交
382 383
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
G
Guy Schalnat 已提交
384 385 386 387 388 389
   png_uint_32 push_length;
   png_uint_32 skip_length;
   png_uint_32 save_buffer_size;
   png_uint_32 save_buffer_max;
   png_uint_32 buffer_size;
   png_uint_32 current_buffer_size;
G
Guy Schalnat 已提交
390
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
G
Guy Schalnat 已提交
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
   png_uint_32 current_text_size;
   png_uint_32 current_text_left;
   png_charp current_text;
   png_charp current_text_ptr;
#endif
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* for the Borland special 64K segment handler */
   png_bytepp offset_table_ptr;
   png_bytep offset_table;
   png_uint_16 offset_table_number;
   png_uint_16 offset_table_count;
   png_uint_16 offset_table_count_free;
#endif
   png_byte push_chunk_name[4];
   png_bytep save_buffer_ptr;
   png_bytep save_buffer;
   png_bytep current_buffer_ptr;
   png_bytep current_buffer;
#endif
   png_colorp palette; /* files palette */
G
Guy Schalnat 已提交
411
#if defined(PNG_READ_DITHER_SUPPORTED)
G
Guy Schalnat 已提交
412
   png_bytep palette_lookup; /* lookup table for dithering */
G
Guy Schalnat 已提交
413 414
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
415
   png_bytep gamma_table; /* gamma table for 8 bit depth files */
G
Guy Schalnat 已提交
416
#endif
G
Guy Schalnat 已提交
417
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
418 419
   png_bytep gamma_from_1; /* converts from 1.0 to screen */
   png_bytep gamma_to_1; /* converts from file to 1.0 */
G
Guy Schalnat 已提交
420 421
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
422
   png_bytep trans; /* transparency values for paletted files */
G
Guy Schalnat 已提交
423 424
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
G
Guy Schalnat 已提交
425
   png_bytep dither_index; /* index translation for palette files */
G
Guy Schalnat 已提交
426 427
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
428
   png_uint_16pp gamma_16_table; /* gamma table for 16 bit depth files */
G
Guy Schalnat 已提交
429 430
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
431 432
   png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
   png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
G
Guy Schalnat 已提交
433 434
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
G
Guy Schalnat 已提交
435
   png_uint_16p hist; /* histogram */
G
Guy Schalnat 已提交
436
#endif
G
Guy Schalnat 已提交
437 438 439 440
   png_bytep zbuf; /* buffer for zlib */
   png_bytep row_buf; /* row buffer */
   png_bytep prev_row; /* previous row */
   png_bytep save_row; /* place to save row before filtering */
G
Guy Schalnat 已提交
441
   z_stream * zstream; /* pointer to decompression structure (below) */
G
Guy Schalnat 已提交
442
#if defined(PNG_READ_GAMMA_SUPPORTED)
G
Guy Schalnat 已提交
443 444
   float gamma; /* file gamma value */
   float display_gamma; /* display gamma value */
G
Guy Schalnat 已提交
445 446
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
447
   float background_gamma;
G
Guy Schalnat 已提交
448 449
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
G
Guy Schalnat 已提交
450
   png_color_8 shift; /* shift for significant bit tranformation */
G
Guy Schalnat 已提交
451
#endif
G
Guy Schalnat 已提交
452
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined (PNG_READ_sBIT_SUPPORTED)
G
Guy Schalnat 已提交
453
   png_color_8 sig_bit; /* significant bits in file */
G
Guy Schalnat 已提交
454 455
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
456
   png_color_16 trans_values; /* transparency values for non-paletted files */
G
Guy Schalnat 已提交
457
   png_color_16 background; /* background color, gamma corrected for screen */
G
Guy Schalnat 已提交
458
#if defined(PNG_READ_GAMMA_SUPPORTED)
G
Guy Schalnat 已提交
459
   png_color_16 background_1; /* background normalized to gamma 1.0 */
G
Guy Schalnat 已提交
460 461
#endif
#endif
G
Guy Schalnat 已提交
462
   png_row_info row_info; /* used for transformation routines */
G
Guy Schalnat 已提交
463 464 465 466 467
   FILE *fp; /* used for default png_read and png_write */
   png_msg_ptr error_fn;         /* Function for printing errors and aborting */
   png_msg_ptr warning_fn;       /* Function for printing warnings */
   png_rw_ptr write_data_fn;     /* Function for writing output data */
   png_rw_ptr read_data_fn;      /* Function for reading input data */
G
Guy Schalnat 已提交
468
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
G
Guy Schalnat 已提交
469
   png_flush_ptr output_flush_fn;/* Function for flushing output */
G
Guy Schalnat 已提交
470
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
G
Guy Schalnat 已提交
471
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
G
Guy Schalnat 已提交
472 473 474 475
   png_progressive_info_ptr info_fn;
   png_progressive_row_ptr row_fn;
   png_progressive_end_ptr end_fn;
   png_voidp push_ptr;
G
Guy Schalnat 已提交
476
#endif
G
Guy Schalnat 已提交
477 478
   png_voidp io_ptr;  /* Pointer to user supplied struct for I/O functions */
   png_voidp msg_ptr;  /* Pointer to user supplied struct for message functions */
G
Guy Schalnat 已提交
479
};
G
Guy Schalnat 已提交
480

G
Guy Schalnat 已提交
481 482
typedef png_struct      FAR * FAR * png_structpp;

G
Guy Schalnat 已提交
483
/* Here are the function definitions most commonly used.  This is not
G
Guy Schalnat 已提交
484 485 486
   the place to find out how to use libpng.  See libpng.txt for the
   full explanation, see example.c for the summary.  This just provides
   a simple one line of the use of each function. */
G
Guy Schalnat 已提交
487 488

/* check the first 1 - 8 bytes to see if it is a png file */
G
Guy Schalnat 已提交
489
extern int png_check_sig PNGARG((png_bytep sig, int num));
G
Guy Schalnat 已提交
490 491

/* initialize png structure for reading, and allocate any memory needed */
G
Guy Schalnat 已提交
492
extern void png_read_init PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
493 494

/* initialize png structure for writing, and allocate any memory needed */
G
Guy Schalnat 已提交
495
extern void png_write_init PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
496 497

/* initialize the info structure */
G
Guy Schalnat 已提交
498
extern void png_info_init PNGARG((png_infop info));
G
Guy Schalnat 已提交
499 500

/* Writes all the png information before the image. */
G
Guy Schalnat 已提交
501
extern void png_write_info PNGARG((png_structp png_ptr, png_infop info));
G
Guy Schalnat 已提交
502 503

/* read the information before the actual image data. */
G
Guy Schalnat 已提交
504
extern void png_read_info PNGARG((png_structp png_ptr, png_infop info));
G
Guy Schalnat 已提交
505

G
Guy Schalnat 已提交
506
#if defined(PNG_WRITE_tIME_SUPPORTED)
G
Guy Schalnat 已提交
507
/* convert from a struct tm to png_time */
G
Guy Schalnat 已提交
508 509
extern void png_convert_from_struct_tm PNGARG((png_timep ptime,
   struct tm FAR * ttime)); /*SJT: struct tm FAR *tttime ??? */
G
Guy Schalnat 已提交
510 511

/* convert from time_t to png_time.  Uses gmtime() */
G
Guy Schalnat 已提交
512
extern void png_convert_from_time_t PNGARG((png_timep ptime, time_t ttime));
G
Guy Schalnat 已提交
513
#endif
G
Guy Schalnat 已提交
514

G
Guy Schalnat 已提交
515
#if defined(PNG_READ_EXPAND_SUPPORTED)
G
Guy Schalnat 已提交
516 517
/* Expand the data to 24 bit RGB, or 8 bit Grayscale,
   with alpha if necessary. */
G
Guy Schalnat 已提交
518
extern void png_set_expand PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
519
#endif
G
Guy Schalnat 已提交
520

G
Guy Schalnat 已提交
521
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
G
Guy Schalnat 已提交
522
/* Use blue, green, red order for pixels. */
G
Guy Schalnat 已提交
523
extern void png_set_bgr PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
524 525
#endif

G
Guy Schalnat 已提交
526 527 528 529 530
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* Expand the grayscale to 24 bit RGB if necessary. */
extern void png_set_gray_to_rgb PNGARG((png_structp png_ptr));
#endif

G
Guy Schalnat 已提交
531 532 533 534
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
#define PNG_FILLER_BEFORE 0
#define PNG_FILLER_AFTER 1
/* Add a filler byte to rgb images. */
G
Guy Schalnat 已提交
535
extern void png_set_filler PNGARG((png_structp png_ptr, int filler,
G
Guy Schalnat 已提交
536 537 538 539
   int filler_loc));

/* old ways of doing this, still supported through 1.x for backwards
   compatability, but not suggested */
G
Guy Schalnat 已提交
540 541

/* Add a filler byte to rgb images after the colors. */
G
Guy Schalnat 已提交
542
extern void png_set_rgbx PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
543 544

/* Add a filler byte to rgb images before the colors. */
G
Guy Schalnat 已提交
545
extern void png_set_xrgb PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
546
#endif
G
Guy Schalnat 已提交
547

G
Guy Schalnat 已提交
548
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
G
Guy Schalnat 已提交
549
/* Swap bytes in 16 bit depth files. */
G
Guy Schalnat 已提交
550
extern void png_set_swap PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
551
#endif
G
Guy Schalnat 已提交
552

G
Guy Schalnat 已提交
553
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
G
Guy Schalnat 已提交
554
/* Use 1 byte per pixel in 1, 2, or 4 bit depth files. */
G
Guy Schalnat 已提交
555
extern void png_set_packing PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
556
#endif
G
Guy Schalnat 已提交
557

G
Guy Schalnat 已提交
558
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
G
Guy Schalnat 已提交
559
/* Converts files to legal bit depths. */
G
Guy Schalnat 已提交
560 561
extern void png_set_shift PNGARG((png_structp png_ptr,
   png_color_8p true_bits));
G
Guy Schalnat 已提交
562
#endif
G
Guy Schalnat 已提交
563

G
Guy Schalnat 已提交
564 565
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
    defined(PNG_WRITE_INTERLACING_SUPPORTED)
G
Guy Schalnat 已提交
566
/* Have the code handle the interlacing.  Returns the number of passes. */
G
Guy Schalnat 已提交
567
extern int png_set_interlace_handling PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
568
#endif
G
Guy Schalnat 已提交
569

G
Guy Schalnat 已提交
570
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
G
Guy Schalnat 已提交
571
/* Invert monocrome files */
G
Guy Schalnat 已提交
572
extern void png_set_invert_mono PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
573
#endif
G
Guy Schalnat 已提交
574

G
Guy Schalnat 已提交
575
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
576 577 578 579 580
/* Handle alpha and tRNS by replacing with a background color. */
#define PNG_BACKGROUND_GAMMA_SCREEN 0
#define PNG_BACKGROUND_GAMMA_FILE 1
#define PNG_BACKGROUND_GAMMA_UNIQUE 2
#define PNG_BACKGROUND_GAMMA_UNKNOWN 3
G
Guy Schalnat 已提交
581
extern void png_set_background PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
582
   png_color_16p background_color, int background_gamma_code,
G
Guy Schalnat 已提交
583 584
   int need_expand, double background_gamma));
#endif
G
Guy Schalnat 已提交
585

G
Guy Schalnat 已提交
586
#if defined(PNG_READ_16_TO_8_SUPPORTED)
G
Guy Schalnat 已提交
587
/* strip the second byte of information from a 16 bit depth file. */
G
Guy Schalnat 已提交
588
extern void png_set_strip_16 PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
589
#endif
G
Guy Schalnat 已提交
590

G
Guy Schalnat 已提交
591
#if defined(PNG_GRAY_TO_RGB_SUPPORTED)
G
Guy Schalnat 已提交
592
/* convert a grayscale file into rgb. */
G
Guy Schalnat 已提交
593
extern void png_set_gray_to_rgb PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
594
#endif
G
Guy Schalnat 已提交
595

G
Guy Schalnat 已提交
596
#if defined(PNG_READ_DITHER_SUPPORTED)
G
Guy Schalnat 已提交
597
/* Turn on dithering, and reduce the palette to the number of colors available. */
G
Guy Schalnat 已提交
598
extern void png_set_dither PNGARG((png_structp png_ptr, png_colorp palette,
G
Guy Schalnat 已提交
599 600
   int num_palette, int maximum_colors, png_uint_16p histogram,
   int full_dither));
G
Guy Schalnat 已提交
601
#endif
G
Guy Schalnat 已提交
602

G
Guy Schalnat 已提交
603
#if defined(PNG_READ_GAMMA_SUPPORTED)
G
Guy Schalnat 已提交
604
/* Handle gamma correction. */
G
Guy Schalnat 已提交
605
extern void png_set_gamma PNGARG((png_structp png_ptr, double screen_gamma,
G
Guy Schalnat 已提交
606 607
   double default_file_gamma));
#endif
G
Guy Schalnat 已提交
608

G
Guy Schalnat 已提交
609 610
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
/* Set how many lines between output flushes - 0 for no flushing */
G
Guy Schalnat 已提交
611
extern void png_set_flush PNGARG((png_structp png_ptr, int nrows));
G
Guy Schalnat 已提交
612 613

/* Flush the current PNG output buffer */
G
Guy Schalnat 已提交
614
extern void png_write_flush PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
615 616
#endif /* PNG_WRITE_FLUSH_SUPPORTED */

G
Guy Schalnat 已提交
617
/* optional update palette with requested transformations */
G
Guy Schalnat 已提交
618
extern void png_start_read_image PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
619 620

/* optional call to update the users info structure */
G
Guy Schalnat 已提交
621
extern void png_read_update_info PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
622
   png_infop info_ptr));
G
Guy Schalnat 已提交
623 624

/* read a one or more rows of image data.*/
G
Guy Schalnat 已提交
625
extern void png_read_rows PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
626 627
   png_bytepp row,
   png_bytepp display_row, png_uint_32 num_rows));
G
Guy Schalnat 已提交
628 629

/* read a row of data.*/
G
Guy Schalnat 已提交
630
extern void png_read_row PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
631 632
   png_bytep row,
   png_bytep display_row));
G
Guy Schalnat 已提交
633 634

/* read the whole image into memory at once. */
G
Guy Schalnat 已提交
635
extern void png_read_image PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
636
   png_bytepp image));
G
Guy Schalnat 已提交
637 638

/* write a row of image data */
G
Guy Schalnat 已提交
639
extern void png_write_row PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
640
   png_bytep row));
G
Guy Schalnat 已提交
641 642

/* write a few rows of image data */
G
Guy Schalnat 已提交
643 644
extern void png_write_rows PNGARG((png_structp png_ptr,
   png_bytepp row,
G
Guy Schalnat 已提交
645 646 647
   png_uint_32 num_rows));

/* write the image data */
G
Guy Schalnat 已提交
648
extern void png_write_image PNGARG((png_structp png_ptr, png_bytepp image));
G
Guy Schalnat 已提交
649 650

/* writes the end of the png file. */
G
Guy Schalnat 已提交
651
extern void png_write_end PNGARG((png_structp png_ptr, png_infop info));
G
Guy Schalnat 已提交
652 653

/* read the end of the png file. */
G
Guy Schalnat 已提交
654
extern void png_read_end PNGARG((png_structp png_ptr, png_infop info));
G
Guy Schalnat 已提交
655 656

/* free all memory used by the read */
G
Guy Schalnat 已提交
657
extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
658
   png_infop end_info));
G
Guy Schalnat 已提交
659 660

/* free any memory used in png struct */
G
Guy Schalnat 已提交
661
extern void png_write_destroy PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
662

G
Guy Schalnat 已提交
663 664 665
/* These functions give the user control over the filtering and
   compression libraries used by zlib.  These functions are mainly
   useful for testing, as the defaults should work with most users.
G
Guy Schalnat 已提交
666
   Those users who are tight on memory, or are wanting faster
G
Guy Schalnat 已提交
667 668 669
   performance at the expense of compression can modify them.
   See the compression library header file for an explination
   of these functions */
G
Guy Schalnat 已提交
670
extern void png_set_filtering PNGARG((png_structp png_ptr, int filter));
G
Guy Schalnat 已提交
671

G
Guy Schalnat 已提交
672
extern void png_set_compression_level PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
673 674
   int level));

G
Guy Schalnat 已提交
675
extern void png_set_compression_mem_level PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
676 677
   int mem_level));

G
Guy Schalnat 已提交
678
extern void png_set_compression_strategy PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
679 680
   int strategy));

G
Guy Schalnat 已提交
681
extern void png_set_compression_window_bits PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
682 683
   int window_bits));

G
Guy Schalnat 已提交
684
extern void png_set_compression_method PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
685
   int method));
G
Guy Schalnat 已提交
686

G
Guy Schalnat 已提交
687
/* These next functions are stubs of typical c functions for input/output,
G
Guy Schalnat 已提交
688 689 690 691
   memory, and error handling.  They are in the file pngio.c, and pngerror.c.
   These functions can be replaced at run time for those applications that
   need to handle I/O in a different manner.  See the file libpng.txt for
   more information */
G
Guy Schalnat 已提交
692

G
Guy Schalnat 已提交
693 694 695
/* Write the data to whatever output you are using. */
extern void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
   png_uint_32 length));
G
Guy Schalnat 已提交
696

G
Guy Schalnat 已提交
697 698
/* Read data from whatever input you are using */
extern void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
G
Guy Schalnat 已提交
699
   png_uint_32 length));
G
Guy Schalnat 已提交
700

G
Guy Schalnat 已提交
701
/* Initialize the input/output for the png file to the default functions. */
G
Guy Schalnat 已提交
702
extern void png_init_io PNGARG((png_structp png_ptr, FILE *fp));
G
Guy Schalnat 已提交
703

G
Guy Schalnat 已提交
704
/* Replace the error message and abort, and warning functions with user
G
Guy Schalnat 已提交
705 706 707 708 709
   supplied functions.  If no messages are to be printed then you must
   supply replacement message functions. The replacement error_fn should
   still do a longjmp to the last setjmp location if you are using this
   method of error handling.  If error_fn or warning_fn is NULL, the
   default functions will be used. */
G
Guy Schalnat 已提交
710
extern void png_set_message_fn PNGARG((png_structp png_ptr, png_voidp msg_ptr,
G
Guy Schalnat 已提交
711
   png_msg_ptr error_fn, png_msg_ptr warning_fn));
G
Guy Schalnat 已提交
712

G
Guy Schalnat 已提交
713
/* Return the user pointer associated with the message functions */
G
Guy Schalnat 已提交
714
extern png_voidp png_get_msg_ptr PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
715 716

/* Replace the default data output functions with a user supplied one(s).
G
Guy Schalnat 已提交
717 718 719
   If buffered output is not used, then output_flush_fn can be set to NULL.
   If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
   output_flush_fn will be ignored (and thus can be NULL). */
G
Guy Schalnat 已提交
720
extern void png_set_write_fn PNGARG((png_structp png_ptr, png_voidp io_ptr,
G
Guy Schalnat 已提交
721
   png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
G
Guy Schalnat 已提交
722 723

/* Replace the default data input function with a user supplied one. */
G
Guy Schalnat 已提交
724 725
extern void png_set_read_fn PNGARG((png_structp png_ptr, png_voidp io_ptr,
   png_rw_ptr read_data_fn));
G
Guy Schalnat 已提交
726 727

/* Return the user pointer associated with the I/O functions */
G
Guy Schalnat 已提交
728 729
extern png_voidp png_get_io_ptr PNGARG((png_structp png_ptr));

G
Guy Schalnat 已提交
730
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
G
Guy Schalnat 已提交
731 732
/* Replace the default push model read functions */
extern void png_set_push_fn PNGARG((png_structp png_ptr, png_voidp push_ptr,
G
Guy Schalnat 已提交
733 734
   png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
   png_progressive_end_ptr end_fn));
G
Guy Schalnat 已提交
735

G
Guy Schalnat 已提交
736
/* returns the user pointer associated with the push read functions */
G
Guy Schalnat 已提交
737
extern png_voidp png_get_progressive_ptr PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
738
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
G
Guy Schalnat 已提交
739 740

extern png_voidp png_large_malloc PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
741
   png_uint_32 size));
G
Guy Schalnat 已提交
742 743 744 745 746

/* free's a pointer allocated by png_large_malloc() */
extern void png_large_free PNGARG((png_structp png_ptr, png_voidp ptr));

/* Allocate memory. */
G
Guy Schalnat 已提交
747
extern void * png_malloc PNGARG((png_structp png_ptr, png_uint_32 size));
G
Guy Schalnat 已提交
748 749

/* Reallocate memory. */
G
Guy Schalnat 已提交
750
extern void * png_realloc PNGARG((png_structp png_ptr, void * ptr,
G
Guy Schalnat 已提交
751 752 753
   png_uint_32 size, png_uint_32 old_size));

/* free's a pointer allocated by png_malloc() */
G
Guy Schalnat 已提交
754
extern void png_free PNGARG((png_structp png_ptr, void * ptr));
G
Guy Schalnat 已提交
755 756 757 758 759 760

/* Fatal error in libpng - can't continue */ 
extern void png_error PNGARG((png_structp png_ptr, png_const_charp error));

/* Non-fatal error in libpng.  Can continue, but may have a problem. */
extern void png_warning PNGARG((png_structp png_ptr, png_const_charp message));
G
Guy Schalnat 已提交
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781

/* These next functions are used internally in the code.  If you use
   them, make sure you read and understand the png spec.  More information
   about them can be found in the files where the functions are.
   Feel free to move any of these outside the PNG_INTERNAL define if
   you just need a few of them, but if you need access to more, you should
   define PNG_INTERNAL inside your code, so everyone who includes png.h
   won't get yet another definition the compiler has to deal with. */

#ifdef PNG_INTERNAL

/* various modes of operation.  Note that after an init, mode is set to
   zero automatically */
#define PNG_BEFORE_IHDR 0
#define PNG_HAVE_IHDR 1
#define PNG_HAVE_PLTE 2
#define PNG_HAVE_IDAT 3
#define PNG_AT_LAST_IDAT 4
#define PNG_AFTER_IDAT 5
#define PNG_AFTER_IEND 6

G
Guy Schalnat 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
/* push model modes */
#define PNG_READ_SIG_MODE 0
#define PNG_READ_CHUNK_MODE 1
#define PNG_READ_IDAT_MODE 2
#define PNG_READ_PLTE_MODE 3
#define PNG_READ_END_MODE 4
#define PNG_SKIP_MODE 5
#define PNG_READ_tEXt_MODE 6
#define PNG_READ_zTXt_MODE 7
#define PNG_READ_DONE_MODE 8
#define PNG_ERROR_MODE 9

/* read modes */
#define PNG_READ_PULL_MODE 0
#define PNG_READ_PUSH_MODE 1

G
Guy Schalnat 已提交
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
/* defines for the transformations the png library does on the image data */
#define PNG_BGR 0x0001
#define PNG_INTERLACE 0x0002
#define PNG_PACK 0x0004
#define PNG_SHIFT 0x0008
#define PNG_SWAP_BYTES 0x0010
#define PNG_INVERT_MONO 0x0020
#define PNG_DITHER 0x0040
#define PNG_BACKGROUND 0x0080
#define PNG_XRGB 0x0100
#define PNG_16_TO_8 0x0200
#define PNG_RGBA 0x0400
#define PNG_EXPAND 0x0800
#define PNG_GAMMA 0x1000
#define PNG_GRAY_TO_RGB 0x2000
G
Guy Schalnat 已提交
813
#define PNG_FILLER 0x4000
G
Guy Schalnat 已提交
814 815 816 817 818 819 820 821 822 823 824

/* save typing and make code easier to understand */
#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
   abs((int)((c1).green) - (int)((c2).green)) + \
   abs((int)((c1).blue) - (int)((c2).blue)))

/* variables defined in png.c - only it needs to define PNG_NO_EXTERN */
#ifndef PNG_NO_EXTERN
/* place to hold the signiture string for a png file. */
extern png_byte png_sig[];

G
Guy Schalnat 已提交
825 826 827
/* version information for c files, stored in png.c. */
extern char png_libpng_ver[];

G
Guy Schalnat 已提交
828 829
/* constant strings for known chunk types.  If you need to add a chunk,
   add a string holding the name here.  See png.c for more details */
G
Guy Schalnat 已提交
830 831 832 833
extern png_byte FARDATA png_IHDR[];
extern png_byte FARDATA png_IDAT[];
extern png_byte FARDATA png_IEND[];
extern png_byte FARDATA png_PLTE[];
G
Guy Schalnat 已提交
834
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
G
Guy Schalnat 已提交
835
extern png_byte FARDATA png_gAMA[];
G
Guy Schalnat 已提交
836 837
#endif
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
G
Guy Schalnat 已提交
838
extern png_byte FARDATA png_sBIT[];
G
Guy Schalnat 已提交
839 840
#endif
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
G
Guy Schalnat 已提交
841
extern png_byte FARDATA png_cHRM[];
G
Guy Schalnat 已提交
842 843
#endif
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
G
Guy Schalnat 已提交
844
extern png_byte FARDATA png_tRNS[];
G
Guy Schalnat 已提交
845 846
#endif
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
G
Guy Schalnat 已提交
847
extern png_byte FARDATA png_bKGD[];
G
Guy Schalnat 已提交
848 849
#endif
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
G
Guy Schalnat 已提交
850
extern png_byte FARDATA png_hIST[];
G
Guy Schalnat 已提交
851 852
#endif
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED)
G
Guy Schalnat 已提交
853
extern png_byte FARDATA png_tEXt[];
G
Guy Schalnat 已提交
854 855
#endif
#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
G
Guy Schalnat 已提交
856
extern png_byte FARDATA png_zTXt[];
G
Guy Schalnat 已提交
857 858
#endif
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
G
Guy Schalnat 已提交
859
extern png_byte FARDATA png_pHYs[];
G
Guy Schalnat 已提交
860 861
#endif
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
G
Guy Schalnat 已提交
862
extern png_byte FARDATA png_oFFs[];
G
Guy Schalnat 已提交
863 864
#endif
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
G
Guy Schalnat 已提交
865
extern png_byte FARDATA png_tIME[];
G
Guy Schalnat 已提交
866
#endif
G
Guy Schalnat 已提交
867
/* Structures to facilitate easy interlacing.  See png.c for more details */
G
Guy Schalnat 已提交
868 869 870 871
extern int FARDATA png_pass_start[];
extern int FARDATA png_pass_inc[];
extern int FARDATA png_pass_ystart[];
extern int FARDATA png_pass_yinc[];
G
Guy Schalnat 已提交
872
/* these are not currently used.  If you need them, see png.c
G
Guy Schalnat 已提交
873 874
extern int FARDATA png_pass_width[];
extern int FARDATA png_pass_height[];
G
Guy Schalnat 已提交
875
*/
G
Guy Schalnat 已提交
876 877
extern int FARDATA png_pass_mask[];
extern int FARDATA png_pass_dsp_mask[];
G
Guy Schalnat 已提交
878 879 880 881

#endif /* PNG_NO_EXTERN */

/* Function to allocate memory for zlib. */
G
Guy Schalnat 已提交
882
extern voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
G
Guy Schalnat 已提交
883 884

/* function to free memory for zlib */
G
Guy Schalnat 已提交
885
extern void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
G
Guy Schalnat 已提交
886 887

/* reset the crc variable */
G
Guy Schalnat 已提交
888
extern void png_reset_crc PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
889 890 891 892 893

/* calculate the crc over a section of data.  Note that while we
   are passing in a 32 bit value for length, on 16 bit machines, you
   would need to use huge pointers to access all that data.  See the
   code in png.c for more information. */
G
Guy Schalnat 已提交
894
extern void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
G
Guy Schalnat 已提交
895
   png_uint_32 length));
G
Guy Schalnat 已提交
896 897

/* default error and warning functions if user doesn't supply them */
G
Guy Schalnat 已提交
898 899 900 901
extern void png_default_warning PNGARG((png_structp png_ptr,
   png_const_charp message));
extern void png_default_error PNGARG((png_structp png_ptr,
   png_const_charp error));
G
Guy Schalnat 已提交
902
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
G
Guy Schalnat 已提交
903 904
extern void png_flush PNGARG((png_structp png_ptr));
extern void png_default_flush PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
905
#endif
G
Guy Schalnat 已提交
906 907

/* place a 32 bit number into a buffer in png byte order.  We work
G
Guy Schalnat 已提交
908 909
   with unsigned numbers for convenience, you may have to cast
   signed numbers (if you use any, most png data is unsigned). */
G
Guy Schalnat 已提交
910
extern void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
G
Guy Schalnat 已提交
911 912

/* place a 16 bit number into a buffer in png byte order */
G
Guy Schalnat 已提交
913
extern void png_save_uint_16 PNGARG((png_bytep buf, png_uint_16 i));
G
Guy Schalnat 已提交
914 915

/* write a 32 bit number */
G
Guy Schalnat 已提交
916
extern void png_write_uint_32 PNGARG((png_structp png_ptr, png_uint_32 i));
G
Guy Schalnat 已提交
917 918

/* write a 16 bit number */
G
Guy Schalnat 已提交
919
extern void png_write_uint_16 PNGARG((png_structp png_ptr, png_uint_16 i));
G
Guy Schalnat 已提交
920 921

/* Write a png chunk.  */
G
Guy Schalnat 已提交
922
extern void png_write_chunk PNGARG((png_structp png_ptr, png_bytep type,
G
Guy Schalnat 已提交
923
   png_bytep data, png_uint_32 length));
G
Guy Schalnat 已提交
924 925

/* Write the start of a png chunk. */
G
Guy Schalnat 已提交
926
extern void png_write_chunk_start PNGARG((png_structp png_ptr, png_bytep type,
G
Guy Schalnat 已提交
927
   png_uint_32 total_length));
G
Guy Schalnat 已提交
928 929

/* write the data of a png chunk started with png_write_chunk_start(). */
G
Guy Schalnat 已提交
930
extern void png_write_chunk_data PNGARG((png_structp png_ptr, png_bytep data,
G
Guy Schalnat 已提交
931
   png_uint_32 length));
G
Guy Schalnat 已提交
932 933

/* finish a chunk started with png_write_chunk_start() */
G
Guy Schalnat 已提交
934
extern void png_write_chunk_end PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
935 936

/* simple function to write the signiture */
G
Guy Schalnat 已提交
937
extern void png_write_sig PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
938 939 940 941

/* write various chunks */

/* Write the IHDR chunk, and update the png_struct with the necessary
G
Guy Schalnat 已提交
942
   information. */
G
Guy Schalnat 已提交
943
extern void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
G
Guy Schalnat 已提交
944 945 946
   png_uint_32 height,
   int bit_depth, int color_type, int compression_type, int filter_type,
   int interlace_type));
G
Guy Schalnat 已提交
947

G
Guy Schalnat 已提交
948
extern void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
G
Guy Schalnat 已提交
949
   int number));
G
Guy Schalnat 已提交
950

G
Guy Schalnat 已提交
951
extern void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
G
Guy Schalnat 已提交
952
   png_uint_32 length));
G
Guy Schalnat 已提交
953

G
Guy Schalnat 已提交
954
extern void png_write_IEND PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
955

G
Guy Schalnat 已提交
956
#if defined(PNG_WRITE_gAMA_SUPPORTED)
G
Guy Schalnat 已提交
957
extern void png_write_gAMA PNGARG((png_structp png_ptr, double gamma));
G
Guy Schalnat 已提交
958
#endif
G
Guy Schalnat 已提交
959

G
Guy Schalnat 已提交
960
#if defined(PNG_WRITE_sBIT_SUPPORTED)
G
Guy Schalnat 已提交
961
extern void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
G
Guy Schalnat 已提交
962
   int color_type));
G
Guy Schalnat 已提交
963
#endif
G
Guy Schalnat 已提交
964

G
Guy Schalnat 已提交
965
#if defined(PNG_WRITE_cHRM_SUPPORTED)
G
Guy Schalnat 已提交
966
extern void png_write_cHRM PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
967 968 969
   double white_x, double white_y,
   double red_x, double red_y, double green_x, double green_y,
   double blue_x, double blue_y));
G
Guy Schalnat 已提交
970
#endif
G
Guy Schalnat 已提交
971

G
Guy Schalnat 已提交
972
#if defined(PNG_WRITE_tRNS_SUPPORTED)
G
Guy Schalnat 已提交
973
extern void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
G
Guy Schalnat 已提交
974
   png_color_16p values, int number, int color_type));
G
Guy Schalnat 已提交
975
#endif
G
Guy Schalnat 已提交
976

G
Guy Schalnat 已提交
977
#if defined(PNG_WRITE_bKGD_SUPPORTED)
G
Guy Schalnat 已提交
978
extern void png_write_bKGD PNGARG((png_structp png_ptr, png_color_16p values,
G
Guy Schalnat 已提交
979
   int color_type));
G
Guy Schalnat 已提交
980
#endif
G
Guy Schalnat 已提交
981

G
Guy Schalnat 已提交
982
#if defined(PNG_WRITE_hIST_SUPPORTED)
G
Guy Schalnat 已提交
983
extern void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
G
Guy Schalnat 已提交
984
   int number));
G
Guy Schalnat 已提交
985
#endif
G
Guy Schalnat 已提交
986

G
Guy Schalnat 已提交
987
#if defined(PNG_WRITE_tEXt_SUPPORTED)
G
Guy Schalnat 已提交
988
extern void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
G
Guy Schalnat 已提交
989
   png_charp text, png_uint_32 text_len));
G
Guy Schalnat 已提交
990
#endif
G
Guy Schalnat 已提交
991

G
Guy Schalnat 已提交
992
#if defined(PNG_WRITE_zTXt_SUPPORTED)
G
Guy Schalnat 已提交
993
extern void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
G
Guy Schalnat 已提交
994
   png_charp text, png_uint_32 text_len, int compression));
G
Guy Schalnat 已提交
995
#endif
G
Guy Schalnat 已提交
996

G
Guy Schalnat 已提交
997
#if defined(PNG_WRITE_pHYs_SUPPORTED)
G
Guy Schalnat 已提交
998
extern void png_write_pHYs PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
999 1000 1001
   png_uint_32 x_pixels_per_unit,
   png_uint_32 y_pixels_per_unit,
   int unit_type));
G
Guy Schalnat 已提交
1002
#endif
G
Guy Schalnat 已提交
1003

G
Guy Schalnat 已提交
1004
#if defined(PNG_WRITE_oFFs_SUPPORTED)
G
Guy Schalnat 已提交
1005
extern void png_write_oFFs PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
1006
   png_uint_32 x_offset,
G
Guy Schalnat 已提交
1007 1008
   png_uint_32 y_offset,
   int unit_type));
G
Guy Schalnat 已提交
1009
#endif
G
Guy Schalnat 已提交
1010

G
Guy Schalnat 已提交
1011
#if defined(PNG_WRITE_tIME_SUPPORTED)
G
Guy Schalnat 已提交
1012
extern void png_write_tIME PNGARG((png_structp png_ptr, png_timep mod_time));
G
Guy Schalnat 已提交
1013
#endif
G
Guy Schalnat 已提交
1014 1015

/* Internal use only.   Called when finished processing a row of data */
G
Guy Schalnat 已提交
1016
extern void png_write_finish_row PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
1017 1018

/* Internal use only.   Called before first row of data */
G
Guy Schalnat 已提交
1019
extern void png_write_start_row PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
1020 1021

/* callbacks for png chunks */
G
Guy Schalnat 已提交
1022
extern void png_read_IHDR PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1023
   png_uint_32 width, png_uint_32 height, int bit_depth,
G
Guy Schalnat 已提交
1024
   int color_type, int compression_type, int filter_type,
G
Guy Schalnat 已提交
1025
   int interlace_type));
G
Guy Schalnat 已提交
1026

G
Guy Schalnat 已提交
1027
extern void png_read_PLTE PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1028
   png_colorp palette, int num));
G
Guy Schalnat 已提交
1029 1030

#if defined(PNG_READ_gAMA_SUPPORTED)
G
Guy Schalnat 已提交
1031
extern void png_read_gAMA PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1032
   double gamma));
G
Guy Schalnat 已提交
1033 1034 1035
#endif

#if defined(PNG_READ_sBIT_SUPPORTED)
G
Guy Schalnat 已提交
1036
extern void png_read_sBIT PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1037
   png_color_8p sig_bit));
G
Guy Schalnat 已提交
1038 1039 1040
#endif

#if defined(PNG_READ_cHRM_SUPPORTED)
G
Guy Schalnat 已提交
1041
extern void png_read_cHRM PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1042 1043
   double white_x, double white_y, double red_x, double red_y,
   double green_x, double green_y, double blue_x, double blue_y));
G
Guy Schalnat 已提交
1044 1045 1046
#endif

#if defined(PNG_READ_tRNS_SUPPORTED)
G
Guy Schalnat 已提交
1047
extern void png_read_tRNS PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1048
   png_bytep trans, int num_trans,   png_color_16p trans_values));
G
Guy Schalnat 已提交
1049 1050 1051
#endif

#if defined(PNG_READ_bKGD_SUPPORTED)
G
Guy Schalnat 已提交
1052
extern void png_read_bKGD PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1053
   png_color_16p background));
G
Guy Schalnat 已提交
1054 1055 1056
#endif

#if defined(PNG_READ_hIST_SUPPORTED)
G
Guy Schalnat 已提交
1057
extern void png_read_hIST PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1058
   png_uint_16p hist));
G
Guy Schalnat 已提交
1059 1060 1061
#endif

#if defined(PNG_READ_pHYs_SUPPORTED)
G
Guy Schalnat 已提交
1062
extern void png_read_pHYs PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1063
   png_uint_32 res_x, png_uint_32 res_y, int unit_type));
G
Guy Schalnat 已提交
1064 1065 1066
#endif

#if defined(PNG_READ_oFFs_SUPPORTED)
G
Guy Schalnat 已提交
1067
extern void png_read_oFFs PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1068
   png_uint_32 offset_x, png_uint_32 offset_y, int unit_type));
G
Guy Schalnat 已提交
1069 1070 1071
#endif

#if defined(PNG_READ_tIME_SUPPORTED)
G
Guy Schalnat 已提交
1072
extern void png_read_tIME PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1073
   png_timep mod_time));
G
Guy Schalnat 已提交
1074 1075 1076
#endif

#if defined(PNG_READ_tEXt_SUPPORTED)
G
Guy Schalnat 已提交
1077
extern void png_read_tEXt PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1078
   png_charp key, png_charp text, png_uint_32 text_len));
G
Guy Schalnat 已提交
1079 1080 1081
#endif

#if defined(PNG_READ_zTXt_SUPPORTED)
G
Guy Schalnat 已提交
1082
extern void png_read_zTXt PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1083
   png_charp key, png_charp text, png_uint_32 text_len, int compression));
G
Guy Schalnat 已提交
1084
#endif
G
Guy Schalnat 已提交
1085

G
Guy Schalnat 已提交
1086
#if defined(PNG_READ_GAMMA_SUPPORTED)
G
Guy Schalnat 已提交
1087
void
G
Guy Schalnat 已提交
1088
png_build_gamma_table PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
1089
#endif
G
Guy Schalnat 已提交
1090 1091

/* combine a row of data, dealing with alpha, etc. if requested */
G
Guy Schalnat 已提交
1092
extern void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
G
Guy Schalnat 已提交
1093
   int mask));
G
Guy Schalnat 已提交
1094 1095

#if defined(PNG_READ_INTERLACING_SUPPORTED)
G
Guy Schalnat 已提交
1096
/* expand an interlaced row */
G
Guy Schalnat 已提交
1097
extern void png_do_read_interlace PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1098
   png_bytep row, int pass));
G
Guy Schalnat 已提交
1099 1100 1101
#endif

#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
G
Guy Schalnat 已提交
1102
/* grab pixels out of a row for an interlaced pass */
G
Guy Schalnat 已提交
1103
extern void png_do_write_interlace PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1104
   png_bytep row, int pass));
G
Guy Schalnat 已提交
1105
#endif
G
Guy Schalnat 已提交
1106 1107

/* unfilter a row */
G
Guy Schalnat 已提交
1108
extern void png_read_filter_row PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1109
   png_bytep row, png_bytep prev_row, int filter));
G
Guy Schalnat 已提交
1110
/* filter a row, and place the correct filter byte in the row */
G
Guy Schalnat 已提交
1111
extern void png_write_filter_row PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1112
   png_bytep row, png_bytep prev_row));
G
Guy Schalnat 已提交
1113
/* finish a row while reading, dealing with interlacing passes, etc. */
G
Guy Schalnat 已提交
1114
extern void png_read_finish_row PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
1115
/* initialize the row buffers, etc. */
G
Guy Schalnat 已提交
1116
extern void png_read_start_row PNGARG((png_structp png_ptr));
G
Guy Schalnat 已提交
1117
/* optional call to update the users info structure */
G
Guy Schalnat 已提交
1118
extern void png_read_transform_info PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
1119
   png_infop info_ptr));
G
Guy Schalnat 已提交
1120 1121

/* these are the functions that do the transformations */
G
Guy Schalnat 已提交
1122
#if defined(PNG_READ_FILLER_SUPPORTED)
G
Guy Schalnat 已提交
1123
extern void png_do_read_filler PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1124
   png_bytep row, png_byte filler, png_byte filler_loc));
G
Guy Schalnat 已提交
1125 1126 1127
#endif

#if defined(PNG_WRITE_FILLER_SUPPORTED)
G
Guy Schalnat 已提交
1128
extern void png_do_write_filler PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1129
   png_bytep row, png_byte filler_loc));
G
Guy Schalnat 已提交
1130 1131 1132
#endif

#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
G
Guy Schalnat 已提交
1133
extern void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
G
Guy Schalnat 已提交
1134 1135 1136
#endif

#if defined(PNG_READ_PACK_SUPPORTED)
G
Guy Schalnat 已提交
1137
extern void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
G
Guy Schalnat 已提交
1138 1139 1140
#endif

#if defined(PNG_READ_SHIFT_SUPPORTED)
G
Guy Schalnat 已提交
1141 1142
extern void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
   png_color_8p sig_bits));
G
Guy Schalnat 已提交
1143 1144 1145
#endif

#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
G
Guy Schalnat 已提交
1146
extern void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
G
Guy Schalnat 已提交
1147 1148
#endif

G
Guy Schalnat 已提交
1149
extern void png_build_grayscale_palette PNGARG((int bit_depth,
G
Guy Schalnat 已提交
1150
   png_colorp palette));
G
Guy Schalnat 已提交
1151

G
Guy Schalnat 已提交
1152
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
G
Guy Schalnat 已提交
1153
extern void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1154
   png_bytep row));
G
Guy Schalnat 已提交
1155 1156 1157
#endif

#if defined(PNG_READ_16_TO_8_SUPPORTED)
G
Guy Schalnat 已提交
1158
extern void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
G
Guy Schalnat 已提交
1159 1160 1161
#endif

#if defined(PNG_READ_DITHER_SUPPORTED)
G
Guy Schalnat 已提交
1162
extern void png_do_dither PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1163
   png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
G
Guy Schalnat 已提交
1164 1165 1166
#endif

#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
G
Guy Schalnat 已提交
1167
extern void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
G
Guy Schalnat 已提交
1168 1169 1170
#endif

#if defined(PNG_WRITE_PACK_SUPPORTED)
G
Guy Schalnat 已提交
1171
extern void png_do_pack PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1172
   png_bytep row, png_byte bit_depth));
G
Guy Schalnat 已提交
1173 1174 1175
#endif

#if defined(PNG_WRITE_SHIFT_SUPPORTED)
G
Guy Schalnat 已提交
1176 1177
extern void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
   png_color_8p bit_depth));
G
Guy Schalnat 已提交
1178 1179 1180
#endif

#if defined(PNG_READ_BACKGROUND_SUPPORTED)
G
Guy Schalnat 已提交
1181 1182
extern void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
   png_color_16p trans_values, png_color_16p background,
G
Guy Schalnat 已提交
1183 1184 1185 1186
   png_color_16p background_1,
   png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
   png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
   png_uint_16pp gamma_16_to_1, int gamma_shift));
G
Guy Schalnat 已提交
1187 1188 1189
#endif

#if defined(PNG_READ_GAMMA_SUPPORTED)
G
Guy Schalnat 已提交
1190
extern void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
G
Guy Schalnat 已提交
1191
   png_bytep gamma_table, png_uint_16pp gamma_16_table,
G
Guy Schalnat 已提交
1192
   int gamma_shift));
G
Guy Schalnat 已提交
1193 1194 1195
#endif

#if defined(PNG_READ_EXPAND_SUPPORTED)
G
Guy Schalnat 已提交
1196
extern void png_do_expand_palette PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1197
   png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
G
Guy Schalnat 已提交
1198
extern void png_do_expand PNGARG((png_row_infop row_info,
G
Guy Schalnat 已提交
1199
   png_bytep row, png_color_16p trans_value));
G
Guy Schalnat 已提交
1200
#endif
G
Guy Schalnat 已提交
1201 1202

/* unpack 16 and 32 bit values from a string */
G
Guy Schalnat 已提交
1203 1204
extern png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
extern png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
G
Guy Schalnat 已提交
1205 1206

/* read bytes into buf, and update png_ptr->crc */
G
Guy Schalnat 已提交
1207
extern void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
G
Guy Schalnat 已提交
1208 1209
   png_uint_32 length));
/* skip length bytes, and update png_ptr->crc */
G
Guy Schalnat 已提交
1210
extern void png_crc_skip PNGARG((png_structp png_ptr, png_uint_32 length));
G
Guy Schalnat 已提交
1211 1212 1213 1214 1215

/* the following decodes the appropriate chunks, and does error correction,
   then calls the appropriate callback for the chunk if it is valid */

/* decode the IHDR chunk */
G
Guy Schalnat 已提交
1216
extern void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1217
   png_uint_32 length));
G
Guy Schalnat 已提交
1218
extern void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1219
   png_uint_32 length));
G
Guy Schalnat 已提交
1220
#if defined(PNG_READ_gAMA_SUPPORTED)
G
Guy Schalnat 已提交
1221
extern void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1222
   png_uint_32 length));
G
Guy Schalnat 已提交
1223 1224 1225
#endif

#if defined(PNG_READ_sBIT_SUPPORTED)
G
Guy Schalnat 已提交
1226
extern void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1227
   png_uint_32 length));
G
Guy Schalnat 已提交
1228 1229 1230
#endif

#if defined(PNG_READ_cHRM_SUPPORTED)
G
Guy Schalnat 已提交
1231
extern void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1232
   png_uint_32 length));
G
Guy Schalnat 已提交
1233 1234 1235
#endif

#if defined(PNG_READ_tRNS_SUPPORTED)
G
Guy Schalnat 已提交
1236
extern void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1237
   png_uint_32 length));
G
Guy Schalnat 已提交
1238 1239 1240
#endif

#if defined(PNG_READ_bKGD_SUPPORTED)
G
Guy Schalnat 已提交
1241
extern void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1242
   png_uint_32 length));
G
Guy Schalnat 已提交
1243 1244 1245
#endif

#if defined(PNG_READ_hIST_SUPPORTED)
G
Guy Schalnat 已提交
1246
extern void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1247
   png_uint_32 length));
G
Guy Schalnat 已提交
1248 1249 1250
#endif

#if defined(PNG_READ_pHYs_SUPPORTED)
G
Guy Schalnat 已提交
1251
extern void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1252
   png_uint_32 length));
G
Guy Schalnat 已提交
1253 1254 1255
#endif

#if defined(PNG_READ_oFFs_SUPPORTED)
G
Guy Schalnat 已提交
1256
extern void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1257
   png_uint_32 length));
G
Guy Schalnat 已提交
1258 1259 1260
#endif

#if defined(PNG_READ_tIME_SUPPORTED)
G
Guy Schalnat 已提交
1261
extern void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1262
   png_uint_32 length));
G
Guy Schalnat 已提交
1263 1264 1265
#endif

#if defined(PNG_READ_tEXt_SUPPORTED)
G
Guy Schalnat 已提交
1266
extern void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1267
   png_uint_32 length));
G
Guy Schalnat 已提交
1268 1269 1270
#endif

#if defined(PNG_READ_zTXt_SUPPORTED)
G
Guy Schalnat 已提交
1271
extern void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1272
   png_uint_32 length));
G
Guy Schalnat 已提交
1273
#endif
G
Guy Schalnat 已提交
1274 1275

/* handle the transformations for reading and writing */
G
Guy Schalnat 已提交
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
extern void png_do_read_transformations PNGARG((png_structp png_ptr));
extern void png_do_write_transformations PNGARG((png_structp png_ptr));

extern void png_init_read_transformations PNGARG((png_structp png_ptr));

#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
extern void png_push_read_chunk PNGARG((png_structp png_ptr, png_infop info));
extern void png_push_read_sig PNGARG((png_structp png_ptr));
extern void png_push_check_crc PNGARG((png_structp png_ptr));
extern void png_push_crc_skip PNGARG((png_structp png_ptr, png_uint_32 length));
extern void png_push_skip PNGARG((png_structp png_ptr));
extern void png_push_fill_buffer PNGARG((png_structp png_ptr, png_bytep buffer,
G
Guy Schalnat 已提交
1288
   png_uint_32 length));
G
Guy Schalnat 已提交
1289 1290
extern void png_push_save_buffer PNGARG((png_structp png_ptr));
extern void png_push_restore_buffer PNGARG((png_structp png_ptr, png_bytep buffer,
G
Guy Schalnat 已提交
1291
   png_uint_32 buffer_length));
G
Guy Schalnat 已提交
1292 1293
extern void png_push_read_idat PNGARG((png_structp png_ptr));
extern void png_process_IDAT_data PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
1294
   png_bytep buffer, png_uint_32 buffer_length));
G
Guy Schalnat 已提交
1295 1296
extern void png_push_process_row PNGARG((png_structp png_ptr));
extern void png_push_handle_PLTE PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
1297
   png_uint_32 length));
G
Guy Schalnat 已提交
1298 1299
extern void png_push_read_plte PNGARG((png_structp png_ptr, png_infop info));
extern void png_push_handle_tRNS PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1300
   png_uint_32 length));
G
Guy Schalnat 已提交
1301
extern void png_push_handle_hIST PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1302
   png_uint_32 length));
G
Guy Schalnat 已提交
1303 1304 1305 1306 1307
extern void png_push_have_info PNGARG((png_structp png_ptr, png_infop info));
extern void png_push_have_end PNGARG((png_structp png_ptr, png_infop info));
extern void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
extern void png_push_read_end PNGARG((png_structp png_ptr, png_infop info));
extern void png_process_some_data PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
1308
   png_infop info));
G
Guy Schalnat 已提交
1309 1310
extern void png_read_push_finish_row PNGARG((png_structp png_ptr));
#if defined(PNG_READ_tEXt_SUPPORTED)
G
Guy Schalnat 已提交
1311 1312
extern void png_push_handle_tEXt PNGARG((png_structp png_ptr,
   png_uint_32 length));
G
Guy Schalnat 已提交
1313 1314 1315
extern void png_push_read_text PNGARG((png_structp png_ptr, png_infop info));
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
G
Guy Schalnat 已提交
1316 1317
extern void png_push_handle_zTXt PNGARG((png_structp png_ptr,
   png_uint_32 length));
G
Guy Schalnat 已提交
1318 1319
extern void png_push_read_ztxt PNGARG((png_structp png_ptr, png_infop info));
#endif
G
Guy Schalnat 已提交
1320

G
Guy Schalnat 已提交
1321
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
G
Guy Schalnat 已提交
1322 1323 1324

#endif /* PNG_INTERNAL */

G
Guy Schalnat 已提交
1325 1326
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
extern void png_process_data PNGARG((png_structp png_ptr, png_infop info,
G
Guy Schalnat 已提交
1327
   png_bytep buffer, png_uint_32 buffer_size));
G
Guy Schalnat 已提交
1328
extern void png_set_progressive_read_fn PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
1329 1330 1331
   png_voidp progressive_ptr,
   png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
   png_progressive_end_ptr end_fn));
G
Guy Schalnat 已提交
1332
extern void png_progressive_combine_row PNGARG((png_structp png_ptr,
G
Guy Schalnat 已提交
1333
   png_bytep old_row, png_bytep new_row));
G
Guy Schalnat 已提交
1334 1335
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */

G
Guy Schalnat 已提交
1336 1337
/* do not put anything past this line */
#endif /* _PNG_H */
G
Guy Schalnat 已提交
1338