Home | History | Annotate | Download | only in jni
      1 
      2 /* pngpriv.h - private declarations for use inside libpng
      3  *
      4  * For conditions of distribution and use, see copyright notice in png.h
      5  * Copyright (c) 1998-2012 Glenn Randers-Pehrson
      6  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
      7  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
      8  *
      9  * Last changed in libpng 1.5.10 [March 29, 2012]
     10  *
     11  * This code is released under the libpng license.
     12  * For conditions of distribution and use, see the disclaimer
     13  * and license in png.h
     14  */
     15 
     16 /* The symbols declared in this file (including the functions declared
     17  * as PNG_EXTERN) are PRIVATE.  They are not part of the libpng public
     18  * interface, and are not recommended for use by regular applications.
     19  * Some of them may become public in the future; others may stay private,
     20  * change in an incompatible way, or even disappear.
     21  * Although the libpng users are not forbidden to include this header,
     22  * they should be well aware of the issues that may arise from doing so.
     23  */
     24 
     25 #ifndef PNGPRIV_H
     26 #define PNGPRIV_H
     27 
     28 /* Feature Test Macros.  The following are defined here to ensure that correctly
     29  * implemented libraries reveal the APIs libpng needs to build and hide those
     30  * that are not needed and potentially damaging to the compilation.
     31  *
     32  * Feature Test Macros must be defined before any system header is included (see
     33  * POSIX 1003.1 2.8.2 "POSIX Symbols."
     34  *
     35  * These macros only have an effect if the operating system supports either
     36  * POSIX 1003.1 or C99, or both.  On other operating systems (particularly
     37  * Windows/Visual Studio) there is no effect; the OS specific tests below are
     38  * still required (as of 2011-05-02.)
     39  */
     40 #define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
     41 
     42 /* This is required for the definition of abort(), used as a last ditch
     43  * error handler when all else fails.
     44  */
     45 #include <stdlib.h>
     46 
     47 /* This is used to find 'offsetof', used below for alignment tests. */
     48 #include <stddef.h>
     49 
     50 #define PNGLIB_BUILD /*libpng is being built, not used*/
     51 
     52 #ifdef PNG_USER_CONFIG
     53 #  include "pngusr.h"
     54    /* These should have been defined in pngusr.h */
     55 #  ifndef PNG_USER_PRIVATEBUILD
     56 #    define PNG_USER_PRIVATEBUILD "Custom libpng build"
     57 #  endif
     58 #  ifndef PNG_USER_DLLFNAME_POSTFIX
     59 #    define PNG_USER_DLLFNAME_POSTFIX "Cb"
     60 #  endif
     61 #endif
     62 
     63 /* Is this a build of a DLL where compilation of the object modules requires
     64  * different preprocessor settings to those required for a simple library?  If
     65  * so PNG_BUILD_DLL must be set.
     66  *
     67  * If libpng is used inside a DLL but that DLL does not export the libpng APIs
     68  * PNG_BUILD_DLL must not be set.  To avoid the code below kicking in build a
     69  * static library of libpng then link the DLL against that.
     70  */
     71 #ifndef PNG_BUILD_DLL
     72 #  ifdef DLL_EXPORT
     73       /* This is set by libtool when files are compiled for a DLL; libtool
     74        * always compiles twice, even on systems where it isn't necessary.  Set
     75        * PNG_BUILD_DLL in case it is necessary:
     76        */
     77 #     define PNG_BUILD_DLL
     78 #  else
     79 #     ifdef _WINDLL
     80          /* This is set by the Microsoft Visual Studio IDE in projects that
     81           * build a DLL.  It can't easily be removed from those projects (it
     82           * isn't visible in the Visual Studio UI) so it is a fairly reliable
     83           * indication that PNG_IMPEXP needs to be set to the DLL export
     84           * attributes.
     85           */
     86 #        define PNG_BUILD_DLL
     87 #     else
     88 #        ifdef __DLL__
     89             /* This is set by the Borland C system when compiling for a DLL
     90              * (as above.)
     91              */
     92 #           define PNG_BUILD_DLL
     93 #        else
     94             /* Add additional compiler cases here. */
     95 #        endif
     96 #     endif
     97 #  endif
     98 #endif /* Setting PNG_BUILD_DLL if required */
     99 
    100 /* See pngconf.h for more details: the builder of the library may set this on
    101  * the command line to the right thing for the specific compilation system or it
    102  * may be automagically set above (at present we know of no system where it does
    103  * need to be set on the command line.)
    104  *
    105  * PNG_IMPEXP must be set here when building the library to prevent pngconf.h
    106  * setting it to the "import" setting for a DLL build.
    107  */
    108 #ifndef PNG_IMPEXP
    109 #  ifdef PNG_BUILD_DLL
    110 #     define PNG_IMPEXP PNG_DLL_EXPORT
    111 #  else
    112       /* Not building a DLL, or the DLL doesn't require specific export
    113        * definitions.
    114        */
    115 #     define PNG_IMPEXP
    116 #  endif
    117 #endif
    118 
    119 /* No warnings for private or deprecated functions in the build: */
    120 #ifndef PNG_DEPRECATED
    121 #  define PNG_DEPRECATED
    122 #endif
    123 #ifndef PNG_PRIVATE
    124 #  define PNG_PRIVATE
    125 #endif
    126 
    127 #include "png.h"
    128 #include "pnginfo.h"
    129 #include "pngstruct.h"
    130 
    131 /* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */
    132 #ifndef PNG_DLL_EXPORT
    133 #  define PNG_DLL_EXPORT
    134 #endif
    135 
    136 /* SECURITY and SAFETY:
    137  *
    138  * By default libpng is built without any internal limits on image size,
    139  * individual heap (png_malloc) allocations or the total amount of memory used.
    140  * If PNG_SAFE_LIMITS_SUPPORTED is defined, however, the limits below are used
    141  * (unless individually overridden).  These limits are believed to be fairly
    142  * safe, but builders of secure systems should verify the values against the
    143  * real system capabilities.
    144  */
    145 
    146 #ifdef PNG_SAFE_LIMITS_SUPPORTED
    147    /* 'safe' limits */
    148 #  ifndef PNG_USER_WIDTH_MAX
    149 #     define PNG_USER_WIDTH_MAX 1000000
    150 #  endif
    151 #  ifndef PNG_USER_HEIGHT_MAX
    152 #     define PNG_USER_HEIGHT_MAX 1000000
    153 #  endif
    154 #  ifndef PNG_USER_CHUNK_CACHE_MAX
    155 #     define PNG_USER_CHUNK_CACHE_MAX 128
    156 #  endif
    157 #  ifndef PNG_USER_CHUNK_MALLOC_MAX
    158 #     define PNG_USER_CHUNK_MALLOC_MAX 8000000
    159 #  endif
    160 #else
    161    /* values for no limits */
    162 #  ifndef PNG_USER_WIDTH_MAX
    163 #     define PNG_USER_WIDTH_MAX 0x7fffffff
    164 #  endif
    165 #  ifndef PNG_USER_HEIGHT_MAX
    166 #     define PNG_USER_HEIGHT_MAX 0x7fffffff
    167 #  endif
    168 #  ifndef PNG_USER_CHUNK_CACHE_MAX
    169 #     define PNG_USER_CHUNK_CACHE_MAX 0
    170 #  endif
    171 #  ifndef PNG_USER_CHUNK_MALLOC_MAX
    172 #     define PNG_USER_CHUNK_MALLOC_MAX 0
    173 #  endif
    174 #endif
    175 
    176 /* This is used for 16 bit gamma tables - only the top level pointers are const,
    177  * this could be changed:
    178  */
    179 typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
    180 
    181 /* Added at libpng-1.2.9 */
    182 /* Moved to pngpriv.h at libpng-1.5.0 */
    183 
    184 /* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure"
    185  * script.  We may need it here to get the correct configuration on things
    186  * like limits.
    187  */
    188 #ifdef PNG_CONFIGURE_LIBPNG
    189 #  ifdef HAVE_CONFIG_H
    190 #    include "config.h"
    191 #  endif
    192 #endif
    193 
    194 /* Moved to pngpriv.h at libpng-1.5.0 */
    195 /* NOTE: some of these may have been used in external applications as
    196  * these definitions were exposed in pngconf.h prior to 1.5.
    197  */
    198 
    199 /* If you are running on a machine where you cannot allocate more
    200  * than 64K of memory at once, uncomment this.  While libpng will not
    201  * normally need that much memory in a chunk (unless you load up a very
    202  * large file), zlib needs to know how big of a chunk it can use, and
    203  * libpng thus makes sure to check any memory allocation to verify it
    204  * will fit into memory.
    205  *
    206  * zlib provides 'MAXSEG_64K' which, if defined, indicates the
    207  * same limit and pngconf.h (already included) sets the limit
    208  * if certain operating systems are detected.
    209  */
    210 #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
    211 #  define PNG_MAX_MALLOC_64K
    212 #endif
    213 
    214 #ifndef PNG_UNUSED
    215 /* Unused formal parameter warnings are silenced using the following macro
    216  * which is expected to have no bad effects on performance (optimizing
    217  * compilers will probably remove it entirely).  Note that if you replace
    218  * it with something other than whitespace, you must include the terminating
    219  * semicolon.
    220  */
    221 #  define PNG_UNUSED(param) (void)param;
    222 #endif
    223 
    224 /* Just a little check that someone hasn't tried to define something
    225  * contradictory.
    226  */
    227 #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
    228 #  undef PNG_ZBUF_SIZE
    229 #  define PNG_ZBUF_SIZE 65536L
    230 #endif
    231 
    232 /* PNG_STATIC is used to mark internal file scope functions if they need to be
    233  * accessed for implementation tests (see the code in tests/?*).
    234  */
    235 #ifndef PNG_STATIC
    236 #   define PNG_STATIC static
    237 #endif
    238 
    239 /* C99 restrict is used where possible, to do this 'restrict' is defined as
    240  * empty if we can't be sure it is supported.  configure builds have already
    241  * done this work.
    242  */
    243 #ifdef PNG_CONFIGURE_LIBPNG
    244 #  define PNG_RESTRICT restrict
    245 #else
    246    /* Modern compilers support restrict, but assume not for anything not
    247     * recognized here:
    248     */
    249 #  if defined __GNUC__ || defined _MSC_VER || defined __WATCOMC__
    250 #     define PNG_RESTRICT restrict
    251 #  else
    252 #     define PNG_RESTRICT
    253 #  endif
    254 #endif
    255 
    256 /* If warnings or errors are turned off the code is disabled or redirected here.
    257  * From 1.5.4 functions have been added to allow very limited formatting of
    258  * error and warning messages - this code will also be disabled here.
    259  */
    260 #ifdef PNG_WARNINGS_SUPPORTED
    261 #  define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;
    262 #else
    263 #  define png_warning(s1,s2) ((void)(s1))
    264 #  define png_chunk_warning(s1,s2) ((void)(s1))
    265 #  define png_warning_parameter(p,number,string) ((void)0)
    266 #  define png_warning_parameter_unsigned(p,number,format,value) ((void)0)
    267 #  define png_warning_parameter_signed(p,number,format,value) ((void)0)
    268 #  define png_formatted_warning(pp,p,message) ((void)(pp))
    269 #  define PNG_WARNING_PARAMETERS(p)
    270 #endif
    271 #ifndef PNG_ERROR_TEXT_SUPPORTED
    272 #  define png_error(s1,s2) png_err(s1)
    273 #  define png_chunk_error(s1,s2) png_err(s1)
    274 #  define png_fixed_error(s1,s2) png_err(s1)
    275 #endif
    276 
    277 /* C allows up-casts from (void*) to any pointer and (const void*) to any
    278  * pointer to a const object.  C++ regards this as a type error and requires an
    279  * explicit, static, cast and provides the static_cast<> rune to ensure that
    280  * const is not cast away.
    281  */
    282 #ifdef __cplusplus
    283 #  define png_voidcast(type, value) static_cast<type>(value)
    284 #else
    285 #  define png_voidcast(type, value) (value)
    286 #endif /* __cplusplus */
    287 
    288 #ifndef PNG_EXTERN
    289 /* The functions exported by PNG_EXTERN are internal functions, which
    290  * aren't usually used outside the library (as far as I know), so it is
    291  * debatable if they should be exported at all.  In the future, when it
    292  * is possible to have run-time registry of chunk-handling functions,
    293  * some of these might be made available again.
    294  *
    295  * 1.5.7: turned the use of 'extern' back on, since it is localized to pngpriv.h
    296  * it should be safe now (it is unclear why it was turned off.)
    297  */
    298 #  define PNG_EXTERN extern
    299 #endif
    300 
    301 /* Some fixed point APIs are still required even if not exported because
    302  * they get used by the corresponding floating point APIs.  This magic
    303  * deals with this:
    304  */
    305 #ifdef PNG_FIXED_POINT_SUPPORTED
    306 #  define PNGFAPI PNGAPI
    307 #else
    308 #  define PNGFAPI /* PRIVATE */
    309 #endif
    310 
    311 /* Other defines specific to compilers can go here.  Try to keep
    312  * them inside an appropriate ifdef/endif pair for portability.
    313  */
    314 #if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
    315     defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
    316    /* png.c requires the following ANSI-C constants if the conversion of
    317     * floating point to ASCII is implemented therein:
    318     *
    319     *  DBL_DIG  Maximum number of decimal digits (can be set to any constant)
    320     *  DBL_MIN  Smallest normalized fp number (can be set to an arbitrary value)
    321     *  DBL_MAX  Maximum floating point number (can be set to an arbitrary value)
    322     */
    323 #  include <float.h>
    324 
    325 #  if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
    326     defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
    327      /* We need to check that <math.h> hasn't already been included earlier
    328       * as it seems it doesn't agree with <fp.h>, yet we should really use
    329       * <fp.h> if possible.
    330       */
    331 #    if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
    332 #      include <fp.h>
    333 #    endif
    334 #  else
    335 #    include <math.h>
    336 #  endif
    337 #  if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
    338      /* Amiga SAS/C: We must include builtin FPU functions when compiling using
    339       * MATH=68881
    340       */
    341 #    include <m68881.h>
    342 #  endif
    343 #endif
    344 
    345 /* This provides the non-ANSI (far) memory allocation routines. */
    346 #if defined(__TURBOC__) && defined(__MSDOS__)
    347 #  include <mem.h>
    348 #  include <alloc.h>
    349 #endif
    350 
    351 #if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \
    352     defined(_WIN32) || defined(__WIN32__)
    353 #  include <windows.h>  /* defines _WINDOWS_ macro */
    354 #endif
    355 
    356 /* Moved here around 1.5.0beta36 from pngconf.h */
    357 /* Users may want to use these so they are not private.  Any library
    358  * functions that are passed far data must be model-independent.
    359  */
    360 
    361 /* Memory model/platform independent fns */
    362 #ifndef PNG_ABORT
    363 #  ifdef _WINDOWS_
    364 #    define PNG_ABORT() ExitProcess(0)
    365 #  else
    366 #    define PNG_ABORT() abort()
    367 #  endif
    368 #endif
    369 
    370 #ifdef USE_FAR_KEYWORD
    371 /* Use this to make far-to-near assignments */
    372 #  define CHECK   1
    373 #  define NOCHECK 0
    374 #  define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
    375 #  define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
    376 #  define png_strlen  _fstrlen
    377 #  define png_memcmp  _fmemcmp    /* SJT: added */
    378 #  define png_memcpy  _fmemcpy
    379 #  define png_memset  _fmemset
    380 #else
    381 #  ifdef _WINDOWS_  /* Favor Windows over C runtime fns */
    382 #    define CVT_PTR(ptr)         (ptr)
    383 #    define CVT_PTR_NOCHECK(ptr) (ptr)
    384 #    define png_strlen  lstrlenA
    385 #    define png_memcmp  memcmp
    386 #    define png_memcpy  CopyMemory
    387 #    define png_memset  memset
    388 #  else
    389 #    define CVT_PTR(ptr)         (ptr)
    390 #    define CVT_PTR_NOCHECK(ptr) (ptr)
    391 #    define png_strlen  strlen
    392 #    define png_memcmp  memcmp      /* SJT: added */
    393 #    define png_memcpy  memcpy
    394 #    define png_memset  memset
    395 #  endif
    396 #endif
    397 
    398 /* These macros may need to be architecture dependent. */
    399 #define PNG_ALIGN_NONE   0 /* do not use data alignment */
    400 #define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */
    401 #ifdef offsetof
    402 #  define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */
    403 #else
    404 #  define PNG_ALIGN_OFFSET -1 /* prevent the use of this */
    405 #endif
    406 #define PNG_ALIGN_SIZE   3 /* use sizeof to determine alignment */
    407 
    408 #ifndef PNG_ALIGN_TYPE
    409    /* Default to using aligned access optimizations and requiring alignment to a
    410     * multiple of the data type size.  Override in a compiler specific fashion
    411     * if necessary by inserting tests here:
    412     */
    413 #  define PNG_ALIGN_TYPE PNG_ALIGN_SIZE
    414 #endif
    415 
    416 #if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE
    417    /* This is used because in some compiler implementations non-aligned
    418     * structure members are supported, so the offsetof approach below fails.
    419     * Set PNG_ALIGN_TO_SIZE=0 for compiler combinations where unaligned access
    420     * is good for performance.  Do not do this unless you have tested the result
    421     * and understand it.
    422     */
    423 #  define png_alignof(type) (sizeof (type))
    424 #else
    425 #  if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET
    426 #     define png_alignof(type) offsetof(struct{char c; type t;}, t)
    427 #  else
    428 #     if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS
    429 #        define png_alignof(type) (1)
    430 #     endif
    431       /* Else leave png_alignof undefined to prevent use thereof */
    432 #  endif
    433 #endif
    434 
    435 /* This implicitly assumes alignment is always to a power of 2. */
    436 #ifdef png_alignof
    437 #  define png_isaligned(ptr, type)\
    438    ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0)
    439 #else
    440 #  define png_isaligned(ptr, type) 0
    441 #endif
    442 
    443 /* End of memory model/platform independent support */
    444 /* End of 1.5.0beta36 move from pngconf.h */
    445 
    446 /* CONSTANTS and UTILITY MACROS
    447  * These are used internally by libpng and not exposed in the API
    448  */
    449 
    450 /* Various modes of operation.  Note that after an init, mode is set to
    451  * zero automatically when the structure is created.  Three of these
    452  * are defined in png.h because they need to be visible to applications
    453  * that call png_set_unknown_chunk().
    454  */
    455 /* #define PNG_HAVE_IHDR            0x01 (defined in png.h) */
    456 /* #define PNG_HAVE_PLTE            0x02 (defined in png.h) */
    457 #define PNG_HAVE_IDAT               0x04
    458 /* #define PNG_AFTER_IDAT           0x08 (defined in png.h) */
    459 #define PNG_HAVE_IEND               0x10
    460 #define PNG_HAVE_gAMA               0x20
    461 #define PNG_HAVE_cHRM               0x40
    462 #define PNG_HAVE_sRGB               0x80
    463 #define PNG_HAVE_CHUNK_HEADER      0x100
    464 #define PNG_WROTE_tIME             0x200
    465 #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
    466 #define PNG_BACKGROUND_IS_GRAY     0x800
    467 #define PNG_HAVE_PNG_SIGNATURE    0x1000
    468 #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
    469 #define PNG_HAVE_iCCP             0x4000
    470 
    471 /* Flags for the transformations the PNG library does on the image data */
    472 #define PNG_BGR                 0x0001
    473 #define PNG_INTERLACE           0x0002
    474 #define PNG_PACK                0x0004
    475 #define PNG_SHIFT               0x0008
    476 #define PNG_SWAP_BYTES          0x0010
    477 #define PNG_INVERT_MONO         0x0020
    478 #define PNG_QUANTIZE            0x0040
    479 #define PNG_COMPOSE             0x0080     /* Was PNG_BACKGROUND */
    480 #define PNG_BACKGROUND_EXPAND   0x0100
    481 #define PNG_EXPAND_16           0x0200     /* Added to libpng 1.5.2 */
    482 #define PNG_16_TO_8             0x0400     /* Becomes 'chop' in 1.5.4 */
    483 #define PNG_RGBA                0x0800
    484 #define PNG_EXPAND              0x1000
    485 #define PNG_GAMMA               0x2000
    486 #define PNG_GRAY_TO_RGB         0x4000
    487 #define PNG_FILLER              0x8000
    488 #define PNG_PACKSWAP           0x10000
    489 #define PNG_SWAP_ALPHA         0x20000
    490 #define PNG_STRIP_ALPHA        0x40000
    491 #define PNG_INVERT_ALPHA       0x80000
    492 #define PNG_USER_TRANSFORM    0x100000
    493 #define PNG_RGB_TO_GRAY_ERR   0x200000
    494 #define PNG_RGB_TO_GRAY_WARN  0x400000
    495 #define PNG_RGB_TO_GRAY       0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */
    496 #define PNG_ENCODE_ALPHA      0x800000 /* Added to libpng-1.5.4 */
    497 #define PNG_ADD_ALPHA         0x1000000 /* Added to libpng-1.2.7 */
    498 #define PNG_EXPAND_tRNS       0x2000000 /* Added to libpng-1.2.9 */
    499 #define PNG_SCALE_16_TO_8     0x4000000 /* Added to libpng-1.5.4 */
    500                        /*   0x8000000 unused */
    501                        /*  0x10000000 unused */
    502                        /*  0x20000000 unused */
    503                        /*  0x40000000 unused */
    504 /* Flags for png_create_struct */
    505 #define PNG_STRUCT_PNG   0x0001
    506 #define PNG_STRUCT_INFO  0x0002
    507 
    508 /* Scaling factor for filter heuristic weighting calculations */
    509 #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
    510 #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
    511 
    512 /* Flags for the png_ptr->flags rather than declaring a byte for each one */
    513 #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY     0x0001
    514 #define PNG_FLAG_ZLIB_CUSTOM_LEVEL        0x0002
    515 #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL    0x0004
    516 #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS  0x0008
    517 #define PNG_FLAG_ZLIB_CUSTOM_METHOD       0x0010
    518 #define PNG_FLAG_ZLIB_FINISHED            0x0020
    519 #define PNG_FLAG_ROW_INIT                 0x0040
    520 #define PNG_FLAG_FILLER_AFTER             0x0080
    521 #define PNG_FLAG_CRC_ANCILLARY_USE        0x0100
    522 #define PNG_FLAG_CRC_ANCILLARY_NOWARN     0x0200
    523 #define PNG_FLAG_CRC_CRITICAL_USE         0x0400
    524 #define PNG_FLAG_CRC_CRITICAL_IGNORE      0x0800
    525 #define PNG_FLAG_ASSUME_sRGB              0x1000  /* Added to libpng-1.5.4 */
    526 #define PNG_FLAG_OPTIMIZE_ALPHA           0x2000  /* Added to libpng-1.5.4 */
    527 #define PNG_FLAG_DETECT_UNINITIALIZED     0x4000  /* Added to libpng-1.5.4 */
    528 #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS      0x8000
    529 #define PNG_FLAG_KEEP_UNSAFE_CHUNKS       0x10000
    530 #define PNG_FLAG_LIBRARY_MISMATCH         0x20000
    531 #define PNG_FLAG_STRIP_ERROR_NUMBERS      0x40000
    532 #define PNG_FLAG_STRIP_ERROR_TEXT         0x80000
    533 #define PNG_FLAG_MALLOC_NULL_MEM_OK       0x100000
    534                                   /*      0x200000  unused */
    535                                   /*      0x400000  unused */
    536 #define PNG_FLAG_BENIGN_ERRORS_WARN       0x800000  /* Added to libpng-1.4.0 */
    537 #define PNG_FLAG_ZTXT_CUSTOM_STRATEGY    0x1000000  /* 5 lines added */
    538 #define PNG_FLAG_ZTXT_CUSTOM_LEVEL       0x2000000  /* to libpng-1.5.4 */
    539 #define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL   0x4000000
    540 #define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000
    541 #define PNG_FLAG_ZTXT_CUSTOM_METHOD      0x10000000
    542                                   /*     0x20000000  unused */
    543                                   /*     0x40000000  unused */
    544 
    545 #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
    546                                      PNG_FLAG_CRC_ANCILLARY_NOWARN)
    547 
    548 #define PNG_FLAG_CRC_CRITICAL_MASK  (PNG_FLAG_CRC_CRITICAL_USE | \
    549                                      PNG_FLAG_CRC_CRITICAL_IGNORE)
    550 
    551 #define PNG_FLAG_CRC_MASK           (PNG_FLAG_CRC_ANCILLARY_MASK | \
    552                                      PNG_FLAG_CRC_CRITICAL_MASK)
    553 
    554 /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
    555  * can handle at once.  This type need be no larger than 16 bits (so maximum of
    556  * 65535), this define allows us to discover how big it is, but limited by the
    557  * maximuum for png_size_t.  The value can be overriden in a library build
    558  * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
    559  * lower value (e.g. 255 works).  A lower value may help memory usage (slightly)
    560  * and may even improve performance on some systems (and degrade it on others.)
    561  */
    562 #ifndef ZLIB_IO_MAX
    563 #  define ZLIB_IO_MAX ((uInt)-1)
    564 #endif
    565 
    566 /* Save typing and make code easier to understand */
    567 
    568 #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
    569    abs((int)((c1).green) - (int)((c2).green)) + \
    570    abs((int)((c1).blue) - (int)((c2).blue)))
    571 
    572 /* Added to libpng-1.2.6 JB */
    573 #define PNG_ROWBYTES(pixel_bits, width) \
    574     ((pixel_bits) >= 8 ? \
    575     ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
    576     (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )
    577 
    578 /* PNG_OUT_OF_RANGE returns true if value is outside the range
    579  * ideal-delta..ideal+delta.  Each argument is evaluated twice.
    580  * "ideal" and "delta" should be constants, normally simple
    581  * integers, "value" a variable. Added to libpng-1.2.6 JB
    582  */
    583 #define PNG_OUT_OF_RANGE(value, ideal, delta) \
    584    ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
    585 
    586 /* Conversions between fixed and floating point, only defined if
    587  * required (to make sure the code doesn't accidentally use float
    588  * when it is supposedly disabled.)
    589  */
    590 #ifdef PNG_FLOATING_POINT_SUPPORTED
    591 /* The floating point conversion can't overflow, though it can and
    592  * does lose accuracy relative to the original fixed point value.
    593  * In practice this doesn't matter because png_fixed_point only
    594  * stores numbers with very low precision.  The png_ptr and s
    595  * arguments are unused by default but are there in case error
    596  * checking becomes a requirement.
    597  */
    598 #define png_float(png_ptr, fixed, s) (.00001 * (fixed))
    599 
    600 /* The fixed point conversion performs range checking and evaluates
    601  * its argument multiple times, so must be used with care.  The
    602  * range checking uses the PNG specification values for a signed
    603  * 32 bit fixed point value except that the values are deliberately
    604  * rounded-to-zero to an integral value - 21474 (21474.83 is roughly
    605  * (2^31-1) * 100000). 's' is a string that describes the value being
    606  * converted.
    607  *
    608  * NOTE: this macro will raise a png_error if the range check fails,
    609  * therefore it is normally only appropriate to use this on values
    610  * that come from API calls or other sources where an out of range
    611  * error indicates a programming error, not a data error!
    612  *
    613  * NOTE: by default this is off - the macro is not used - because the
    614  * function call saves a lot of code.
    615  */
    616 #ifdef PNG_FIXED_POINT_MACRO_SUPPORTED
    617 #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
    618     ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))
    619 #else
    620 PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp,
    621    png_const_charp text));
    622 #endif
    623 #endif
    624 
    625 /* Constants for known chunk types.  If you need to add a chunk, define the name
    626  * here.  For historical reasons these constants have the form png_<name>; i.e.
    627  * the prefix is lower case.  Please use decimal values as the parameters to
    628  * match the ISO PNG specification and to avoid relying on the C locale
    629  * interpretation of character values.
    630  *
    631  * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values
    632  * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string
    633  * to be generated if required.
    634  *
    635  * PNG_32b correctly produces a value shifted by up to 24 bits, even on
    636  * architectures where (int) is only 16 bits.
    637  */
    638 #define PNG_32b(b,s) ((png_uint_32)(b) << (s))
    639 #define PNG_CHUNK(b1,b2,b3,b4) \
    640    (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
    641 
    642 #define png_IHDR PNG_CHUNK( 73,  72,  68,  82)
    643 #define png_IDAT PNG_CHUNK( 73,  68,  65,  84)
    644 #define png_IEND PNG_CHUNK( 73,  69,  78,  68)
    645 #define png_PLTE PNG_CHUNK( 80,  76,  84,  69)
    646 #define png_bKGD PNG_CHUNK( 98,  75,  71,  68)
    647 #define png_cHRM PNG_CHUNK( 99,  72,  82,  77)
    648 #define png_gAMA PNG_CHUNK(103,  65,  77,  65)
    649 #define png_hIST PNG_CHUNK(104,  73,  83,  84)
    650 #define png_iCCP PNG_CHUNK(105,  67,  67,  80)
    651 #define png_iTXt PNG_CHUNK(105,  84,  88, 116)
    652 #define png_oFFs PNG_CHUNK(111,  70,  70, 115)
    653 #define png_pCAL PNG_CHUNK(112,  67,  65,  76)
    654 #define png_sCAL PNG_CHUNK(115,  67,  65,  76)
    655 #define png_pHYs PNG_CHUNK(112,  72,  89, 115)
    656 #define png_sBIT PNG_CHUNK(115,  66,  73,  84)
    657 #define png_sPLT PNG_CHUNK(115,  80,  76,  84)
    658 #define png_sRGB PNG_CHUNK(115,  82,  71,  66)
    659 #define png_sTER PNG_CHUNK(115,  84,  69,  82)
    660 #define png_tEXt PNG_CHUNK(116,  69,  88, 116)
    661 #define png_tIME PNG_CHUNK(116,  73,  77,  69)
    662 #define png_tRNS PNG_CHUNK(116,  82,  78,  83)
    663 #define png_zTXt PNG_CHUNK(122,  84,  88, 116)
    664 
    665 /* The following will work on (signed char*) strings, whereas the get_uint_32
    666  * macro will fail on top-bit-set values because of the sign extension.
    667  */
    668 #define PNG_CHUNK_FROM_STRING(s)\
    669    PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3])
    670 
    671 /* This uses (char), not (png_byte) to avoid warnings on systems where (char) is
    672  * signed and the argument is a (char[])  This macro will fail miserably on
    673  * systems where (char) is more than 8 bits.
    674  */
    675 #define PNG_STRING_FROM_CHUNK(s,c)\
    676    (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\
    677    ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c)))
    678 
    679 /* Do the same but terminate with a null character. */
    680 #define PNG_CSTRING_FROM_CHUNK(s,c)\
    681    (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
    682 
    683 /* Test on flag values as defined in the spec (section 5.4): */
    684 #define PNG_CHUNK_ANCILLIARY(c)   (1 & ((c) >> 29))
    685 #define PNG_CHUNK_CRITICAL(c)     (!PNG_CHUNK_ANCILLIARY(c))
    686 #define PNG_CHUNK_PRIVATE(c)      (1 & ((c) >> 21))
    687 #define PNG_CHUNK_RESERVED(c)     (1 & ((c) >> 13))
    688 #define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >>  5))
    689 
    690 /* Gamma values (new at libpng-1.5.4): */
    691 #define PNG_GAMMA_MAC_OLD 151724  /* Assume '1.8' is really 2.2/1.45! */
    692 #define PNG_GAMMA_MAC_INVERSE 65909
    693 #define PNG_GAMMA_sRGB_INVERSE 45455
    694 
    695 
    696 /* Inhibit C++ name-mangling for libpng functions but not for system calls. */
    697 #ifdef __cplusplus
    698 extern "C" {
    699 #endif /* __cplusplus */
    700 
    701 /* These functions are used internally in the code.  They generally
    702  * shouldn't be used unless you are writing code to add or replace some
    703  * functionality in libpng.  More information about most functions can
    704  * be found in the files where the functions are located.
    705  */
    706 
    707 /* Check the user version string for compatibility, returns false if the version
    708  * numbers aren't compatible.
    709  */
    710 PNG_EXTERN int png_user_version_check(png_structp png_ptr,
    711    png_const_charp user_png_ver);
    712 
    713 /* Allocate memory for an internal libpng struct */
    714 PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)),
    715    PNG_ALLOCATED);
    716 
    717 /* Free memory from internal libpng struct */
    718 PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
    719 
    720 PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2,
    721    PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)),
    722    PNG_ALLOCATED);
    723 PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
    724     png_free_ptr free_fn, png_voidp mem_ptr));
    725 
    726 /* Free any memory that info_ptr points to and reset struct. */
    727 PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
    728     png_infop info_ptr));
    729 
    730 /* Function to allocate memory for zlib.  PNGAPI is disallowed. */
    731 PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items,
    732    uInt size)),PNG_ALLOCATED);
    733 
    734 /* Function to free memory for zlib.  PNGAPI is disallowed. */
    735 PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
    736 
    737 /* Next four functions are used internally as callbacks.  PNGCBAPI is required
    738  * but not PNG_EXPORT.  PNGAPI added at libpng version 1.2.3, changed to
    739  * PNGCBAPI at 1.5.0
    740  */
    741 
    742 PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr,
    743     png_bytep data, png_size_t length));
    744 
    745 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
    746 PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
    747     png_bytep buffer, png_size_t length));
    748 #endif
    749 
    750 PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr,
    751     png_bytep data, png_size_t length));
    752 
    753 #ifdef PNG_WRITE_FLUSH_SUPPORTED
    754 #  ifdef PNG_STDIO_SUPPORTED
    755 PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr));
    756 #  endif
    757 #endif
    758 
    759 /* Reset the CRC variable */
    760 PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
    761 
    762 /* Write the "data" buffer to whatever output you are using */
    763 PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr,
    764     png_const_bytep data, png_size_t length));
    765 
    766 /* Read and check the PNG file signature */
    767 PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr));
    768 
    769 /* Read the chunk header (length + type name) */
    770 PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr));
    771 
    772 /* Read data from whatever input you are using into the "data" buffer */
    773 PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
    774     png_size_t length));
    775 
    776 /* Read bytes into buf, and update png_ptr->crc */
    777 PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
    778     png_size_t length));
    779 
    780 /* Decompress data in a chunk that uses compression */
    781 #if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED)
    782 PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr,
    783     int comp_type, png_size_t chunklength, png_size_t prefix_length,
    784     png_size_t *data_length));
    785 #endif
    786 
    787 /* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
    788 PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
    789 
    790 /* Read the CRC from the file and compare it to the libpng calculated CRC */
    791 PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
    792 
    793 /* Calculate the CRC over a section of data.  Note that we are only
    794  * passing a maximum of 64K on systems that have this as a memory limit,
    795  * since this is the maximum buffer size we can specify.
    796  */
    797 PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr,
    798     png_const_bytep ptr, png_size_t length));
    799 
    800 #ifdef PNG_WRITE_FLUSH_SUPPORTED
    801 PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
    802 #endif
    803 
    804 /* Write various chunks */
    805 
    806 /* Write the IHDR chunk, and update the png_struct with the necessary
    807  * information.
    808  */
    809 PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
    810     png_uint_32 height,
    811     int bit_depth, int color_type, int compression_method, int filter_method,
    812     int interlace_method));
    813 
    814 PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr,
    815     png_const_colorp palette, png_uint_32 num_pal));
    816 
    817 PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
    818     png_size_t length));
    819 
    820 PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
    821 
    822 #ifdef PNG_WRITE_gAMA_SUPPORTED
    823 #  ifdef PNG_FLOATING_POINT_SUPPORTED
    824 PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
    825 #  endif
    826 #  ifdef PNG_FIXED_POINT_SUPPORTED
    827 PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr,
    828     png_fixed_point file_gamma));
    829 #  endif
    830 #endif
    831 
    832 #ifdef PNG_WRITE_sBIT_SUPPORTED
    833 PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr,
    834     png_const_color_8p sbit, int color_type));
    835 #endif
    836 
    837 #ifdef PNG_WRITE_cHRM_SUPPORTED
    838 #  ifdef PNG_FLOATING_POINT_SUPPORTED
    839 PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
    840     double white_x, double white_y,
    841     double red_x, double red_y, double green_x, double green_y,
    842     double blue_x, double blue_y));
    843 #  endif
    844 PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
    845     png_fixed_point int_white_x, png_fixed_point int_white_y,
    846     png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
    847     int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
    848     png_fixed_point int_blue_y));
    849 #endif
    850 
    851 #ifdef PNG_WRITE_sRGB_SUPPORTED
    852 PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
    853     int intent));
    854 #endif
    855 
    856 #ifdef PNG_WRITE_iCCP_SUPPORTED
    857 PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
    858     png_const_charp name, int compression_type,
    859     png_const_charp profile, int proflen));
    860    /* Note to maintainer: profile should be png_bytep */
    861 #endif
    862 
    863 #ifdef PNG_WRITE_sPLT_SUPPORTED
    864 PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
    865     png_const_sPLT_tp palette));
    866 #endif
    867 
    868 #ifdef PNG_WRITE_tRNS_SUPPORTED
    869 PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr,
    870     png_const_bytep trans, png_const_color_16p values, int number,
    871     int color_type));
    872 #endif
    873 
    874 #ifdef PNG_WRITE_bKGD_SUPPORTED
    875 PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
    876     png_const_color_16p values, int color_type));
    877 #endif
    878 
    879 #ifdef PNG_WRITE_hIST_SUPPORTED
    880 PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr,
    881     png_const_uint_16p hist, int num_hist));
    882 #endif
    883 
    884 /* Chunks that have keywords */
    885 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
    886     defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
    887 PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
    888     png_const_charp key, png_charpp new_key));
    889 #endif
    890 
    891 #ifdef PNG_WRITE_tEXt_SUPPORTED
    892 PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key,
    893     png_const_charp text, png_size_t text_len));
    894 #endif
    895 
    896 #ifdef PNG_WRITE_zTXt_SUPPORTED
    897 PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key,
    898     png_const_charp text, png_size_t text_len, int compression));
    899 #endif
    900 
    901 #ifdef PNG_WRITE_iTXt_SUPPORTED
    902 PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
    903     int compression, png_const_charp key, png_const_charp lang,
    904     png_const_charp lang_key, png_const_charp text));
    905 #endif
    906 
    907 #ifdef PNG_TEXT_SUPPORTED  /* Added at version 1.0.14 and 1.2.4 */
    908 PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
    909     png_infop info_ptr, png_const_textp text_ptr, int num_text));
    910 #endif
    911 
    912 #ifdef PNG_WRITE_oFFs_SUPPORTED
    913 PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
    914     png_int_32 x_offset, png_int_32 y_offset, int unit_type));
    915 #endif
    916 
    917 #ifdef PNG_WRITE_pCAL_SUPPORTED
    918 PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
    919     png_int_32 X0, png_int_32 X1, int type, int nparams,
    920     png_const_charp units, png_charpp params));
    921 #endif
    922 
    923 #ifdef PNG_WRITE_pHYs_SUPPORTED
    924 PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
    925     png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
    926     int unit_type));
    927 #endif
    928 
    929 #ifdef PNG_WRITE_tIME_SUPPORTED
    930 PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
    931     png_const_timep mod_time));
    932 #endif
    933 
    934 #ifdef PNG_WRITE_sCAL_SUPPORTED
    935 PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
    936     int unit, png_const_charp width, png_const_charp height));
    937 #endif
    938 
    939 /* Called when finished processing a row of data */
    940 PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
    941 
    942 /* Internal use only.   Called before first row of data */
    943 PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
    944 
    945 /* Combine a row of data, dealing with alpha, etc. if requested.  'row' is an
    946  * array of png_ptr->width pixels.  If the image is not interlaced or this
    947  * is the final pass this just does a png_memcpy, otherwise the "display" flag
    948  * is used to determine whether to copy pixels that are not in the current pass.
    949  *
    950  * Because 'png_do_read_interlace' (below) replicates pixels this allows this
    951  * function to achieve the documented 'blocky' appearance during interlaced read
    952  * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row'
    953  * are not changed if they are not in the current pass, when display is 0.
    954  *
    955  * 'display' must be 0 or 1, otherwise the memcpy will be done regardless.
    956  *
    957  * The API always reads from the png_struct row buffer and always assumes that
    958  * it is full width (png_do_read_interlace has already been called.)
    959  *
    960  * This function is only ever used to write to row buffers provided by the
    961  * caller of the relevant libpng API and the row must have already been
    962  * transformed by the read transformations.
    963  *
    964  * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed
    965  * bitmasks for use within the code, otherwise runtime generated masks are used.
    966  * The default is compile time masks.
    967  */
    968 #ifndef PNG_USE_COMPILE_TIME_MASKS
    969 #  define PNG_USE_COMPILE_TIME_MASKS 1
    970 #endif
    971 PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
    972     int display));
    973 
    974 #ifdef PNG_READ_INTERLACING_SUPPORTED
    975 /* Expand an interlaced row: the 'row_info' describes the pass data that has
    976  * been read in and must correspond to the pixels in 'row', the pixels are
    977  * expanded (moved apart) in 'row' to match the final layout, when doing this
    978  * the pixels are *replicated* to the intervening space.  This is essential for
    979  * the correct operation of png_combine_row, above.
    980  */
    981 PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
    982     png_bytep row, int pass, png_uint_32 transformations));
    983 #endif
    984 
    985 /* GRR TO DO (2.0 or whenever):  simplify other internal calling interfaces */
    986 
    987 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
    988 /* Grab pixels out of a row for an interlaced pass */
    989 PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
    990     png_bytep row, int pass));
    991 #endif
    992 
    993 /* Unfilter a row: check the filter value before calling this, there is no point
    994  * calling it for PNG_FILTER_VALUE_NONE.
    995  */
    996 PNG_EXTERN void png_read_filter_row PNGARG((png_structp pp, png_row_infop
    997     row_info, png_bytep row, png_const_bytep prev_row, int filter));
    998 
    999 PNG_EXTERN void png_read_filter_row_up_neon PNGARG((png_row_infop row_info,
   1000     png_bytep row, png_const_bytep prev_row));
   1001 PNG_EXTERN void png_read_filter_row_sub3_neon PNGARG((png_row_infop row_info,
   1002     png_bytep row, png_const_bytep prev_row));
   1003 PNG_EXTERN void png_read_filter_row_sub4_neon PNGARG((png_row_infop row_info,
   1004     png_bytep row, png_const_bytep prev_row));
   1005 PNG_EXTERN void png_read_filter_row_avg3_neon PNGARG((png_row_infop row_info,
   1006     png_bytep row, png_const_bytep prev_row));
   1007 PNG_EXTERN void png_read_filter_row_avg4_neon PNGARG((png_row_infop row_info,
   1008     png_bytep row, png_const_bytep prev_row));
   1009 PNG_EXTERN void png_read_filter_row_paeth3_neon PNGARG((png_row_infop row_info,
   1010     png_bytep row, png_const_bytep prev_row));
   1011 PNG_EXTERN void png_read_filter_row_paeth4_neon PNGARG((png_row_infop row_info,
   1012     png_bytep row, png_const_bytep prev_row));
   1013 
   1014 /* Choose the best filter to use and filter the row data */
   1015 PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
   1016     png_row_infop row_info));
   1017 
   1018 /* Finish a row while reading, dealing with interlacing passes, etc. */
   1019 PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
   1020 
   1021 /* Initialize the row buffers, etc. */
   1022 PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
   1023 
   1024 #ifdef PNG_READ_TRANSFORMS_SUPPORTED
   1025 /* Optional call to update the users info structure */
   1026 PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
   1027     png_infop info_ptr));
   1028 #endif
   1029 
   1030 /* These are the functions that do the transformations */
   1031 #ifdef PNG_READ_FILLER_SUPPORTED
   1032 PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
   1033     png_bytep row, png_uint_32 filler, png_uint_32 flags));
   1034 #endif
   1035 
   1036 #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
   1037 PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
   1038     png_bytep row));
   1039 #endif
   1040 
   1041 #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
   1042 PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
   1043     png_bytep row));
   1044 #endif
   1045 
   1046 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
   1047 PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
   1048     png_bytep row));
   1049 #endif
   1050 
   1051 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
   1052 PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
   1053     png_bytep row));
   1054 #endif
   1055 
   1056 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
   1057     defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
   1058 PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info,
   1059     png_bytep row, int at_start));
   1060 #endif
   1061 
   1062 #ifdef PNG_16BIT_SUPPORTED
   1063 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
   1064 PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info,
   1065     png_bytep row));
   1066 #endif
   1067 #endif
   1068 
   1069 #if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
   1070     defined(PNG_WRITE_PACKSWAP_SUPPORTED)
   1071 PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info,
   1072     png_bytep row));
   1073 #endif
   1074 
   1075 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
   1076 PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr,
   1077     png_row_infop row_info, png_bytep row));
   1078 #endif
   1079 
   1080 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
   1081 PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
   1082     png_bytep row));
   1083 #endif
   1084 
   1085 #ifdef PNG_READ_PACK_SUPPORTED
   1086 PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info,
   1087     png_bytep row));
   1088 #endif
   1089 
   1090 #ifdef PNG_READ_SHIFT_SUPPORTED
   1091 PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info,
   1092     png_bytep row, png_const_color_8p sig_bits));
   1093 #endif
   1094 
   1095 #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
   1096 PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info,
   1097     png_bytep row));
   1098 #endif
   1099 
   1100 #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
   1101 PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info,
   1102     png_bytep row));
   1103 #endif
   1104 
   1105 #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
   1106 PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info,
   1107     png_bytep row));
   1108 #endif
   1109 
   1110 #ifdef PNG_READ_QUANTIZE_SUPPORTED
   1111 PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info,
   1112     png_bytep row, png_const_bytep palette_lookup,
   1113     png_const_bytep quantize_lookup));
   1114 
   1115 #  ifdef PNG_CORRECT_PALETTE_SUPPORTED
   1116 PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
   1117     png_colorp palette, int num_palette));
   1118 #  endif
   1119 #endif
   1120 
   1121 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
   1122 PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info,
   1123     png_bytep row));
   1124 #endif
   1125 
   1126 #ifdef PNG_WRITE_PACK_SUPPORTED
   1127 PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
   1128    png_bytep row, png_uint_32 bit_depth));
   1129 #endif
   1130 
   1131 #ifdef PNG_WRITE_SHIFT_SUPPORTED
   1132 PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info,
   1133     png_bytep row, png_const_color_8p bit_depth));
   1134 #endif
   1135 
   1136 #if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
   1137     defined(PNG_READ_ALPHA_MODE_SUPPORTED)
   1138 PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info,
   1139     png_bytep row, png_structp png_ptr));
   1140 #endif
   1141 
   1142 #ifdef PNG_READ_GAMMA_SUPPORTED
   1143 PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info,
   1144     png_bytep row, png_structp png_ptr));
   1145 #endif
   1146 
   1147 #ifdef PNG_READ_ALPHA_MODE_SUPPORTED
   1148 PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info,
   1149    png_bytep row, png_structp png_ptr));
   1150 #endif
   1151 
   1152 #ifdef PNG_READ_EXPAND_SUPPORTED
   1153 PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
   1154     png_bytep row, png_const_colorp palette, png_const_bytep trans,
   1155     int num_trans));
   1156 PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
   1157     png_bytep row, png_const_color_16p trans_color));
   1158 #endif
   1159 
   1160 #ifdef PNG_READ_EXPAND_16_SUPPORTED
   1161 PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info,
   1162     png_bytep row));
   1163 #endif
   1164 
   1165 /* The following decodes the appropriate chunks, and does error correction,
   1166  * then calls the appropriate callback for the chunk if it is valid.
   1167  */
   1168 
   1169 /* Decode the IHDR chunk */
   1170 PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
   1171     png_uint_32 length));
   1172 PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
   1173     png_uint_32 length));
   1174 PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
   1175     png_uint_32 length));
   1176 
   1177 #ifdef PNG_READ_bKGD_SUPPORTED
   1178 PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
   1179     png_uint_32 length));
   1180 #endif
   1181 
   1182 #ifdef PNG_READ_cHRM_SUPPORTED
   1183 PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
   1184     png_uint_32 length));
   1185 #endif
   1186 
   1187 #ifdef PNG_READ_gAMA_SUPPORTED
   1188 PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
   1189     png_uint_32 length));
   1190 #endif
   1191 
   1192 #ifdef PNG_READ_hIST_SUPPORTED
   1193 PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
   1194     png_uint_32 length));
   1195 #endif
   1196 
   1197 #ifdef PNG_READ_iCCP_SUPPORTED
   1198 PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
   1199     png_uint_32 length));
   1200 #endif /* PNG_READ_iCCP_SUPPORTED */
   1201 
   1202 #ifdef PNG_READ_iTXt_SUPPORTED
   1203 PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
   1204     png_uint_32 length));
   1205 #endif
   1206 
   1207 #ifdef PNG_READ_oFFs_SUPPORTED
   1208 PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
   1209     png_uint_32 length));
   1210 #endif
   1211 
   1212 #ifdef PNG_READ_pCAL_SUPPORTED
   1213 PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
   1214     png_uint_32 length));
   1215 #endif
   1216 
   1217 #ifdef PNG_READ_pHYs_SUPPORTED
   1218 PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
   1219     png_uint_32 length));
   1220 #endif
   1221 
   1222 #ifdef PNG_READ_sBIT_SUPPORTED
   1223 PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
   1224     png_uint_32 length));
   1225 #endif
   1226 
   1227 #ifdef PNG_READ_sCAL_SUPPORTED
   1228 PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
   1229     png_uint_32 length));
   1230 #endif
   1231 
   1232 #ifdef PNG_READ_sPLT_SUPPORTED
   1233 PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
   1234     png_uint_32 length));
   1235 #endif /* PNG_READ_sPLT_SUPPORTED */
   1236 
   1237 #ifdef PNG_READ_sRGB_SUPPORTED
   1238 PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
   1239     png_uint_32 length));
   1240 #endif
   1241 
   1242 #ifdef PNG_READ_tEXt_SUPPORTED
   1243 PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
   1244     png_uint_32 length));
   1245 #endif
   1246 
   1247 #ifdef PNG_READ_tIME_SUPPORTED
   1248 PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
   1249     png_uint_32 length));
   1250 #endif
   1251 
   1252 #ifdef PNG_READ_tRNS_SUPPORTED
   1253 PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
   1254     png_uint_32 length));
   1255 #endif
   1256 
   1257 #ifdef PNG_READ_zTXt_SUPPORTED
   1258 PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
   1259     png_uint_32 length));
   1260 #endif
   1261 
   1262 PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
   1263     png_infop info_ptr, png_uint_32 length));
   1264 
   1265 PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
   1266     png_uint_32 chunk_name));
   1267 
   1268 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
   1269 /* Exactly as png_handle_as_unknown() except that the argument is a 32-bit chunk
   1270  * name, not a string.
   1271  */
   1272 PNG_EXTERN int png_chunk_unknown_handling PNGARG((png_structp png_ptr,
   1273     png_uint_32 chunk_name));
   1274 #endif
   1275 
   1276 /* Handle the transformations for reading and writing */
   1277 #ifdef PNG_READ_TRANSFORMS_SUPPORTED
   1278 PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr,
   1279    png_row_infop row_info));
   1280 #endif
   1281 #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
   1282 PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr,
   1283    png_row_infop row_info));
   1284 #endif
   1285 
   1286 #ifdef PNG_READ_TRANSFORMS_SUPPORTED
   1287 PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
   1288 #endif
   1289 
   1290 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
   1291 PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
   1292     png_infop info_ptr));
   1293 PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
   1294     png_infop info_ptr));
   1295 PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
   1296 PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
   1297     png_uint_32 length));
   1298 PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
   1299 PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
   1300 PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
   1301     png_bytep buffer, png_size_t buffer_length));
   1302 PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
   1303 PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
   1304     png_bytep buffer, png_size_t buffer_length));
   1305 PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
   1306 PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
   1307    png_infop info_ptr, png_uint_32 length));
   1308 PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
   1309    png_infop info_ptr));
   1310 PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
   1311    png_infop info_ptr));
   1312 PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
   1313 PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
   1314     png_infop info_ptr));
   1315 PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
   1316     png_infop info_ptr));
   1317 PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
   1318 #  ifdef PNG_READ_tEXt_SUPPORTED
   1319 PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
   1320     png_infop info_ptr, png_uint_32 length));
   1321 PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
   1322     png_infop info_ptr));
   1323 #  endif
   1324 #  ifdef PNG_READ_zTXt_SUPPORTED
   1325 PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
   1326     png_infop info_ptr, png_uint_32 length));
   1327 PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
   1328     png_infop info_ptr));
   1329 #  endif
   1330 #  ifdef PNG_READ_iTXt_SUPPORTED
   1331 PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
   1332     png_infop info_ptr, png_uint_32 length));
   1333 PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
   1334     png_infop info_ptr));
   1335 #  endif
   1336 
   1337 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
   1338 
   1339 #ifdef PNG_MNG_FEATURES_SUPPORTED
   1340 PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
   1341     png_bytep row));
   1342 PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
   1343     png_bytep row));
   1344 #endif
   1345 
   1346 /* Added at libpng version 1.4.0 */
   1347 #ifdef PNG_CHECK_cHRM_SUPPORTED
   1348 PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr,
   1349     png_fixed_point int_white_x, png_fixed_point int_white_y,
   1350     png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
   1351     int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
   1352     png_fixed_point int_blue_y));
   1353 #endif
   1354 
   1355 #ifdef PNG_CHECK_cHRM_SUPPORTED
   1356 /* Added at libpng version 1.2.34 and 1.4.0 */
   1357 /* Currently only used by png_check_cHRM_fixed */
   1358 PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2,
   1359     unsigned long *hi_product, unsigned long *lo_product));
   1360 #endif
   1361 
   1362 #ifdef PNG_cHRM_SUPPORTED
   1363 /* Added at libpng version 1.5.5 */
   1364 typedef struct png_xy
   1365 {
   1366    png_fixed_point redx, redy;
   1367    png_fixed_point greenx, greeny;
   1368    png_fixed_point bluex, bluey;
   1369    png_fixed_point whitex, whitey;
   1370 } png_xy;
   1371 
   1372 typedef struct png_XYZ
   1373 {
   1374    png_fixed_point redX, redY, redZ;
   1375    png_fixed_point greenX, greenY, greenZ;
   1376    png_fixed_point blueX, blueY, blueZ;
   1377 } png_XYZ;
   1378 
   1379 /* The conversion APIs return 0 on success, non-zero on a parameter error. They
   1380  * allow conversion between the above representations of a color encoding.  When
   1381  * converting from XYZ end points to chromaticities the absolute magnitude of
   1382  * the end points is lost, when converting back the sum of the Y values of the
   1383  * three end points will be 1.0
   1384  */
   1385 PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ));
   1386 PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy));
   1387 PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_structp png_ptr,
   1388    png_XYZ *XYZ, png_xy xy));
   1389 #endif
   1390 
   1391 /* Added at libpng version 1.4.0 */
   1392 PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr,
   1393     png_uint_32 width, png_uint_32 height, int bit_depth,
   1394     int color_type, int interlace_type, int compression_type,
   1395     int filter_type));
   1396 
   1397 /* Added at libpng version 1.5.10 */
   1398 #if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
   1399     defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
   1400 PNG_EXTERN void png_do_check_palette_indexes PNGARG((png_structp png_ptr,
   1401     png_row_infop row_info));
   1402 #endif
   1403 
   1404 /* Free all memory used by the read (old method - NOT DLL EXPORTED) */
   1405 PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr,
   1406     png_infop info_ptr, png_infop end_info_ptr));
   1407 
   1408 /* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
   1409 PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr));
   1410 
   1411 #ifdef USE_FAR_KEYWORD  /* memory model conversion function */
   1412 PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr,
   1413     int check));
   1414 #endif /* USE_FAR_KEYWORD */
   1415 
   1416 #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
   1417 PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr,
   1418    png_const_charp name),PNG_NORETURN);
   1419 #endif
   1420 
   1421 /* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite
   1422  * the end.  Always leaves the buffer nul terminated.  Never errors out (and
   1423  * there is no error code.)
   1424  */
   1425 PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos,
   1426     png_const_charp string);
   1427 
   1428 /* Various internal functions to handle formatted warning messages, currently
   1429  * only implemented for warnings.
   1430  */
   1431 #if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
   1432 /* Utility to dump an unsigned value into a buffer, given a start pointer and
   1433  * and end pointer (which should point just *beyond* the end of the buffer!)
   1434  * Returns the pointer to the start of the formatted string.  This utility only
   1435  * does unsigned values.
   1436  */
   1437 PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end,
   1438    int format, png_alloc_size_t number);
   1439 
   1440 /* Convenience macro that takes an array: */
   1441 #define PNG_FORMAT_NUMBER(buffer,format,number) \
   1442    png_format_number(buffer, buffer + (sizeof buffer), format, number)
   1443 
   1444 /* Suggested size for a number buffer (enough for 64 bits and a sign!) */
   1445 #define PNG_NUMBER_BUFFER_SIZE 24
   1446 
   1447 /* These are the integer formats currently supported, the name is formed from
   1448  * the standard printf(3) format string.
   1449  */
   1450 #define PNG_NUMBER_FORMAT_u     1 /* chose unsigned API! */
   1451 #define PNG_NUMBER_FORMAT_02u   2
   1452 #define PNG_NUMBER_FORMAT_d     1 /* chose signed API! */
   1453 #define PNG_NUMBER_FORMAT_02d   2
   1454 #define PNG_NUMBER_FORMAT_x     3
   1455 #define PNG_NUMBER_FORMAT_02x   4
   1456 #define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */
   1457 #endif
   1458 
   1459 #ifdef PNG_WARNINGS_SUPPORTED
   1460 /* New defines and members adding in libpng-1.5.4 */
   1461 #  define PNG_WARNING_PARAMETER_SIZE 32
   1462 #  define PNG_WARNING_PARAMETER_COUNT 8
   1463 
   1464 /* An l-value of this type has to be passed to the APIs below to cache the
   1465  * values of the parameters to a formatted warning message.
   1466  */
   1467 typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][
   1468    PNG_WARNING_PARAMETER_SIZE];
   1469 
   1470 PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number,
   1471     png_const_charp string);
   1472     /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters,
   1473      * including the trailing '\0'.
   1474      */
   1475 PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p,
   1476     int number, int format, png_alloc_size_t value);
   1477     /* Use png_alloc_size_t because it is an unsigned type as big as any we
   1478      * need to output.  Use the following for a signed value.
   1479      */
   1480 PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p,
   1481     int number, int format, png_int_32 value);
   1482 
   1483 PNG_EXTERN void png_formatted_warning(png_structp png_ptr,
   1484     png_warning_parameters p, png_const_charp message);
   1485     /* 'message' follows the X/Open approach of using @1, @2 to insert
   1486      * parameters previously supplied using the above functions.  Errors in
   1487      * specifying the paramters will simple result in garbage substitutions.
   1488      */
   1489 #endif
   1490 
   1491 /* ASCII to FP interfaces, currently only implemented if sCAL
   1492  * support is required.
   1493  */
   1494 #if defined(PNG_READ_sCAL_SUPPORTED)
   1495 /* MAX_DIGITS is actually the maximum number of characters in an sCAL
   1496  * width or height, derived from the precision (number of significant
   1497  * digits - a build time settable option) and assumpitions about the
   1498  * maximum ridiculous exponent.
   1499  */
   1500 #define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)
   1501 
   1502 #ifdef PNG_FLOATING_POINT_SUPPORTED
   1503 PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii,
   1504     png_size_t size, double fp, unsigned int precision));
   1505 #endif /* FLOATING_POINT */
   1506 
   1507 #ifdef PNG_FIXED_POINT_SUPPORTED
   1508 PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr,
   1509     png_charp ascii, png_size_t size, png_fixed_point fp));
   1510 #endif /* FIXED_POINT */
   1511 #endif /* READ_sCAL */
   1512 
   1513 #if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
   1514 /* An internal API to validate the format of a floating point number.
   1515  * The result is the index of the next character.  If the number is
   1516  * not valid it will be the index of a character in the supposed number.
   1517  *
   1518  * The format of a number is defined in the PNG extensions specification
   1519  * and this API is strictly conformant to that spec, not anyone elses!
   1520  *
   1521  * The format as a regular expression is:
   1522  *
   1523  * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
   1524  *
   1525  * or:
   1526  *
   1527  * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
   1528  *
   1529  * The complexity is that either integer or fraction must be present and the
   1530  * fraction is permitted to have no digits only if the integer is present.
   1531  *
   1532  * NOTE: The dangling E problem.
   1533  *   There is a PNG valid floating point number in the following:
   1534  *
   1535  *       PNG floating point numb1.ers are not greedy.
   1536  *
   1537  *   Working this out requires *TWO* character lookahead (because of the
   1538  *   sign), the parser does not do this - it will fail at the 'r' - this
   1539  *   doesn't matter for PNG sCAL chunk values, but it requires more care
   1540  *   if the value were ever to be embedded in something more complex.  Use
   1541  *   ANSI-C strtod if you need the lookahead.
   1542  */
   1543 /* State table for the parser. */
   1544 #define PNG_FP_INTEGER    0  /* before or in integer */
   1545 #define PNG_FP_FRACTION   1  /* before or in fraction */
   1546 #define PNG_FP_EXPONENT   2  /* before or in exponent */
   1547 #define PNG_FP_STATE      3  /* mask for the above */
   1548 #define PNG_FP_SAW_SIGN   4  /* Saw +/- in current state */
   1549 #define PNG_FP_SAW_DIGIT  8  /* Saw a digit in current state */
   1550 #define PNG_FP_SAW_DOT   16  /* Saw a dot in current state */
   1551 #define PNG_FP_SAW_E     32  /* Saw an E (or e) in current state */
   1552 #define PNG_FP_SAW_ANY   60  /* Saw any of the above 4 */
   1553 
   1554 /* These three values don't affect the parser.  They are set but not used.
   1555  */
   1556 #define PNG_FP_WAS_VALID 64  /* Preceding substring is a valid fp number */
   1557 #define PNG_FP_NEGATIVE 128  /* A negative number, including "-0" */
   1558 #define PNG_FP_NONZERO  256  /* A non-zero value */
   1559 #define PNG_FP_STICKY   448  /* The above three flags */
   1560 
   1561 /* This is available for the caller to store in 'state' if required.  Do not
   1562  * call the parser after setting it (the parser sometimes clears it.)
   1563  */
   1564 #define PNG_FP_INVALID  512  /* Available for callers as a distinct value */
   1565 
   1566 /* Result codes for the parser (boolean - true meants ok, false means
   1567  * not ok yet.)
   1568  */
   1569 #define PNG_FP_MAYBE      0  /* The number may be valid in the future */
   1570 #define PNG_FP_OK         1  /* The number is valid */
   1571 
   1572 /* Tests on the sticky non-zero and negative flags.  To pass these checks
   1573  * the state must also indicate that the whole number is valid - this is
   1574  * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this
   1575  * is equivalent to PNG_FP_OK above.)
   1576  */
   1577 #define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO)
   1578    /* NZ_MASK: the string is valid and a non-zero negative value */
   1579 #define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO)
   1580    /* Z MASK: the string is valid and a non-zero value. */
   1581    /* PNG_FP_SAW_DIGIT: the string is valid. */
   1582 #define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT)
   1583 #define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)
   1584 #define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)
   1585 
   1586 /* The actual parser.  This can be called repeatedly, it updates
   1587  * the index into the string and the state variable (which must
   1588  * be initialzed to 0).  It returns a result code, as above.  There
   1589  * is no point calling the parser any more if it fails to advance to
   1590  * the end of the string - it is stuck on an invalid character (or
   1591  * terminated by '\0').
   1592  *
   1593  * Note that the pointer will consume an E or even an E+ then leave
   1594  * a 'maybe' state even though a preceding integer.fraction is valid.
   1595  * The PNG_FP_WAS_VALID flag indicates that a preceding substring was
   1596  * a valid number.  It's possible to recover from this by calling
   1597  * the parser again (from the start, with state 0) but with a string
   1598  * that omits the last character (i.e. set the size to the index of
   1599  * the problem character.)  This has not been tested within libpng.
   1600  */
   1601 PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string,
   1602     png_size_t size, int *statep, png_size_tp whereami));
   1603 
   1604 /* This is the same but it checks a complete string and returns true
   1605  * only if it just contains a floating point number.  As of 1.5.4 this
   1606  * function also returns the state at the end of parsing the number if
   1607  * it was valid (otherwise it returns 0.)  This can be used for testing
   1608  * for negative or zero values using the sticky flag.
   1609  */
   1610 PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string,
   1611     png_size_t size));
   1612 #endif /* pCAL || sCAL */
   1613 
   1614 #if defined(PNG_READ_GAMMA_SUPPORTED) ||\
   1615     defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
   1616 /* Added at libpng version 1.5.0 */
   1617 /* This is a utility to provide a*times/div (rounded) and indicate
   1618  * if there is an overflow.  The result is a boolean - false (0)
   1619  * for overflow, true (1) if no overflow, in which case *res
   1620  * holds the result.
   1621  */
   1622 PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a,
   1623     png_int_32 multiplied_by, png_int_32 divided_by));
   1624 #endif
   1625 
   1626 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
   1627 /* Same deal, but issue a warning on overflow and return 0. */
   1628 PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr,
   1629     png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by));
   1630 #endif
   1631 
   1632 #ifdef PNG_READ_GAMMA_SUPPORTED
   1633 /* Calculate a reciprocal - used for gamma values.  This returns
   1634  * 0 if the argument is 0 in order to maintain an undefined value,
   1635  * there are no warnings.
   1636  */
   1637 PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a));
   1638 
   1639 /* The same but gives a reciprocal of the product of two fixed point
   1640  * values.  Accuracy is suitable for gamma calculations but this is
   1641  * not exact - use png_muldiv for that.
   1642  */
   1643 PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a,
   1644     png_fixed_point b));
   1645 #endif
   1646 
   1647 #ifdef PNG_READ_GAMMA_SUPPORTED
   1648 /* Internal fixed point gamma correction.  These APIs are called as
   1649  * required to convert single values - they don't need to be fast,
   1650  * they are not used when processing image pixel values.
   1651  *
   1652  * While the input is an 'unsigned' value it must actually be the
   1653  * correct bit value - 0..255 or 0..65535 as required.
   1654  */
   1655 PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr,
   1656     unsigned int value, png_fixed_point gamma_value));
   1657 PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value));
   1658 PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value,
   1659     png_fixed_point gamma_value));
   1660 PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value,
   1661     png_fixed_point gamma_value));
   1662 PNG_EXTERN void png_destroy_gamma_table(png_structp png_ptr);
   1663 PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
   1664     int bit_depth));
   1665 #endif
   1666 
   1667 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
   1668 
   1669 #include "pngdebug.h"
   1670 
   1671 #ifdef __cplusplus
   1672 }
   1673 #endif
   1674 
   1675 #endif /* PNGPRIV_H */
   1676