CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/libpng17/pngpriv.h
Views: 1401
1/* pngpriv.h - private declarations for use inside libpng2*3* Last changed in libpng 1.7.0 [(PENDING RELEASE)]4* Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson5* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)6* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)7*8* This code is released under the libpng license.9* For conditions of distribution and use, see the disclaimer10* and license in png.h11*/1213/* The symbols declared in this file (including the functions declared14* as extern) are PRIVATE. They are not part of the libpng public15* interface, and are not recommended for use by regular applications.16* Some of them may become public in the future; others may stay private,17* change in an incompatible way, or even disappear.18* Although the libpng users are not forbidden to include this header,19* they should be well aware of the issues that may arise from doing so.20*/2122#ifndef PNGPRIV_H23#define PNGPRIV_H2425/* Feature Test Macros. The following are defined here to ensure that correctly26* implemented libraries reveal the APIs libpng needs to build and hide those27* that are not needed and potentially damaging to the compilation.28*29* Feature Test Macros must be defined before any system header is included (see30* POSIX 1003.1 2.8.2 "POSIX Symbols."31*32* These macros only have an effect if the operating system supports either33* POSIX 1003.1 or C99, or both. On other operating systems (particularly34* Windows/Visual Studio) there is no effect; the OS specific tests below are35* still required (as of 2011-05-02.)36*/37#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */3839#ifndef PNG_VERSION_INFO_ONLY40/* Keep standard libraries at the top of this file */4142/* Standard library headers not required by png.h: */43# include <stdlib.h>44# include <string.h>4546/* For headers only required with some build configurations see the lines after47* pnglibconf.h is included!48*/4950#endif /* VERSION_INFO_ONLY */5152#define PNGLIB_BUILD /*libpng is being built, not used*/5354/* If HAVE_CONFIG_H is defined during the build then the build system must55* provide an appropriate "config.h" file on the include path. The header file56* must provide definitions as required below (search for "HAVE_CONFIG_H");57* see configure.ac for more details of the requirements. The macro58* "PNG_NO_CONFIG_H" is provided for maintainers to test for dependencies on59* 'configure'; define this macro to prevent the configure build including the60* configure generated config.h. Libpng is expected to compile without *any*61* special build system support on a reasonably ANSI-C compliant system.62*/63#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)64# include <config.h>6566/* Pick up the definition of 'restrict' from config.h if it was read: */67# define PNG_RESTRICT restrict68#endif6970/* To support symbol prefixing it is necessary to know *before* including png.h71* whether the fixed point (and maybe other) APIs are exported, because if they72* are not internal definitions may be required. This is handled below just73* before png.h is included, but load the configuration now if it is available.74*/75#ifndef PNGLCONF_H76# include "pnglibconf.h"77#endif7879/* Local renames may change non-exported API functions from png.h */80#if defined(PNG_PREFIX) && !defined(PNGPREFIX_H)81# include "pngprefix.h"82#endif8384#ifdef PNG_USER_CONFIG85# include "pngusr.h"86/* These should have been defined in pngusr.h */87# ifndef PNG_USER_PRIVATEBUILD88# define PNG_USER_PRIVATEBUILD "Custom libpng build"89# endif90# ifndef PNG_USER_DLLFNAME_POSTFIX91# define PNG_USER_DLLFNAME_POSTFIX "Cb"92# endif93#endif9495#ifndef PNG_VERSION_INFO_ONLY96/* Additional standard libaries required in certain cases, put only standard97* ANSI-C89 headers here. If not available, or non-functional, the problem98* should be fixed by writing a wrapper for the header and the file on your99* include path.100*/101#if defined(PNG_sCAL_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)102/* png.c requires the following ANSI-C constants if the conversion of103* floating point to ASCII is implemented therein:104*105* DBL_MIN_10_EXP Minimum negative integer such that 10^integer is a106* normalized (double) value.107* DBL_DIG Maximum number of decimal digits (can be set to any constant)108* DBL_MIN Smallest normalized fp number (can be set to an arbitrary value)109* DBL_MAX Maximum floating point number (can be set to an arbitrary value)110*/111# include <float.h>112#endif /* sCAL && FLOATING_POINT */113114#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) ||\115defined(PNG_FLOATING_POINT_SUPPORTED)116/* ANSI-C90 math functions are required. Full compliance with the standard117* is probably not a requirement, but the functions must exist and be118* declared in <math.h>119*/120# include <math.h>121#endif /* FLOATING_ARITHMETIC || FLOATING_POINT */122123#endif /* VERSION_INFO_ONLY */124125/* Is this a build of a DLL where compilation of the object modules requires126* different preprocessor settings to those required for a simple library? If127* so PNG_BUILD_DLL must be set.128*129* If libpng is used inside a DLL but that DLL does not export the libpng APIs130* PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a131* static library of libpng then link the DLL against that.132*/133#ifndef PNG_BUILD_DLL134# ifdef DLL_EXPORT135/* This is set by libtool when files are compiled for a DLL; libtool136* always compiles twice, even on systems where it isn't necessary. Set137* PNG_BUILD_DLL in case it is necessary:138*/139# define PNG_BUILD_DLL140# else141# ifdef _WINDLL142/* This is set by the Microsoft Visual Studio IDE in projects that143* build a DLL. It can't easily be removed from those projects (it144* isn't visible in the Visual Studio UI) so it is a fairly reliable145* indication that PNG_IMPEXP needs to be set to the DLL export146* attributes.147*/148# define PNG_BUILD_DLL149# else150# ifdef __DLL__151/* This is set by the Borland C system when compiling for a DLL152* (as above.)153*/154# define PNG_BUILD_DLL155# else156/* Add additional compiler cases here. */157# endif158# endif159# endif160#endif /* Setting PNG_BUILD_DLL if required */161162/* See pngconf.h for more details: the builder of the library may set this on163* the command line to the right thing for the specific compilation system or it164* may be automagically set above (at present we know of no system where it does165* need to be set on the command line.)166*167* PNG_IMPEXP must be set here when building the library to prevent pngconf.h168* setting it to the "import" setting for a DLL build.169*/170#ifndef PNG_IMPEXP171# ifdef PNG_BUILD_DLL172# define PNG_IMPEXP PNG_DLL_EXPORT173# else174/* Not building a DLL, or the DLL doesn't require specific export175* definitions.176*/177# define PNG_IMPEXP178# endif179#endif180181/* No warnings for private or deprecated functions in the build: */182#ifndef PNG_DEPRECATED183# define PNG_DEPRECATED184#endif185#ifndef PNG_PRIVATE186# define PNG_PRIVATE187#endif188189/* Symbol preprocessing support.190*191* To enable listing global, but internal, symbols the following macros should192* always be used to declare an extern data or function object in this file.193*/194#ifndef PNG_INTERNAL_DATA195# define PNG_INTERNAL_DATA(type, name, array) extern type name array196#endif197198#ifndef PNG_INTERNAL_FUNCTION199# define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\200extern PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)201#endif202203#ifndef PNG_INTERNAL_CALLBACK204# define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\205extern PNG_FUNCTION(type, (PNGCBAPI name), args, PNG_EMPTY attributes)206#endif207208/* If floating or fixed point APIs are disabled they may still be compiled209* internally. To handle this make sure they are declared as the appropriate210* internal extern function (otherwise the symbol prefixing stuff won't work and211* the functions will be used without definitions.)212*213* NOTE: although all the API functions are declared here they are not all214* actually built! Because the declarations are still made it is necessary to215* fake out types that they depend on.216*/217#ifndef PNG_FP_EXPORT218# ifndef PNG_FLOATING_POINT_SUPPORTED219# define PNG_FP_EXPORT(ordinal, type, name, args)\220PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);221# ifndef PNG_VERSION_INFO_ONLY222typedef struct png_incomplete png_double;223typedef png_double* png_doublep;224typedef const png_double* png_const_doublep;225typedef png_double** png_doublepp;226# endif227# endif228#endif229#ifndef PNG_FIXED_EXPORT230# ifndef PNG_FIXED_POINT_SUPPORTED231# define PNG_FIXED_EXPORT(ordinal, type, name, args)\232PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);233# endif234#endif235236/* Include png.h here to get the version info and other macros, pngstruct.h and237* pnginfo.h are included later under the protection of !PNG_VERSION_INFO_ONLY238*/239#include "png.h"240241/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */242#ifndef PNG_DLL_EXPORT243# define PNG_DLL_EXPORT244#endif245246/* This is a global switch to set the compilation for an installed system247* (a release build). It can be set for testing debug builds to ensure that248* they will compile when the build type is switched to RC or STABLE, the249* default is just to use PNG_LIBPNG_BUILD_BASE_TYPE. Set this in CPPFLAGS250* with either:251*252* -DPNG_RELEASE_BUILD Turns on the release compile path253* -DPNG_RELEASE_BUILD=0 Turns it off254* or in your pngusr.h with255* #define PNG_RELEASE_BUILD=1 Turns on the release compile path256* #define PNG_RELEASE_BUILD=0 Turns it off257*/258#ifndef PNG_RELEASE_BUILD259# define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC)260#endif261262/* General purpose macros avoid the need to put #if PNG_RELEASE_BUILD263* macro blocks around function declarations and definitions when the264* parameter number varies. Using these results in slightly cleaner code.265*/266#if PNG_RELEASE_BUILD267# define only_rel(text) text268# define only_deb(text)269# define param_rel(param) param,270# define param_deb(param)271#else272# define only_rel(text)273# define only_deb(text) text274# define param_rel(param)275# define param_deb(param) param,276#endif277278/* The affirm mechanism results in a minimal png_error() in released versions279* ('STABLE' versions) and a more descriptive PNG_ABORT in all other cases,280* when the "condition" is false (zero). If "condition" is true (nonzero),281* then the affirm mechanism does nothing.282*283* The PNG_RELEASE_BUILD macro, defined above, controls the behavior of284* 'affirm': if set to 1 affirm will call png_error (or png_err) rather than285* abort. The png_error text is the minimal (file location) text in this case,286* if it is produced. This flag indicates a STABLE (or RC) build.287*288* The macros rely on the naming convention throughout this code - png_ptr289* exists and is of type png_const_structrp or a compatible type - and the290* presence in each file of a uniquely defined macro PNG_SRC_FILE; a number291* indicating which file this is (this is to save space in released versions).292*293* 'affirm' is intended to look like the ANSI-C <assert.h> macro; note that294* this macro can coexist with the assert macro if <assert.h> is295* included.296*297* PNG_SRC_LINE is the position of the affirm macro. There are currently 15298* main source files (4 bits) and the biggest (pngrtran.c) has more than 4095299* lines (12 bits). However, to ensure the number will fit into 16-bits in the300* future and to allow hardware files to use affirm, the encoding is a bit-wise301* encoding based on the current number of lines.302*303* 'debug' is a version of 'affirm' that is completely removed from RELEASE304* builds. This is used when either an unexpected condition is completely305* handled or when it can't be handled even by png_error, for example after a306* memory overwrite.307*308* UNTESTED is used to mark code that has not been tested; it causes an assert309* if the code is executed and (therefore) tested. UNTESTED should not remain310* in release candidate code.311*312* PNG_AFFIRM_TEXT is set to 1 if affirm text should be produced, either313* the minimal text or, if PNG_RELEASE_BUILD is 0, the more verbose text314* including the 'condition' string. This value depends on whether the315* build supports an appropriate way of outputting the message.316*317* Note that PNG_AFFIRM_TEXT is not configurable but is worked out here: this318* is just the affirm code; there's no reason to allow configuration of this319* option.320*/321#if PNG_RELEASE_BUILD ?\322(defined PNG_ERROR_TEXT_SUPPORTED) :\323(defined PNG_WARNINGS_SUPPORTED) || (defined PNG_CONSOLE_IO_SUPPORTED)324# define PNG_AFFIRM_TEXT 1325#else326# define PNG_AFFIRM_TEXT 0327#endif /* PNG_AFFIRM_TEXT definition */328329#define PNG_SRC_LINE (PNG_SRC_FILE + __LINE__)330331/* png_affirmpp and png_impossiblepp are macros to make the correct call to the332* png_affirm function; these macros do not assume that the png_structp is333* called png_ptr.334*/335#if PNG_RELEASE_BUILD336# define png_affirmpp(pp, cond)\337do\338if (!(cond)) png_affirm(pp, PNG_SRC_LINE);\339while (0)340# define png_affirmexp(pp, cond)\341((cond) ? (void)0 : png_affirm(pp, PNG_SRC_LINE))342# define png_handled(pp, m) ((void)0)343# define png_impossiblepp(pp, reason) png_affirm(pp, PNG_SRC_LINE)344345# define debug(cond) do {} while (0)346# define debug_handled(cond) do {} while (0)347# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC348/* Make sure there are no 'UNTESTED' macros in released code: */349# define UNTESTED libpng untested code350# endif351# define NOT_REACHED do {} while (0)352#else353# define png_affirmpp(pp, cond)\354do\355if (!(cond)) png_affirm(pp, #cond, PNG_SRC_LINE);\356while (0)357# define png_affirmexp(pp, cond)\358((cond) ? (void)0 : png_affirm(pp, #cond, PNG_SRC_LINE))359# define png_handled(pp, m) (png_handled_affirm((pp), (m), PNG_SRC_LINE))360# define png_impossiblepp(pp, reason) png_affirm(pp, reason, PNG_SRC_LINE)361362# define debug(cond) png_affirmpp(png_ptr, cond)363# define debug_handled(cond)\364do\365if (!(cond)) png_handled(png_ptr, #cond);\366while (0)367# define UNTESTED png_affirm(png_ptr, "untested code", PNG_SRC_LINE);368# define NOT_REACHED png_affirm(png_ptr, "NOT REACHED", PNG_SRC_LINE)369#endif370371#define affirm(cond) png_affirmpp(png_ptr, cond)372#define affirmexp(cond) png_affirmexp(png_ptr, cond)373#define handled(m) png_handled(png_ptr, (m))374#define impossible(cond) png_impossiblepp(png_ptr, cond)375#define implies(a, b) debug(!(a) || (b))376377/* The defines for PNG_SRC_FILE: */378#define PNG_SRC_FILE_(f,lines) PNG_SRC_FILE_ ## f + lines379380#define PNG_SRC_FILE_png 0381#define PNG_SRC_FILE_pngerror (PNG_SRC_FILE_png +8192)382#define PNG_SRC_FILE_pngget (PNG_SRC_FILE_pngerror +2048)383#define PNG_SRC_FILE_pngmem (PNG_SRC_FILE_pngget +2048)384#define PNG_SRC_FILE_pngpread (PNG_SRC_FILE_pngmem +1024)385#define PNG_SRC_FILE_pngread (PNG_SRC_FILE_pngpread +2048)386#define PNG_SRC_FILE_pngrio (PNG_SRC_FILE_pngread +8192)387#define PNG_SRC_FILE_pngrtran (PNG_SRC_FILE_pngrio +1024)388#define PNG_SRC_FILE_pngrutil (PNG_SRC_FILE_pngrtran +8192)389#define PNG_SRC_FILE_pngset (PNG_SRC_FILE_pngrutil +8192)390#define PNG_SRC_FILE_pngtrans (PNG_SRC_FILE_pngset +2048)391#define PNG_SRC_FILE_pngwio (PNG_SRC_FILE_pngtrans +4096)392#define PNG_SRC_FILE_pngwrite (PNG_SRC_FILE_pngwio +1024)393#define PNG_SRC_FILE_pngwtran (PNG_SRC_FILE_pngwrite +4096)394#define PNG_SRC_FILE_pngwutil (PNG_SRC_FILE_pngwtran +1024)395396#define PNG_SRC_FILE_arm_arm_init (PNG_SRC_FILE_pngwutil +8192)397#define PNG_SRC_FILE_arm_filter_neon_intrinsics\398(PNG_SRC_FILE_arm_arm_init +1024)399400/* Add new files by changing the following line: */401#define PNG_SRC_FILE_LAST (PNG_SRC_FILE_arm_filter_neon_intrinsics +1024)402403/* The following #define must list the files in exactly the same order as404* the above.405*/406#define PNG_FILES\407PNG_apply(png)\408PNG_apply(pngerror)\409PNG_apply(pngget)\410PNG_apply(pngmem)\411PNG_apply(pngpread)\412PNG_apply(pngread)\413PNG_apply(pngrio)\414PNG_apply(pngrtran)\415PNG_apply(pngrutil)\416PNG_apply(pngset)\417PNG_apply(pngtrans)\418PNG_apply(pngwio)\419PNG_apply(pngwrite)\420PNG_apply(pngwtran)\421PNG_apply(pngwutil)\422PNG_apply(arm_arm_init)\423PNG_apply(arm_filter_neon_intrinsics)\424PNG_end425426/* SECURITY and SAFETY:427*428* libpng is built with support for internal limits on image dimensions and429* memory usage. These are documented in scripts/pnglibconf.dfa of the430* source and recorded in the machine generated header file pnglibconf.h.431*/432433/* If you are running on a machine where you cannot allocate more434* than 64K of memory at once, uncomment this. While libpng will not435* normally need that much memory in a chunk (unless you load up a very436* large file), zlib needs to know how big of a chunk it can use, and437* libpng thus makes sure to check any memory allocation to verify it438* will fit into memory.439*440* zlib provides 'MAXSEG_64K' which, if defined, indicates the441* same limit and pngconf.h (already included) sets the limit442* if certain operating systems are detected.443*/444#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)445# define PNG_MAX_MALLOC_64K446#endif447448#ifndef PNG_UNUSED449/* Unused formal parameter warnings are silenced using the following macro450* which is expected to have no bad effects on performance (optimizing451* compilers will probably remove it entirely). Note that if you replace452* it with something other than whitespace, you must include the terminating453* semicolon.454*/455# define PNG_UNUSED(param) (void)param;456#endif457458/* This is a convenience for parameters which are not used in release459* builds.460*/461#define PNG_UNUSEDRC(param) only_rel(PNG_UNUSED(param))462463/* Just a little check that someone hasn't tried to define something464* contradictory.465*/466#if (PNG_ZBUF_SIZE > 32768) && defined(PNG_MAX_MALLOC_64K)467# undef PNG_ZBUF_SIZE468# define PNG_ZBUF_SIZE 32768469#endif470471/* If warnings or errors are turned off the code is disabled or redirected here.472* From 1.5.4 functions have been added to allow very limited formatting of473* error and warning messages - this code will also be disabled here.474*/475#ifdef PNG_WARNINGS_SUPPORTED476# define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;477#else478# define png_warning_parameter(p,number,string) ((void)0)479# define png_warning_parameter_unsigned(p,number,format,value) ((void)0)480# define png_warning_parameter_signed(p,number,format,value) ((void)0)481# define png_formatted_warning(pp,p,message) ((void)(pp))482# define PNG_WARNING_PARAMETERS(p)483#endif484#ifndef PNG_ERROR_TEXT_SUPPORTED485# define png_fixed_error(s1,s2) png_err(s1)486#endif487488/* C allows up-casts from (void*) to any pointer and (const void*) to any489* pointer to a const object. C++ regards this as a type error and requires an490* explicit, static, cast and provides the static_cast<> rune to ensure that491* const is not cast away.492*/493#ifdef __cplusplus494# define png_voidcast(type, value) static_cast<type>(value)495# define png_upcast(type, value) static_cast<type>(value)496# define png_constcast(type, value) const_cast<type>(value)497# define png_aligncast(type, value) \498static_cast<type>(static_cast<void*>(value))499# define png_aligncastconst(type, value) \500static_cast<type>(static_cast<const void*>(value))501#else502# define png_voidcast(type, value) (value)503# define png_upcast(type, value) ((type)(value))504# define png_constcast(type, value) ((type)(value))505# define png_aligncast(type, value) ((void*)(value))506# define png_aligncastconst(type, value) ((const void*)(value))507#endif /* __cplusplus */508509/* Some fixed point APIs are still required even if not exported because510* they get used by the corresponding floating point APIs. This magic511* deals with this:512*/513#ifdef PNG_FIXED_POINT_SUPPORTED514# define PNGFAPI PNGAPI515#else516# define PNGFAPI /* PRIVATE */517#endif518519/* These macros may need to be architecture dependent. */520#define PNG_ALIGN_NONE 0 /* do not use data alignment */521#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */522#ifdef offsetof523# define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */524#else525# define PNG_ALIGN_OFFSET -1 /* prevent the use of this */526#endif527#define PNG_ALIGN_SIZE 3 /* use sizeof to determine alignment */528529#ifndef PNG_ALIGN_TYPE530/* Default to using aligned access optimizations and requiring alignment to a531* multiple of the data type size. Override in a compiler specific fashion532* if necessary by inserting tests here:533*/534# define PNG_ALIGN_TYPE PNG_ALIGN_SIZE535#endif536537#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE538/* This is used because in some compiler implementations non-aligned539* structure members are supported, so the offsetof approach below fails.540* Set PNG_ALIGN_SIZE=0 for compiler combinations where unaligned access541* is good for performance. Do not do this unless you have tested the result542* and understand it.543*/544# define png_alignof(type) (sizeof (type))545#else546# if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET547# define png_alignof(type) offsetof(struct{char c; type t;}, t)548# else549# if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS550# define png_alignof(type) (1)551# endif552/* Else leave png_alignof undefined to prevent use thereof */553# endif554#endif555556/* This implicitly assumes alignment is always to a power of 2. */557#ifdef png_alignof558# define png_isaligned(ptr, type)\559((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0)560#else561# define png_isaligned(ptr, type) 0562#endif563564/* Buffer alignment control. These #defines control how the buffers used during565* read are aligned and how big they are.566*/567#ifndef PNG_ROW_BUFFER_ALIGN_TYPE568/* The absolute minimum alignment for a row buffer is that required for569* png_uint_32 direct access. The #define is of a legal C type that can be570* used as the type in the definition of the first member of a C union; give571* a typedef name if in doubt.572*/573# define PNG_ROW_BUFFER_ALIGN_TYPE png_uint_32574#endif /* !ROW_BUFFER_ALIGN_TYPE */575#ifndef PNG_ROW_BUFFER_BYTE_ALIGN576/* This is the minimum size in bytes of the buffer used while processing577* parts of row. Except at the end of the row pixels will always be578* processed in blocks such that the block size is a multiple of this number579*/580# define PNG_ROW_BUFFER_BYTE_ALIGN\581((unsigned int)/*SAFE*/(sizeof (PNG_ROW_BUFFER_ALIGN_TYPE)))582#endif /* !ROW_BUFFER_BYTE_ALIGN */583#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED584# define PNG_MAX_PIXEL_BYTES 16U /* 4x32-bit channels */585#else /* !READ_USER_TRANSFORM */586# define PNG_MAX_PIXEL_BYTES 8U /* 4x16-bit channels */587#endif /* !READ_USER_TRANSFORM */588/* PNG_ROW_BUFFER_SIZE is a compile time constant for the size of the row589* buffer. The minimum size of 2048 bytes is intended to allow the buffer to590* hold a complete 256 entry color map of 64-bit (8-byte) pixels. This is a591* requirement at some points of the colormap handling code.592*593* The maximum size is intended to allow (unsigned int) indexing of the buffer,594* it only affects systems with a 16-bit unsigned value where it limits the595* maximum to 4096 bytes.596*/597#define PNG_MIN_ROW_BUFFER_SIZE\598(PNG_MAX_PIXEL_BYTES * PNG_ROW_BUFFER_BYTE_ALIGN * 8U)599#define PNG_MAX_ROW_BUFFER_SIZE ((UINT_MAX / 16U) + 1U)600#ifndef PNG_ROW_BUFFER_SIZE601# define PNG_ROW_BUFFER_SIZE\602(PNG_MIN_ROW_BUFFER_SIZE < 2048U ? 2048U : PNG_MIN_ROW_BUFFER_SIZE)603#endif /* ROW_BUFFER_SIZE */604605/* End of memory model/platform independent support */606/* End of 1.5.0beta36 move from pngconf.h */607608/* CONSTANTS and UTILITY MACROS609* These are used internally by libpng and not exposed in the API610*/611612/* Various modes of operation. Note that after an init, mode is set to613* zero automatically when the structure is created. Three of these614* are defined in png.h because they need to be visible to applications615* that call png_set_unknown_chunk().616*/617/* #define PNG_HAVE_IHDR 0x01 (defined as (int) in png.h) */618/* #define PNG_HAVE_PLTE 0x02 (defined as (int) in png.h) */619#define PNG_HAVE_IDAT 0x04U620/* #define PNG_AFTER_IDAT 0x08 (defined as (int) in png.h) */621#define PNG_HAVE_IEND 0x10U622#define PNG_HAVE_PNG_SIGNATURE 0x20U623624#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\625defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)626/* See below for the definitions of the tables used in these macros */627#define PNG_sRGB_FROM_LINEAR(pp, linear) png_check_byte(pp,\628(png_sRGB_base[(linear)>>15] +\629((((linear)&0x7fffU)*png_sRGB_delta[(linear)>>15])>>12)) >> 8)630/* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB631* encoded value with maximum error 0.646365. Note that the input is not a632* 16-bit value; it has been multiplied by 255! */633#endif /* PNG_SIMPLIFIED_READ/WRITE */634635/* Added to libpng-1.6.0: scale a 16-bit value in the range 0..65535 to 0..255636* by dividing by 257 *with rounding*. This macro is exact for the given range.637* See the discourse in pngrtran.c png_do_scale_16_to_8. The values in the638* macro were established by experiment (modifying the added value). The macro639* has a second variant that takes a value already scaled by 255 and divides by640* 65535 - this has a maximum error of .502. Over the range 0..65535*65535 it641* only gives off-by-one errors and only for 0.5% (1 in 200) of the values.642*/643#define PNG_DIV65535(v24) (((v24) + 32895U) >> 16)644#define PNG_DIV257(v16) PNG_DIV65535((png_uint_32)(v16) * 255U)645646/* Added to libpng-1.2.6 JB647* Modified in libpng-1.7.0 to avoid the intermediate calculation overflow648* when:649*650* pixel_bits == 4: any width over 0x3FFFFFFEU overflows651* pixel_bits == 2: any width over 0x7FFFFFFCU overflows652*653* In both these cases any width results in a rowbytes that fits in 32 bits.654* The problem arose in previous versions because the calculation used was655* simply ((width x pixel-bit-depth)+7)/8. At the cost of more calculations656* on pixel_depth this avoids the problem.657*/658#define PNG_SHIFTOF(pixel_bits/*<8*/) \659( (pixel_bits) == 1 ? 3 : \660( (pixel_bits) == 2 ? 2 : \661( (pixel_bits) == 4 ? 1 : \6620/*force bytes*/ ) ) )663#define PNG_ADDOF(pixel_bits/*<8*/) ((1U<<PNG_SHIFTOF(pixel_bits))-1)664#define PNG_ROWBYTES(pixel_bits, width) \665((pixel_bits) >= 8 ? \666((png_alloc_size_t)(width) * ((pixel_bits) >> 3)) : \667(((png_alloc_size_t)(width) + PNG_ADDOF(pixel_bits)) >> \668PNG_SHIFTOF(pixel_bits)) )669670/* This macros, added in 1.7.0, makes it easy to deduce the number of channels671* and therefore the pixel depth from the color type. The PNG specification672* numbers are used in preference to the png.h constants to make it more clear673* why the macro works.674*/675#define PNG_COLOR_TYPE_CHANNELS(ct)\676(((ct) & PNG_COLOR_MASK_PALETTE) ?\6771U : 1U+((ct) & 2U/*COLOR*/)+(((ct)>>2)&1U/*ALPHA*/))678#define PNG_CHANNELS(ps) PNG_COLOR_TYPE_CHANNELS((ps).color_type)679#define PNG_PIXEL_DEPTH(ps) (PNG_CHANNELS(ps) * (ps).bit_depth)680681/* PNG_OUT_OF_RANGE returns true if value is outside the range682* ideal-delta..ideal+delta. Each argument is evaluated twice.683* "ideal" and "delta" should be constants, normally simple684* integers, "value" a variable. Added to libpng-1.2.6 JB685*/686#define PNG_OUT_OF_RANGE(value, ideal, delta) \687( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )688689/* Handling of bit-field masks. Because the expression:690*691* bit_field & ~mask692*693* has implementation defined behavior in ANSI C-90 for many (int) values of694* 'mask' and because some of these are defined in png.h and passed in (int)695* parameters use of '~' has been expunged in libpng 1.7 and replaced by this696* macro, which is well defined in ANSI C-90 (there is a similar, 16-bit,697* version in pngstruct.h for the colorspace flags.)698*/699#define PNG_BIC_MASK(flags) (0xFFFFFFFFU - (flags))700701/* Conversions between fixed and floating point, only defined if702* required (to make sure the code doesn't accidentally use float703* when it is supposedly disabled.)704*/705#ifdef PNG_FLOATING_POINT_SUPPORTED706/* The floating point conversion can't overflow, though it can and707* does lose accuracy relative to the original fixed point value.708* In practice this doesn't matter because png_fixed_point only709* stores numbers with very low precision. The png_ptr and s710* arguments are unused by default but are there in case error711* checking becomes a requirement.712*/713#define png_float(png_ptr, fixed, s) (.00001 * (fixed))714715/* The fixed point conversion performs range checking and evaluates716* its argument multiple times, so must be used with care. The717* range checking uses the PNG specification values for a signed718* 32 bit fixed point value except that the values are deliberately719* rounded-to-zero to an integral value - 21474 (21474.83 is roughly720* (2^31-1) * 100000). 's' is a string that describes the value being721* converted.722*723* NOTE: this macro will raise a png_error if the range check fails,724* therefore it is normally only appropriate to use this on values725* that come from API calls or other sources where an out of range726* error indicates a programming error, not a data error!727*728* NOTE: by default this is off - the macro is not used - because the729* function call saves a lot of code.730*/731#ifdef PNG_FIXED_POINT_MACRO_SUPPORTED732#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\733((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))734#endif735/* else the corresponding function is defined below, inside the scope of the736* cplusplus test.737*/738#endif739740/* Gamma values (new at libpng-1.5.4): */741#define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */742#define PNG_GAMMA_MAC_INVERSE 65909743#define PNG_GAMMA_sRGB_INVERSE 45455744745/* Almost everything below is C specific; the #defines above can be used in746* non-C code (so long as it is C-preprocessed) the rest of this stuff cannot.747*/748#ifndef PNG_VERSION_INFO_ONLY749750#include "pngstruct.h"751#include "pnginfo.h"752753/* Validate the include paths - the include path used to generate pnglibconf.h754* must match that used in the build, or we must be using pnglibconf.h.prebuilt:755*/756#if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM757# error ZLIB_VERNUM != PNG_ZLIB_VERNUM \758"-I (include path) error: see the notes in pngpriv.h"759/* This means that when pnglibconf.h was built the copy of zlib.h that it760* used is not the same as the one being used here. Because the build of761* libpng makes decisions to use inflateInit2 and inflateReset2 based on the762* zlib version number and because this affects handling of certain broken763* PNG files the -I directives must match.764*765* The most likely explanation is that you passed a -I in CFLAGS. This will766* not work; all the preprocessor directories and in particular all the -I767* directives must be in CPPFLAGS.768*/769#endif770771/* This is used for 16 bit gamma tables -- only the top level pointers are772* const; this could be changed:773*/774typedef const png_uint_16p * png_const_uint_16pp;775776/* Added to libpng-1.5.7: sRGB conversion tables */777#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\778defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)779#ifdef PNG_SIMPLIFIED_READ_SUPPORTED780PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]);781/* Convert from an sRGB encoded value 0..255 to a 16-bit linear value,782* 0..65535. This table gives the closest 16-bit answers (no errors).783*/784#endif785786PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_base, [512]);787PNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]);788#endif /* PNG_SIMPLIFIED_READ/WRITE */789790791/* Inhibit C++ name-mangling for libpng functions but not for system calls. */792#ifdef __cplusplus793extern "C" {794#endif /* __cplusplus */795796/* Internal functions; these are not exported from a DLL however because they797* are used within several of the C source files they have to be C extern.798*799* All of these functions must be declared with PNG_INTERNAL_FUNCTION.800*/801/* Affirm handling */802PNG_INTERNAL_FUNCTION(void, png_affirm,(png_const_structrp png_ptr,803param_deb(png_const_charp condition) unsigned int position), PNG_NORETURN);804805#if !PNG_RELEASE_BUILD806PNG_INTERNAL_FUNCTION(void, png_handled_affirm,(png_const_structrp png_ptr,807png_const_charp message, unsigned int position), PNG_EMPTY);808/* This is not marked PNG_NORETURN because in PNG_RELEASE_BUILD it will809* disappear and control will pass through it.810*/811#endif /* !RELEASE_BUILD */812813/* Character/byte range checking. */814/* GCC complains about assignments of an (int) expression to a (char) even when815* it can readily determine that the value is in range. This makes arithmetic816* on (char) or (png_byte) values tedious. The warning is not issued by817* default, but libpng coding rules require no warnings leading to excessive,818* ridiculous and dangerous expressions of the form:819*820* <char> = (char)(expression & 0xff)821*822* They are dangerous because they hide the warning, which might actually be823* valid, and therefore merely enable introduction of undetected overflows when824* code is modified.825*826* The following macros exist to reliably detect any overflow in non-release827* builds. The theory here is that we really want to know about overflows, not828* merely hide a basically flawed compiler warning by throwing unnecessary casts829* into the code. The warnings disappear in RC builds so that the released830* (STABLE) version just assigns the value (with, possibly, a warning if someone831* turns on the -Wconversion GCC warning.)832*833* Doing it this way ensures that the code meets two very important aims:834*835* 1) Overflows are detected in pre-release tests; previously versions of libpng836* have been released that really did have overflows in the RGB calculations.837* 2) In release builds GCC specific operations, which may reduce the ability838* of other compilers and even GCC to optimize the code, are avoided.839*840* There is one important extra consequence for pre-release code; it is841* performing a lot of checks in pixel arithmetic that the release code won't842* perform. As a consequence a build time option, RANGE_CHECK, is provided843* to allow the checks to be turned off in pre-release when building for844* performance testing. This is a standard "_SUPPORTED" option except that it845* cannot be set in the system configuration (pnglibconf.h, pnglibconf.dfa).846*847* A separate macro PNG_BYTE() is provided to safely convert an unsigned value848* to the PNG byte range 0..255. This handles the fact that, technically,849* an ANSI-C (unsigned char), hence a (png_byte), may be able to store values850* outside this range. Note that if you are building on a system where this is851* true libpng is almost certainly going to produce errors; it has never been852* tested on such a system. For the moment pngconf.h ensures that this will853* not happen.854*855* PNG_UINT_16 does the same thing for a 16-bit value passed in an (int) or856* (png_uint_32) (where checking is not expected.)857*/858#if !PNG_RELEASE_BUILD859# ifndef PNG_NO_RANGE_CHECK /* Turn off even in pre-release */860# define PNG_RANGE_CHECK_SUPPORTED861# endif862#endif863864#ifdef PNG_RANGE_CHECK_SUPPORTED865PNG_INTERNAL_FUNCTION(unsigned int, png_bit_affirm,(png_const_structrp png_ptr,866unsigned int position, unsigned int u, unsigned int bits), PNG_EMPTY);867868PNG_INTERNAL_FUNCTION(char, png_char_affirm,(png_const_structrp png_ptr,869unsigned int position, int c), PNG_EMPTY);870871PNG_INTERNAL_FUNCTION(png_byte, png_byte_affirm,(png_const_structrp png_ptr,872unsigned int position, int b), PNG_EMPTY);873874#if INT_MAX >= 65535875PNG_INTERNAL_FUNCTION(png_uint_16, png_u16_affirm,(png_const_structrp png_ptr,876unsigned int position, int u), PNG_EMPTY);877# define png_check_u16(pp, u) (png_u16_affirm((pp), PNG_SRC_LINE, (u)))878#else879/* (int) cannot hold a (png_uint_16) so the above function just won't880* compile correctly, for the moment just do this:881*/882# define png_check_u16(pp, u) (u)883#endif884885# define png_check_bits(pp, u, bits)\886(((1U<<(bits))-1) & png_bit_affirm((pp), PNG_SRC_LINE, (u), (bits)))887# define png_check_char(pp, c) (png_char_affirm((pp), PNG_SRC_LINE, (c)))888# define png_check_byte(pp, b) (png_byte_affirm((pp), PNG_SRC_LINE, (b)))889# define PNG_BYTE(b) ((png_byte)((b) & 0xFFU))890# define PNG_UINT_16(u) ((png_uint_16)((u) & 0xFFFFU))891#elif !(defined PNG_REMOVE_CASTS) /* && !RANGE_CHECK */892# define png_check_bits(pp, u, bits) (((1U<<(bits))-1U) & (u))893# define png_check_char(pp, c) ((char)(c))894# define png_check_byte(pp, b) ((png_byte)(b))895# define png_check_u16(pp, u) ((png_uint_16)(u))896# define PNG_BYTE(b) ((png_byte)((b) & 0xFFU))897# define PNG_UINT_16(u) ((png_uint_16)((u) & 0xFFFFU))898#else /* !RANGE_CHECK */899/* This is somewhat trust-me-it-works: if PNG_REMOVE_CASTS is defined then900* the casts, which might otherwise change the values, are completely901* removed. Use this to test your compiler to see if it makes *any*902* difference (code size or speed.) Currently NOT SUPPORTED.903*904* It also makes the PNG_BYTE and PNG_UINT_16 macros do nothing either905* NOTE: this seems safe at present but might lead to unexpected results906* if someone writes code to depend on the truncation.907*/908# define png_check_bits(pp, u, bits) (u)909# define png_check_char(pp, c) (c)910# define png_check_byte(pp, b) (b)911# define png_check_u16(pp, u) (u)912# define PNG_BYTE(b) (b)913# define PNG_UINT_16(u) (u)914#endif /* RANGE_CHECK */915916/* Safe calculation of a rowbytes value; does a png_error if the system limits917* are exceeded.918*/919PNG_INTERNAL_FUNCTION(png_alloc_size_t,png_calc_rowbytes,920(png_const_structrp png_ptr, unsigned int pixel_depth,921png_uint_32 row_width),PNG_EMPTY);922923/* Common code to calculate the maximum number of pixels to transform or filter924* at one time; controlled by PNG_ROW_BUFFER_SIZE above:925*/926PNG_INTERNAL_FUNCTION(unsigned int,png_max_pixel_block,927(png_const_structrp png_ptr),PNG_EMPTY);928929/* Copy the row in row_buffer; this is the non-interlaced copy used in both the930* read and write code. 'x_in_dest' specifies whether the 'x' applies to931* the destination (sp->dp[x], x_in_dest tru) or the source (sp[x]->dp,932* x_in_dest false).933*/934PNG_INTERNAL_FUNCTION(void, png_copy_row,(png_const_structrp png_ptr,935png_bytep dp, png_const_bytep sp, png_uint_32 x/*in INPUT*/,936png_uint_32 width/*of INPUT*/, unsigned int pixel_depth,937int clear/*clear the final byte*/, int x_in_dest),PNG_EMPTY);938939/* Zlib support */940#define PNG_UNEXPECTED_ZLIB_RETURN (-7)941PNG_INTERNAL_FUNCTION(void, png_zstream_error,(z_stream *zstream, int ret),942PNG_EMPTY);943/* Used by the zlib handling functions to ensure that z_stream::msg is always944* set before they return.945*/946947#if defined(PNG_FLOATING_POINT_SUPPORTED) && \948!defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \949(defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \950defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \951defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \952(defined(PNG_sCAL_SUPPORTED) && \953defined(PNG_FLOATING_ARITHMETIC_SUPPORTED))954PNG_INTERNAL_FUNCTION(png_fixed_point,png_fixed,(png_const_structrp png_ptr,955double fp, png_const_charp text),PNG_EMPTY);956#endif957958/* Internal base allocator - no messages, NULL on failure to allocate. This959* does, however, call the application provided allocator and that could call960* png_error (although that would be a bug in the application implementation.)961*/962PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_base,(png_const_structrp png_ptr,963png_alloc_size_t size),PNG_ALLOCATED);964965#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\966defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)967/* Internal array allocator, outputs no error or warning messages on failure,968* just returns NULL.969*/970PNG_INTERNAL_FUNCTION(png_voidp,png_malloc_array,(png_const_structrp png_ptr,971int nelements, size_t element_size),PNG_ALLOCATED);972973/* The same but an existing array is extended by add_elements. This function974* also memsets the new elements to 0 and copies the old elements. The old975* array is not freed or altered.976*/977PNG_INTERNAL_FUNCTION(png_voidp,png_realloc_array,(png_structrp png_ptr,978png_const_voidp array, int old_elements, int add_elements,979size_t element_size),PNG_ALLOCATED);980#endif /* text, sPLT or unknown chunks */981982/* Magic to create a struct when there is no struct to call the user supplied983* memory allocators. Because error handling has not been set up the memory984* handlers can't safely call png_error, but this is an obscure and undocumented985* restriction so libpng has to assume that the 'free' handler, at least, might986* call png_error.987*/988PNG_INTERNAL_FUNCTION(png_structp,png_create_png_struct,989(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,990png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn,991png_free_ptr free_fn),PNG_ALLOCATED);992993/* Free memory from internal libpng struct */994PNG_INTERNAL_FUNCTION(void,png_destroy_png_struct,(png_structrp png_ptr),995PNG_EMPTY);996997/* Free an allocated jmp_buf (always succeeds) */998PNG_INTERNAL_FUNCTION(void,png_free_jmpbuf,(png_structrp png_ptr),PNG_EMPTY);9991000/* Function to allocate memory for zlib. PNGAPI is disallowed. */1001PNG_INTERNAL_FUNCTION(voidpf,png_zalloc,(voidpf png_ptr, uInt items, uInt size),1002PNG_ALLOCATED);10031004/* Function to free memory for zlib. PNGAPI is disallowed. */1005PNG_INTERNAL_FUNCTION(void,png_zfree,(voidpf png_ptr, voidpf ptr),PNG_EMPTY);10061007/* The next three functions are used by png_init_io to set the default1008* implementations for reading or writing to a stdio (png_FILE_p) stream.1009* They can't be static because in 1.7 png_init_io needs to reference them.1010*/1011#ifdef PNG_STDIO_SUPPORTED1012# ifdef PNG_READ_SUPPORTED1013PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_read_data,(png_structp png_ptr,1014png_bytep data, png_size_t length),PNG_EMPTY);1015# endif /* READ */10161017# ifdef PNG_WRITE_SUPPORTED1018PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_write_data,(png_structp png_ptr,1019png_bytep data, png_size_t length),PNG_EMPTY);10201021# ifdef PNG_WRITE_FLUSH_SUPPORTED1022PNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_flush,(png_structp png_ptr),1023PNG_EMPTY);1024# endif /* WRITE_FLUSH */1025# endif /* WRITE */1026#endif /* STDIO */10271028/* Reset the CRC variable. The CRC is initialized with the chunk tag (4 bytes).1029* NOTE: at present png_struct::chunk_name MUST be set before this as well so1030* that png_struct::current_crc is initialized correctly!1031*/1032PNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr,1033png_const_bytep chunk_tag), PNG_EMPTY);10341035/* Write the "data" buffer to whatever output you are using */1036PNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr,1037png_const_voidp data, png_size_t length),PNG_EMPTY);10381039/* Read and check the PNG file signature */1040PNG_INTERNAL_FUNCTION(void,png_read_sig,(png_structrp png_ptr,1041png_inforp info_ptr),PNG_EMPTY);10421043/* Read data from whatever input you are using into the "data" buffer */1044PNG_INTERNAL_FUNCTION(void,png_read_data,(png_structrp png_ptr, png_voidp data,1045png_size_t length),PNG_EMPTY);10461047/* Read bytes into buf, and update png_ptr->crc */1048PNG_INTERNAL_FUNCTION(void,png_crc_read,(png_structrp png_ptr, png_voidp buf,1049png_uint_32 length),PNG_EMPTY);10501051/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */1052PNG_INTERNAL_FUNCTION(int,png_crc_finish,(png_structrp png_ptr,1053png_uint_32 skip),PNG_EMPTY);10541055/* Calculate the CRC over a section of data. Note that we are only1056* passing a maximum of 64K on systems that have this as a memory limit,1057* since this is the maximum buffer size we can specify.1058*/1059PNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr,1060png_const_voidp ptr, png_size_t length),PNG_EMPTY);10611062/* Write various chunks */10631064/* Write the IHDR chunk, and update the png_struct with the necessary1065* information.1066*/1067PNG_INTERNAL_FUNCTION(void,png_write_IHDR,(png_structrp png_ptr,1068png_uint_32 width, png_uint_32 height, int bit_depth, int color_type,1069int compression_method, int filter_method, int interlace_method),PNG_EMPTY);10701071PNG_INTERNAL_FUNCTION(void,png_write_PLTE,(png_structrp png_ptr,1072png_const_colorp palette, unsigned int num_pal),PNG_EMPTY);10731074PNG_INTERNAL_FUNCTION(void,png_write_IEND,(png_structrp png_ptr),PNG_EMPTY);10751076#ifdef PNG_WRITE_gAMA_SUPPORTED1077PNG_INTERNAL_FUNCTION(void,png_write_gAMA_fixed,(png_structrp png_ptr,1078png_fixed_point file_gamma),PNG_EMPTY);1079#endif10801081#ifdef PNG_WRITE_sBIT_SUPPORTED1082PNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,1083png_const_color_8p sbit, int color_type),PNG_EMPTY);1084#endif10851086#ifdef PNG_WRITE_cHRM_SUPPORTED1087PNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,1088const png_xy *xy), PNG_EMPTY);1089/* The xy value must have been previously validated */1090#endif10911092#ifdef PNG_WRITE_sRGB_SUPPORTED1093PNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr,1094int intent),PNG_EMPTY);1095#endif10961097#ifdef PNG_WRITE_iCCP_SUPPORTED1098PNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr,1099png_const_charp name, png_const_voidp profile), PNG_EMPTY);1100/* The profile must have been previously validated for correctness, the1101* length comes from the first four bytes. Only the base, deflate,1102* compression is supported.1103*/1104#endif11051106#ifdef PNG_WRITE_sPLT_SUPPORTED1107PNG_INTERNAL_FUNCTION(void,png_write_sPLT,(png_structrp png_ptr,1108png_const_sPLT_tp palette),PNG_EMPTY);1109#endif11101111#ifdef PNG_WRITE_tRNS_SUPPORTED1112PNG_INTERNAL_FUNCTION(void,png_write_tRNS,(png_structrp png_ptr,1113png_const_bytep trans, png_const_color_16p values, int number,1114int color_type),PNG_EMPTY);1115#endif11161117#ifdef PNG_WRITE_bKGD_SUPPORTED1118PNG_INTERNAL_FUNCTION(void,png_write_bKGD,(png_structrp png_ptr,1119png_const_color_16p values, int color_type),PNG_EMPTY);1120#endif11211122#ifdef PNG_WRITE_hIST_SUPPORTED1123PNG_INTERNAL_FUNCTION(void,png_write_hIST,(png_structrp png_ptr,1124png_const_uint_16p hist, int num_hist),PNG_EMPTY);1125#endif11261127/* Chunks that have keywords */1128#ifdef PNG_WRITE_tEXt_SUPPORTED1129PNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr,1130png_const_charp key, png_const_charp text, png_size_t text_len),PNG_EMPTY);1131#endif11321133#ifdef PNG_WRITE_zTXt_SUPPORTED1134PNG_INTERNAL_FUNCTION(void,png_write_zTXt,(png_structrp png_ptr,1135png_const_charp key, png_const_charp text, int compression),PNG_EMPTY);1136#endif11371138#ifdef PNG_WRITE_iTXt_SUPPORTED1139PNG_INTERNAL_FUNCTION(void,png_write_iTXt,(png_structrp png_ptr,1140int compression, png_const_charp key, png_const_charp lang,1141png_const_charp lang_key, png_const_charp text),PNG_EMPTY);1142#endif11431144#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */1145PNG_INTERNAL_FUNCTION(int,png_set_text_2,(png_structrp png_ptr,1146png_inforp info_ptr, png_const_textp text_ptr, int num_text),PNG_EMPTY);1147#endif11481149#ifdef PNG_WRITE_oFFs_SUPPORTED1150PNG_INTERNAL_FUNCTION(void,png_write_oFFs,(png_structrp png_ptr,1151png_int_32 x_offset, png_int_32 y_offset, int unit_type),PNG_EMPTY);1152#endif11531154#ifdef PNG_WRITE_pCAL_SUPPORTED1155PNG_INTERNAL_FUNCTION(void,png_write_pCAL,(png_structrp png_ptr,1156png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,1157png_const_charp units, png_charpp params),PNG_EMPTY);1158#endif11591160#ifdef PNG_WRITE_pHYs_SUPPORTED1161PNG_INTERNAL_FUNCTION(void,png_write_pHYs,(png_structrp png_ptr,1162png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,1163int unit_type),PNG_EMPTY);1164#endif11651166#ifdef PNG_WRITE_tIME_SUPPORTED1167PNG_INTERNAL_FUNCTION(void,png_write_tIME,(png_structrp png_ptr,1168png_const_timep mod_time),PNG_EMPTY);1169#endif11701171#ifdef PNG_WRITE_sCAL_SUPPORTED1172PNG_INTERNAL_FUNCTION(void,png_write_sCAL_s,(png_structrp png_ptr,1173int unit, png_const_charp width, png_const_charp height),PNG_EMPTY);1174#endif11751176#ifdef PNG_WRITE_SUPPORTED1177PNG_INTERNAL_FUNCTION(void,png_write_start_IDAT,(png_structrp png_ptr),1178PNG_EMPTY);1179/* Do any required initialization before IDAT or row processing starts. */11801181/* Choose the best filter to use and filter the row data then write it out. If1182* WRITE_FILTERING is not supported this just writes the data out with a zero1183* (NONE) filter byte.1184*1185* This may be called multiple times per row, but calls must be in 'x' order;1186* first a call with x 0 to mark the start of the row and, at the end, one with1187* PNG_ROW_END set (this can be done in the same function call if the whole row1188* is passed.) The following flags are used internally to control pass1189* filtering and deflate:1190*/1191enum1192{1193png_pass_last =0x1U, /* This is the last pass in the image */1194png_pass_last_row =0x2U, /* This is the last row in a pass */1195png_pass_first_row =0x4U, /* This is the first row in a pass */1196png_row_end =0x8U, /* This is the last block in the row */1197png_no_row_info =0x0U /* Placeholder */11981199/* A useful macro; return true if this is the last block of the last row in1200* the image.1201*/1202# define PNG_IDAT_END(f) (((f) & ~png_pass_first_row) == \1203(png_row_end+png_pass_last_row+png_pass_last))1204};1205PNG_INTERNAL_FUNCTION(void,png_write_png_data,(png_structrp png_ptr,1206png_bytep prev_pixels, png_const_bytep unfiltered_row, png_uint_32 x,1207unsigned int width/*pixels*/, unsigned int row_info_flags),1208PNG_EMPTY);12091210PNG_INTERNAL_FUNCTION(void,png_write_png_rows,(png_structrp png_ptr,1211png_const_bytep *rows, png_uint_32 num_rows), PNG_EMPTY);1212/* As above but rows[num_rows] of correctly (PNG) formated but unfiltered1213* data are passed in. For an interlaced image the rows will be interlaced1214* rows and therefore may be narrower than the image width.1215*1216* This function advances png_structp::pass and png_structp::row_number as1217* required.1218*/12191220/* Release memory used by the deflate mechanism */1221PNG_INTERNAL_FUNCTION(void, png_deflate_destroy, (png_structp png_ptr),1222PNG_EMPTY);1223#endif /* WRITE */12241225#ifdef PNG_TRANSFORM_MECH_SUPPORTED1226PNG_INTERNAL_FUNCTION(void,png_transform_free,(png_const_structrp png_ptr,1227png_transformp *list),PNG_EMPTY);1228/* Free the entire transform list, from the given point on. the argument is1229* set to NULL.1230*/12311232PNG_INTERNAL_FUNCTION(void,png_init_transform_control,(1233png_transform_controlp out, png_structp png_ptr),PNG_EMPTY);1234/* Initialize a transform control for running the transform list forward (the1235* read case, and write initialization, but the write case is called within1236* pngtrans.c by the above function.)1237*/12381239#ifdef PNG_READ_TRANSFORMS_SUPPORTED1240PNG_INTERNAL_FUNCTION(unsigned int,png_run_this_transform_list_forwards,1241(png_transform_controlp tc, png_transformp *start, png_transformp end),1242PNG_EMPTY);1243/* Used by the transform cache code to run a sub-list, from *start to the1244* transform end.1245*/1246#endif /* READ_TRANSFORMS */12471248#ifdef PNG_READ_SUPPORTED1249PNG_INTERNAL_FUNCTION(unsigned int,png_run_transform_list_forwards,1250(png_structp png_ptr, png_transform_controlp tc),PNG_EMPTY);1251/* Run the transform list in the forwards direction (from PNG format to1252* memory format). The transform control must be initialized completely by1253* the caller. This function takes account of transforms which delete1254* themselves during the run; it must be used.1255*/1256#endif /* READ */12571258#ifdef PNG_WRITE_SUPPORTED1259PNG_INTERNAL_FUNCTION(void,png_run_transform_list_backwards,1260(png_structp png_ptr, png_transform_controlp tc),PNG_EMPTY);1261/* Run the transform list in the backwards direction (from memory format to1262* PNG format). The transform control must be initialized completely by1263* the caller. This function takes account of transforms which delete1264* themselves during the run; it must be used.1265*/1266#endif /* WRITE */12671268PNG_INTERNAL_FUNCTION(png_transformp,png_add_transform,(png_structrp png_ptr,1269size_t size, png_transform_fn fn, unsigned int order),PNG_EMPTY);1270/* Add a transform, using the information in 'order' to control the position1271* of the transform in the list, returning a pointer to the transform. The1272* top 8 bits of 'order' control the position in the list. If a transform1273* does not already exist in the list with the given value a new transform1274* will be created and 'fn' and 'order' set. If there is a transform with1275* that value 'fn' must match and 'order' will be updated by combining the1276* new value in with a bitwise or (|). It is up to the function (fn) or the1277* caller of png_add_transform to determine whether the combination is valid.1278*1279* 'size' is used when creating a new transform, it may be larger than1280* (sizeof png_transform) if required to accomodate extra data.1281*1282* Prior to 1.7.0 transforms were executed in an order hard-wired into the1283* code that executed the transform functions. This was summarized in the1284* read case by the following comment from pngrtran.c1285* (png_init_read_transformations), note that this has been marked up to1286* indicate which PNG formats the transforms in the list apply to:1287*1288* *: applies to most formats1289* A: only formats with alpha1290* L: only low-bit-depth (less than 8 bits per component/pixel)1291* H: only high-bit-depth (16-bits per component)1292*1293> From the code of png_do_read_transformations the order is:1294*1295* GGRR For example column: . no action1296* AGG r acts on read1297* BB w acts on write1298* A B acts on both read and write1299>1300> r.r. 1) PNG_EXPAND (including PNG_EXPAND_tRNS)1301> .r.r 2) PNG_STRIP_ALPHA (if no compose)1302> ..rr 3) PNG_RGB_TO_GRAY1303> rr.. 4) PNG_GRAY_TO_RGB iff !PNG_FLAG_BACKGROUND_IS_GRAY1304> rrrr 5) PNG_COMPOSE1305> rrrr 6) PNG_GAMMA1306> .r.r 7) PNG_STRIP_ALPHA (if compose)1307> .r.r 8) PNG_ENCODE_ALPHA1308> rrrr 9) PNG_SCALE_16_TO_81309> rrrr 10) PNG_16_TO_81310> ..rr 11) PNG_QUANTIZE (converts to palette)1311> rrrr 12) PNG_EXPAND_161312> rr.. 13) PNG_GRAY_TO_RGB iff PNG_FLAG_BACKGROUND_IS_GRAY1313> BB.. 14) PNG_INVERT_MONO1314> .B.B 15) PNG_INVERT_ALPHA1315> BBBB 16) PNG_SHIFT1316*1317* Note that transforms from this point on are used in 1.7.0 on palette1318* indices as well; a png_set_pack request (for example) packs the palette1319* index values if the output will be palettized and the grayscale values1320* if it will not be (if the output is low-bit-grayscale, not palette.)1321*1322> B... 17) PNG_PACK1323> ..BB 18) PNG_BGR1324> B... 19) PNG_PACKSWAP1325> rwrw 20) PNG_FILLER (includes PNG_ADD_ALPHA)1326> .B.B 21) PNG_SWAP_ALPHA1327> BBBB 22) PNG_SWAP_BYTES1328> BBBB 23) PNG_USER_TRANSFORM [must be last]1329*1330* Finally, outside the set of transforms prior to 1.7.0, the libpng1331* interlace handling required the pixels to be replicated to match the pixel1332* spacing in the image row; the first part the pre-1.7.0 interlace support,1333* this is still the case when reading, but for writing the interlace is now1334* a transform:1335*1336> BBBB 24) png_do_{read,write}_interlace (interlaced images only).1337*1338* First transforms are grouped according to basic function using the top 31339* bits of the order code:1340*/1341# define PNG_TR_START 0x0000U /* initial ops on the PNG data */1342# define PNG_TR_ARITHMETIC 0x2000U /* arithmetic linear operations */1343# define PNG_TR_CHANNEL 0x4000U /* PNG conformant format changes */1344# define PNG_TR_QUANTIZE 0x6000U /* quantize and following operations */1345# define PNG_TR_ENCODING 0x8000U /* Row encoding transforms */1346# define PNG_TR_INTERLACE 0xA000U /* write interlace transform */1347/*1348* In libpng 1.7.0 the check on palette index values is moved to the start1349* (of read, end of write, which is where it was before) immediately after1350* the MNG filter handling1351*/1352# define PNG_TR_MNG_INTRAPIXEL (PNG_TR_START + 0x0100U)1353/* Perform intra-pixel differencing (write) or un-differencing on read. */1354# define PNG_TR_CHECK_PALETTE (PNG_TR_START + 0x0200U)1355/* Done before at the start on read, at the end on write to give a1356* consistent postion:1357*1358* PNG_RWTR_CHECK_PALETTE PI W11: happens in pngwrite.c last1359*/1360# define PNG_TR_START_CACHE (PNG_TR_START + 0x0300U)1361/* Not used on a transform; this is just a marker for the point at which1362* palette or low-bit-depth caching can start on read. (The previous1363* operations cannot be cached).1364*/1365# define PNG_TR_INIT_ALPHA (PNG_TR_START + 0x0400U)1366/* This just handles alpha/tRNS initialization issues to resolve the1367* inter-dependencies with tRNS expansion and background composition; it1368* doesn't do anything itself, just sets flags and pushes transforms.1369*/1370/*1371* Prior to 1.7 the arithmetic operations interleaved with the RGB-to-gray1372* and alpha strip byte level ops. This was done to reduce the amount of1373* data processed, i.e. it was an optimization not a requirement. These1374* operations were preceded by the 'expand' operations, which is the1375* opposite; it was done to simplify the code and actually slows things down1376* in the low bit depth gray case. The full list of operations after expand,1377* in the 1.6 order, is:1378*1379* PNG_TR_STRIP_ALPHA png_do_strip_channel (sometimes)1380* PNG_TR_RGB_TO_GRAY png_do_rgb_to_gray1381* PNG_TR_GRAY_TO_RGB png_do_gray_to_rgb (sometimes)1382* PNG_TR_COMPOSE png_do_compose1383* PNG_TR_GAMMA png_do_gamma (if no RGB_TO_GRAY)1384* PNG_TR_STRIP_ALPHA png_do_strip_channel (other times)1385* PNG_TR_ENCODE_ALPHA png_do_encode_alpha1386*1387* In 1.7 the operations are moved round somewhat, including moving alpha and1388* 16-to-8 bit reduction later. This leaves the following operations:1389*1390* PNG_TR_RGB_TO_GRAY png_do_rgb_to_gray1391* PNG_TR_COMPOSE png_do_compose1392* PNG_TR_GAMMA png_do_gamma (if no RGB_TO_GRAY)1393* PNG_TR_ENCODE_ALPHA png_do_encode_alpha1394*1395* Prior to 1.7 some combinations of transforms would do gamma correction1396* twice, the actual implementation in 1.7 is to use the following order and1397* rely on the cache code to optimize gray 1,2,4,8 and (of course) palette.1398*/1399# define PNG_TR_COMPOSE (PNG_TR_ARITHMETIC + 0x0100U)1400/* Handle background composition. This may need to push a gray-to-rgb1401* transform if the background is RGB for gray input. This precedes RGB1402* to gray convertion so that it can handle tRNS appropriately when the1403* background is in the PNG encoding however, typically, the processing1404* happens at PNG_TR_COMPOSE_ALPHA below.1405*1406* NOTE: this must be the first arithmetic transform because the code in1407* png_init_background relies on png_transform_control::gamma being the1408* original PNG gamma.1409*/1410# define PNG_TR_RGB_TO_GRAY (PNG_TR_ARITHMETIC + 0x0200U) /* to gray */1411/* Convert any RGB input (8/16 bit depth, RGB, RGBA) to linear gray1412* 16-bit. This happens first because it cannot be cached; the input data1413* has 24 or 48 bits of uncorrelated data so the transform has to happen1414* pixel-by-pixel. Internally the transform may maintain an 8 or 16-bit1415* gamma correction table (to 16-bit linear) to speed things up.1416*1417* NOTE: this transform must follow PNG_TR_COMPOSE with no intervening1418* transforms; see the code in png_init_background (pngrtran.c) which1419* relies on this during PNG_TC_INIT_FORMAT.1420*/1421# define PNG_TR_COMPOSE_ALPHA (PNG_TR_ARITHMETIC + 0x0300U)1422/* Compose alpha composition and tRNS handling when the background is a1423* screen color. Pushed by PNG_TR_COMPOSE as required.1424*/1425# define PNG_TR_GAMMA_ENCODE (PNG_TR_ARITHMETIC + 0x1F00U) /* last */1426/* Gamma encode the input. This encodes the gray or RGB channels to the1427* required bit depth and either scales the alpha channel or encodes it as1428* well, depending on the requested alpha encoding.1429*/1430/*1431* The 'expand' operations come after the arithmetic ones in libpng 1.7, this1432* forces the arithmetic stuff to do the expand, but since arithmetic is (in1433* 1.7) normally done in 16-bit linear this avoids spurious expands.1434*/1435# define PNG_TR_EXPAND (PNG_TR_CHANNEL + 0x0100U)1436/* Includes:1437*1438* PNG_TR_EXPAND_PALETTE palette images only, includes tRNS1439* PNG_TR_EXPAND_LBP_GRAY grayscale low-bit depth only1440* PNG_TR_EXPAND_tRNS non-palette images only1441*/1442# define PNG_TR_SCALE_16_TO_8 (PNG_TR_CHANNEL + 0x0200U)1443/* Comes after the expand and before the chop version; note that it works on1444* the pixel values directly, so it is a linear transform on a non-linear1445* value.1446*/1447/*1448* To handle transforms that affect the palette entries, not the palette1449* indices in the row data, libpng 1.7 reorders some of the post-quantize1450* transformations to put all the "PC" transforms ahead of all the "PI"1451* transforms. The "PC" transforms that came after png_do_quantize in libpng1452* 1.6 cannot be ordered to be before so they are included in the1453* PNG_TR_QUANTIZE section. The PI transforms are all in PNG_TR_ENCODING,1454* PNG_GRAY_TO_RGB is moved before PNG_TR_QUANTIZE to avoid the unpredictable1455* behavior of png_set_quantize that otherwise arises.1456*1457* The transforms in the PNG_TR_QUANTIZE section are:1458*1459* PNG_TR_EXPAND_16 !P !W1460* PNG_RWTR_INVERT_MONO !P W10: invert the gray channel1461* PNG_RWTR_INVERT_ALPHA PC W8: invert the alpha channel1462* PNG_RWTR_SHIFT PC W6: read: down, write: scale up1463* PNG_RWTR_BGR !P W91464* PNG_RWTR_FILLER !P W2: add on R, remove on W1465* PNG_RWTR_SWAP_ALPHA !P W71466* PNG_RWTR_SWAP_16 !P W51467*1468* The ones in PNG_TR_ENCODING are:1469*1470* PNG_RWTR_PACK PI W4: R: unpack bytes, W: pack1471* PNG_RWTR_PIXEL_SWAP PI W3: Swap pixels in a byte1472* PNG_RWTR_USER PI W11473*/14741475# define PNG_TR_CHANNEL_PREQ (PNG_TR_CHANNEL + 0x1F00U)1476/* The channel swap transforms that must happen before PNG_TR_QUANTIZE:1477*1478* PNG_TR_STRIP_ALPHA1479* PNG_TR_CHOP_16_TO_81480* PNG_TR_GRAY_TO_RGB1481*/1482# define PNG_TR_CHANNEL_POSTQ (PNG_TR_QUANTIZE + 0x0100U)1483/* The post-quantize channel swap transforms:1484*1485* PNG_TR_EXPAND_16 !P !W1486* PNG_RWTR_BGR !P W91487* PNG_RWTR_FILLER !P W2: (filler) add on R, remove on W1488* PNG_RWTR_SWAP_ALPHA !P W71489* PNG_RWTR_SWAP_16 !P W51490*1491* The 'CHANNEL' operation sets the transform_control channel_add flag for1492* use below.1493*/1494# define PNG_TR_INVERT (PNG_TR_QUANTIZE + 0x0200U)1495/* Invert MONO and ALPHA. If the channel_add flag is set in the transform1496* control INVERT_ALPHA will not be done; the png_add_alpha/filler APIs1497* happened after png_set_invert_alpha in earlier versions so the filler1498* value had to include the invert.1499*1500* PNG_RWTR_INVERT_MONO !P W10: invert the gray channel1501* PNG_RWTR_INVERT_ALPHA PC W8: invert the alpha channel1502*/1503# define PNG_TR_SHIFT (PNG_TR_QUANTIZE + 0x0300U)1504/* The channel shift, except that if the channel_add flag has been set the1505* alpha channel is not shifted.1506*1507* PNG_RWTR_SHIFT PC W6: read: down, write: scale up1508*/1509# define PNG_TR_PACK (PNG_TR_ENCODING + 0x0200U)1510/* PNG_RWTR_PACK PI W4: R: unpack bytes, W: pack */1511# define PNG_TR_PIXEL_SWAP (PNG_TR_ENCODING + 0x0300U)1512/* PNG_RWTR_PIXEL_SWAP PI W3: Swap pixels in a byte */1513# define PNG_TR_USER (PNG_TR_ENCODING + 0x1F00U)1514/* The user transform; must be last before the interlace handling because it1515* does unpredictable things to the format.1516*1517* PNG_RWTR_USER PI W11518*/15191520PNG_INTERNAL_FUNCTION(png_transformp,png_push_transform,(png_structrp png_ptr,1521size_t size, png_transform_fn fn, png_transformp *transform,1522png_transform_controlp tc),PNG_EMPTY);1523/* As png_add_transform except that the new transform is inserted ahead of1524* the given transform (*transform). The new transform is returned, but it1525* will also invariably be in *transform. If 'tc' is not NULL the transform1526* callback will also be called; it needs to be called if this function is1527* called while transforms are being run.1528*1529* 'fn' must not be NULL.1530*1531* The transform is inserted with the same 'order' as the passed in1532* *transform, that transform and following transforms are moved up ('order'1533* is incremented) as required to make space. Consequently, unlike with1534* png_add_transform, the transform will always be new. To detect loops1535* (*transform)->fn must not be the same as the passed in 'fn'.1536*/15371538PNG_INTERNAL_FUNCTION(png_voidp,png_transform_cast_check,1539(png_const_structp png_ptr, unsigned int src_line, png_transformp tr,1540size_t size),PNG_EMPTY);1541/* Given a pointer to a transform, 'tr' validate that the underlying derived1542* class has size 'size' using the tr->size field and return the same1543* pointer. If there is a size mismatch the function does an affirm using1544* the given line number.1545*/1546#define png_transform_cast(type, pointer) png_voidcast(type*,\1547png_transform_cast_check(png_ptr, PNG_SRC_LINE, (pointer), sizeof (type)))1548/* This takes a pointer to a transform and safely returns a pointer to a1549* derived transform class (type); type must not have the pointer. It1550* validates the 'size' field. Derived classes start with a png_transform1551* as the first member called 'tr'.1552*/1553#endif /* TRANSFORM_MECH_SUPPORTED */15541555#ifdef PNG_READ_TRANSFORMS_SUPPORTED1556/* Remove a transform from a list, moving the next transform down into1557* *transform.1558*/1559PNG_INTERNAL_FUNCTION(void,png_remove_transform,(png_const_structp png_ptr,1560png_transformp *transform),PNG_EMPTY);15611562/* Initializer for read transforms that handles caching, palette update and1563* palette expansion.1564*/1565PNG_INTERNAL_FUNCTION(unsigned int,png_read_init_transform_mech,1566(png_structp png_ptr, png_transform_control *tc),PNG_EMPTY);15671568/* Optional call to update the users info structure */1569PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr,1570png_inforp info_ptr),PNG_EMPTY);1571#endif15721573/* APIs which do a tranform on both read and write but where the implementation1574* is separate for each; the read and write init functions are in pngrtran.c or1575* pngwtran.c, the API is in pngtrans.c1576*/1577#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED)1578PNG_INTERNAL_FUNCTION(void,png_init_read_pack,(png_transformp *transform,1579png_transform_controlp tc),PNG_EMPTY);1580#endif /* READ_PACK || READ_EXPAND */1581#ifdef PNG_WRITE_PACK_SUPPORTED1582PNG_INTERNAL_FUNCTION(void,png_init_write_pack,(png_transformp *transform,1583png_transform_controlp tc),PNG_EMPTY);1584#endif /* WRITE_PACK */15851586/* Shared transform functions, defined in pngtran.c */1587#if defined(PNG_WRITE_FILLER_SUPPORTED) || \1588defined(PNG_READ_STRIP_ALPHA_SUPPORTED)1589PNG_INTERNAL_FUNCTION(void,png_do_strip_channel,(1590png_transform_controlp row_info, png_bytep row, int at_start),PNG_EMPTY);1591#endif /* FILLER */15921593#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)1594PNG_INTERNAL_FUNCTION(void,png_do_invert,(png_transform_controlp row_info,1595png_bytep row),PNG_EMPTY);1596#endif /* INVERT */15971598#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) ||\1599defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)1600PNG_INTERNAL_FUNCTION(void,png_do_invert_alpha,(png_transform_controlp row_info,1601png_bytep row),PNG_EMPTY);1602#endif /* INVERT_ALPHA */16031604#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED1605PNG_INTERNAL_FUNCTION(void,png_add_rgb_to_gray_byte_ops,(png_structrp png_ptr,1606png_transform_controlp tc, unsigned int index, unsigned int order),1607PNG_EMPTY);1608/* This is an init-time utility to add appropriate byte ops to select a given1609* channel from R/G/B.1610*/1611#endif /* READ_RGB_TO_GRAY */16121613#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) &&\1614defined(PNG_READ_BACKGROUND_SUPPORTED)1615PNG_INTERNAL_FUNCTION(void,png_push_gray_to_rgb_byte_ops,(png_transformp *tr,1616png_transform_controlp tc), PNG_EMPTY);1617/* This is an init-time utility to push appropriate byte ops to expand a1618* grayscale PNG data set to RGB. It calls the function callback so 'tc'1619* must be non-NULL.1620*/1621#endif /* GRAY_TO_RGB && READ_BACKGROUND */16221623#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED1624PNG_INTERNAL_FUNCTION(void,png_add_strip_alpha_byte_ops,(png_structrp png_ptr),1625PNG_EMPTY);1626/* Called from pngrtran.c to add the relevant byte op. */1627#endif /* READ_STRIP_ALPHA */16281629/* The following decodes the appropriate chunks, and does error correction,1630* then calls the appropriate callback for the chunk if it is valid.1631*/16321633#ifdef PNG_READ_SUPPORTED1634PNG_INTERNAL_FUNCTION(png_bytep,png_read_buffer,(png_structrp png_ptr,1635png_alloc_size_t new_size, int warn),PNG_EMPTY);1636/* Manage the dynamically allocated read buffer */16371638/* Shared READ IDAT handling: */1639PNG_INTERNAL_FUNCTION(void,png_read_start_IDAT,(png_structrp png_ptr),1640PNG_EMPTY);1641/* Initialize the row buffers, etc. */16421643typedef enum1644{1645png_row_incomplete,1646/* more IDAT data needed for row */1647png_row_process,1648/* png_struct::row_buffer contains a complete row */1649png_row_repeat,1650/* row not in this pass, but the existing row may be used */1651png_row_skip1652/* row not in pass and no appropriate data; skip this row */1653} png_row_op;1654PNG_INTERNAL_FUNCTION(png_row_op,png_read_process_IDAT,(png_structrp png_ptr,1655png_bytep transformed_row, png_bytep display_row, int save_row),1656PNG_EMPTY);1657/* Process a block of IDAT data; the routine returns early if it has1658* obtained a row. It is valid to call this routine with no input data;1659* it will return png_row_incomplete if it needs input.1660*1661* transformed_row: The transformed pixels of the input are written here.1662* For interlaced images only the pixels in the pass will1663* be written, the other pixels will not be touched.1664*1665* display_row: The transformed pixels but replicated to that the entire1666* buffer will have been initialized. For passes after the1667* first the pixels written are determined by the 'block'1668* algorithm; only those *following* pixels which are1669* written by *later* passes are written (with a copy of the1670* pixel from the pass.)1671*1672* save_row: A boolean which indicates that the row (unexpanded)1673* should be saved in png_struct::transformed_row. This can1674* be used in a later call to png_combine_row.1675*1676* During reading the row is built up until png_row_process is returned. At1677* this point png_struct::row_buffer contains the original PNG row from the1678* file and, if save_row was set, png_struct::transformed_row contains the1679* row after the selected row transforms have been performed. For interlaced1680* images both are the width of the interlace pass.1681*1682* When png_row_repeat is returned the same is true, except that the buffers1683* still contain the contents of the preceding row (the one where this1684* funciton returned png_row_pricess).1685*1686* The row buffers should not be accessed if png_row_skip is returned; this1687* row is not modified in the current pass.1688*/16891690PNG_INTERNAL_FUNCTION(void,png_read_free_row_buffers,(png_structrp png_ptr),1691PNG_EMPTY);1692/* Free allocated row buffers; done as soon as possible to avoid carrying1693* around all the memory for longer than necessary.1694*/16951696PNG_INTERNAL_FUNCTION(int,png_read_finish_IDAT,(png_structrp png_ptr),1697PNG_EMPTY);1698/* Complete reading of the IDAT chunks. This returns 0 if more data is to1699* be read, 1 if the zlib stream has terminated. Call this routine with1700* zstream.avail_in greater than zero unless there is no more input data.1701* When zstream_avail_in is 0 on entry and the stream does not terminate1702* an "IDAT truncated" error will be output.1703*1704* ENTRY: png_ptr->zstream.{next,avail}_in points to more IDAT data, if1705* available, otherwise avail_in should be 0.1706* RET 0: the LZ stream is still active, more IDAT date is required, if1707* available, the routine *must* be called again.1708* RET 1: the LZ stream has been closed and an error may have been output;1709* png_ptr->zstream_error says whether it has. If not and there1710* is more IDAT data available the caller should output an1711* appropriate (too much IDAT) error message.1712*/17131714#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED1715PNG_INTERNAL_FUNCTION(void,png_cache_known_unknown,(png_structrp png_ptr,1716png_const_bytep add, int keep),PNG_EMPTY);1717/* Update the png_struct::known_unknown bit cache which stores whether each1718* known chunk should be treated as unknown.1719*/1720#endif17211722typedef enum1723{1724png_chunk_skip = 0, /* Skip this chunk */1725png_chunk_unknown, /* Pass the chunk to png_handle_unknown */1726png_chunk_process_all, /* Process the chunk all at once */1727png_chunk_process_part /* Process the chunk in parts (for IDAT) */1728} png_chunk_op;17291730PNG_INTERNAL_FUNCTION(png_chunk_op,png_find_chunk_op,(png_structrp png_ptr),1731PNG_EMPTY);1732/* Given a chunk in png_struct::{chunk_name,chunk_length} validate the name1733* and work out how it should be handled. This function checks the chunk1734* location using png_struct::mode and will set the mode appropriately for1735* the known critical chunks but otherwise makes no changes to the stream1736* read state.1737*/17381739PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr,1740const png_uint_32 chunk_name),PNG_EMPTY);17411742PNG_INTERNAL_FUNCTION(void,png_check_chunk_length,(png_const_structrp png_ptr,1743const png_uint_32 chunk_length),PNG_EMPTY);17441745#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED1746PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,1747png_inforp info_ptr, png_bytep chunk_data),PNG_EMPTY);1748/* Handle an unknown chunk that needs to be processed. It is only valid1749* to call this after png_find_chunk_op returns png_chunk_unknown. The1750* data argument points to the png_struct::chunk_length bytes of the chunk1751* data.1752*/1753#endif /* READ_UNKNOWN_CHUNKS */17541755PNG_INTERNAL_FUNCTION(void,png_handle_chunk,(png_structrp png_ptr,1756png_inforp info_ptr),PNG_EMPTY);1757/* The chunk to handle is in png_struct::chunk_name,chunk_length.1758*1759* NOTE: at present it is only valid to call this after png_find_chunk_op1760* has returned png_chunk_process_all and all the data is available for1761* png_handle_chunk (via the libpng read callback.)1762*/1763#endif /* READ */17641765PNG_INTERNAL_FUNCTION(void,png_init_row_info,(png_structrp png_ptr),PNG_EMPTY);1766/* Set the png_struct::row_ members from the PNG file information, running1767* transforms if required.1768*/17691770/* Added at libpng version 1.6.0 */1771#ifdef PNG_GAMMA_SUPPORTED1772PNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,1773png_colorspacerp colorspace, png_fixed_point gAMA), PNG_EMPTY);1774/* Set the colorspace gamma with a value provided by the application or by1775* the gAMA chunk on read. The value will override anything set by an ICC1776* profile.1777*/17781779PNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,1780png_inforp info_ptr), PNG_EMPTY);1781/* Synchronize the info 'valid' flags with the colorspace */17821783PNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,1784png_inforp info_ptr), PNG_EMPTY);1785/* Copy the png_struct colorspace to the info_struct and call the above to1786* synchronize the flags. Checks for NULL info_ptr and does nothing.1787*/1788#endif17891790/* Added at libpng version 1.4.0 */1791#ifdef PNG_COLORSPACE_SUPPORTED1792/* These internal functions are for maintaining the colorspace structure within1793* a png_info or png_struct (or, indeed, both).1794*/1795PNG_INTERNAL_FUNCTION(int,png_colorspace_set_chromaticities,1796(png_const_structrp png_ptr, png_colorspacerp colorspace, const png_xy *xy,1797int preferred), PNG_EMPTY);17981799PNG_INTERNAL_FUNCTION(int,png_colorspace_set_endpoints,1800(png_const_structrp png_ptr, png_colorspacerp colorspace, const png_XYZ *XYZ,1801int preferred), PNG_EMPTY);18021803#ifdef PNG_sRGB_SUPPORTED1804PNG_INTERNAL_FUNCTION(int,png_colorspace_set_sRGB,(png_const_structrp png_ptr,1805png_colorspacerp colorspace, int intent), PNG_EMPTY);1806/* This does set the colorspace gAMA and cHRM values too, but doesn't set the1807* flags to write them, if it returns false there was a problem and an error1808* message has already been output (but the colorspace may still need to be1809* synced to record the invalid flag).1810*/1811#endif /* sRGB */18121813#ifdef PNG_iCCP_SUPPORTED1814PNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr,1815png_colorspacerp colorspace, png_const_charp name,1816png_uint_32 profile_length, png_const_bytep profile, int is_color),1817PNG_EMPTY);1818/* The 'name' is used for information only */18191820/* Routines for checking parts of an ICC profile. */1821PNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr,1822png_colorspacerp colorspace, png_const_charp name,1823png_uint_32 profile_length), PNG_EMPTY);1824PNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr,1825png_colorspacerp colorspace, png_const_charp name,1826png_uint_32 profile_length,1827png_const_bytep profile /* first 132 bytes only */, int is_color),1828PNG_EMPTY);1829PNG_INTERNAL_FUNCTION(int,png_icc_check_tag_table,(png_const_structrp png_ptr,1830png_colorspacerp colorspace, png_const_charp name,1831png_uint_32 profile_length,1832png_const_bytep profile /* header plus whole tag table */), PNG_EMPTY);1833#ifdef PNG_sRGB_SUPPORTED1834PNG_INTERNAL_FUNCTION(void,png_icc_set_sRGB,(1835png_const_structrp png_ptr, png_colorspacerp colorspace,1836png_const_bytep profile, uLong adler), PNG_EMPTY);1837/* 'adler' is the Adler32 checksum of the uncompressed profile data. It may1838* be zero to indicate that it is not available. It is used, if provided,1839* as a fast check on the profile when checking to see if it is sRGB.1840*/1841#endif /* sRGB */1842#endif /* iCCP */1843#endif /* COLORSPACE */18441845/* Added at libpng version 1.4.0 */1846PNG_INTERNAL_FUNCTION(void,png_check_IHDR,(png_const_structrp png_ptr,1847png_uint_32 width, png_uint_32 height, int bit_depth,1848int color_type, int interlace_type, int compression_type,1849int filter_type),PNG_EMPTY);18501851#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)1852PNG_INTERNAL_FUNCTION(void,png_fixed_error,(png_const_structrp png_ptr,1853png_const_charp name),PNG_NORETURN);1854#endif18551856/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite1857* the end. Always leaves the buffer nul terminated. Never errors out (and1858* there is no error code.)1859*/1860PNG_INTERNAL_FUNCTION(size_t,png_safecat,(png_charp buffer, size_t bufsize,1861size_t pos, png_const_charp string),PNG_EMPTY);18621863/* Various internal functions to handle formatted warning messages, currently1864* only implemented for warnings.1865*/1866#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)1867/* Utility to dump an unsigned value into a buffer, given a start pointer and1868* and end pointer (which should point just *beyond* the end of the buffer!)1869* Returns the pointer to the start of the formatted string. This utility only1870* does unsigned values.1871*/1872PNG_INTERNAL_FUNCTION(png_charp,png_format_number,(png_const_charp start,1873png_charp end, int format, png_alloc_size_t number),PNG_EMPTY);18741875/* Convenience macro that takes an array: */1876#define PNG_FORMAT_NUMBER(buffer,format,number) \1877png_format_number(buffer, buffer + (sizeof buffer), format, number)18781879/* Suggested size for a number buffer (enough for 64 bits and a sign!) */1880#define PNG_NUMBER_BUFFER_SIZE 2418811882/* These are the integer formats currently supported, the name is formed from1883* the standard printf(3) format string.1884*/1885#define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */1886#define PNG_NUMBER_FORMAT_02u 21887#define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */1888#define PNG_NUMBER_FORMAT_02d 21889#define PNG_NUMBER_FORMAT_x 31890#define PNG_NUMBER_FORMAT_02x 41891#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */1892#endif18931894#ifdef PNG_WARNINGS_SUPPORTED1895/* New defines and members adding in libpng-1.5.4 */1896# define PNG_WARNING_PARAMETER_SIZE 321897# define PNG_WARNING_PARAMETER_COUNT 8 /* Maximum 9; see pngerror.c */18981899/* An l-value of this type has to be passed to the APIs below to cache the1900* values of the parameters to a formatted warning message.1901*/1902typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][1903PNG_WARNING_PARAMETER_SIZE];19041905PNG_INTERNAL_FUNCTION(void,png_warning_parameter,(png_warning_parameters p,1906int number, png_const_charp string),PNG_EMPTY);1907/* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters,1908* including the trailing '\0'.1909*/1910PNG_INTERNAL_FUNCTION(void,png_warning_parameter_unsigned,1911(png_warning_parameters p, int number, int format, png_alloc_size_t value),1912PNG_EMPTY);1913/* Use png_alloc_size_t because it is an unsigned type as big as any we1914* need to output. Use the following for a signed value.1915*/1916PNG_INTERNAL_FUNCTION(void,png_warning_parameter_signed,1917(png_warning_parameters p, int number, int format, png_int_32 value),1918PNG_EMPTY);19191920PNG_INTERNAL_FUNCTION(void,png_formatted_warning,(png_const_structrp png_ptr,1921png_warning_parameters p, png_const_charp message),PNG_EMPTY);1922/* 'message' follows the X/Open approach of using @1, @2 to insert1923* parameters previously supplied using the above functions. Errors in1924* specifying the parameters will simply result in garbage substitutions.1925*/1926#endif19271928#ifdef PNG_BENIGN_ERRORS_SUPPORTED1929/* Application errors (new in 1.6); use these functions (declared below) for1930* errors in the parameters or order of API function calls on read. The1931* 'warning' should be used for an error that can be handled completely; the1932* 'error' for one which can be handled safely but which may lose application1933* information or settings.1934*1935* By default these both result in a png_error call prior to release, while in a1936* released version the 'warning' is just a warning. However if the application1937* explicitly disables benign errors (explicitly permitting the code to lose1938* information) they both turn into warnings.1939*1940* If benign errors aren't supported they end up as the corresponding base call1941* (png_warning or png_error.)1942*/1943PNG_INTERNAL_FUNCTION(void,png_app_warning,(png_const_structrp png_ptr,1944png_const_charp message),PNG_EMPTY);1945/* The application provided invalid parameters to an API function or called1946* an API function at the wrong time, libpng can completely recover.1947*/19481949PNG_INTERNAL_FUNCTION(void,png_app_error,(png_const_structrp png_ptr,1950png_const_charp message),PNG_EMPTY);1951/* As above but libpng will ignore the call, or attempt some other partial1952* recovery from the error.1953*/1954#else1955# define png_app_warning(pp,s) png_warning(pp,s)1956# define png_app_error(pp,s) png_error(pp,s)1957#endif19581959PNG_INTERNAL_FUNCTION(void,png_chunk_report,(png_const_structrp png_ptr,1960png_const_charp message, int error),PNG_EMPTY);1961/* Report a recoverable issue in chunk data. On read this is used to report1962* a problem found while reading a particular chunk and the1963* png_chunk_benign_error or png_chunk_warning function is used as1964* appropriate. On write this is used to report an error that comes from1965* data set via an application call to a png_set_ API and png_app_error or1966* png_app_warning is used as appropriate.1967*1968* With PNG_CHUNK_FATAL an error can be marked as unrecoverable, and the1969* function will not return.1970*1971* The 'error' parameter must have one of the following values:1972*/1973#define PNG_CHUNK_WARNING 0 /* never an error */1974#define PNG_CHUNK_WRITE_ERROR 1 /* an error only on write */1975#define PNG_CHUNK_ERROR 2 /* always an error */1976#define PNG_CHUNK_FATAL 3 /* an unrecoverable error */19771978#ifndef PNG_ERROR_TEXT_SUPPORTED1979# define png_chunk_report(pp,e,v) png_chunk_report(pp,NULL,v)1980#endif19811982/* ASCII to FP interfaces, currently only implemented if sCAL1983* support is required.1984*/1985#if defined(PNG_sCAL_SUPPORTED)1986/* MAX_DIGITS is actually the maximum number of characters in an sCAL1987* width or height, derived from the precision (number of significant1988* digits - a build time settable option) and assumptions about the1989* maximum ridiculous exponent.1990*/1991#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)19921993#ifdef PNG_FLOATING_POINT_SUPPORTED1994PNG_INTERNAL_FUNCTION(void,png_ascii_from_fp,(png_const_structrp png_ptr,1995png_charp ascii, png_size_t size, double fp, unsigned int precision),1996PNG_EMPTY);1997#endif /* FLOATING_POINT */19981999#ifdef PNG_FIXED_POINT_SUPPORTED2000PNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr,2001png_charp ascii, png_size_t size, png_fixed_point fp),PNG_EMPTY);2002#endif /* FIXED_POINT */2003#endif /* sCAL */20042005#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)2006/* An internal API to validate the format of a floating point number.2007* The result is the index of the next character. If the number is2008* not valid it will be the index of a character in the supposed number.2009*2010* The format of a number is defined in the PNG extensions specification2011* and this API is strictly conformant to that spec, not anyone elses!2012*2013* The format as a regular expression is:2014*2015* [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?2016*2017* or:2018*2019* [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?2020*2021* The complexity is that either integer or fraction must be present and the2022* fraction is permitted to have no digits only if the integer is present.2023*2024* NOTE: The dangling E problem.2025* There is a PNG valid floating point number in the following:2026*2027* PNG floating point numbers are not greedy.2028*2029* Working this out requires *TWO* character lookahead (because of the2030* sign), the parser does not do this - it will fail at the 'r' - this2031* doesn't matter for PNG sCAL chunk values, but it requires more care2032* if the value were ever to be embedded in something more complex. Use2033* ANSI-C strtod if you need the lookahead.2034*/2035/* State table for the parser. */2036#define PNG_FP_INTEGER 0 /* before or in integer */2037#define PNG_FP_FRACTION 1 /* before or in fraction */2038#define PNG_FP_EXPONENT 2 /* before or in exponent */2039#define PNG_FP_STATE 3 /* mask for the above */2040#define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */2041#define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */2042#define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */2043#define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */2044#define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */20452046/* These three values don't affect the parser. They are set but not used.2047*/2048#define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */2049#define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */2050#define PNG_FP_NONZERO 256 /* A non-zero value */2051#define PNG_FP_STICKY 448 /* The above three flags */20522053/* This is available for the caller to store in 'state' if required. Do not2054* call the parser after setting it (the parser sometimes clears it.)2055*/2056#define PNG_FP_INVALID 512 /* Available for callers as a distinct value */20572058/* Result codes for the parser (boolean - true meants ok, false means2059* not ok yet.)2060*/2061#define PNG_FP_MAYBE 0 /* The number may be valid in the future */2062#define PNG_FP_OK 1 /* The number is valid */20632064/* Tests on the sticky non-zero and negative flags. To pass these checks2065* the state must also indicate that the whole number is valid - this is2066* achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this2067* is equivalent to PNG_FP_OK above.)2068*/2069#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO)2070/* NZ_MASK: the string is valid and a non-zero negative value */2071#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO)2072/* Z MASK: the string is valid and a non-zero value. */2073/* PNG_FP_SAW_DIGIT: the string is valid. */2074#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT)2075#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)2076#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)20772078/* The actual parser. This can be called repeatedly. It updates2079* the index into the string and the state variable (which must2080* be initialized to 0). It returns a result code, as above. There2081* is no point calling the parser any more if it fails to advance to2082* the end of the string - it is stuck on an invalid character (or2083* terminated by '\0').2084*2085* Note that the pointer will consume an E or even an E+ and then leave2086* a 'maybe' state even though a preceding integer.fraction is valid.2087* The PNG_FP_WAS_VALID flag indicates that a preceding substring was2088* a valid number. It's possible to recover from this by calling2089* the parser again (from the start, with state 0) but with a string2090* that omits the last character (i.e. set the size to the index of2091* the problem character.) This has not been tested within libpng.2092*/2093PNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string,2094png_size_t size, int *statep, png_size_tp whereami),PNG_EMPTY);20952096/* This is the same but it checks a complete string and returns true2097* only if it just contains a floating point number. As of 1.5.4 this2098* function also returns the state at the end of parsing the number if2099* it was valid (otherwise it returns 0.) This can be used for testing2100* for negative or zero values using the sticky flag.2101*/2102PNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string,2103png_size_t size),PNG_EMPTY);2104#endif /* pCAL || sCAL */21052106#if defined(PNG_GAMMA_SUPPORTED) ||\2107defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)2108/* Added at libpng version 1.5.0 */2109/* This is a utility to provide a*times/div (rounded) and indicate2110* if there is an overflow. The result is a boolean - false (0)2111* for overflow, true (1) if no overflow, in which case *res2112* holds the result.2113*/2114PNG_INTERNAL_FUNCTION(int,png_muldiv,(png_fixed_point_p res, png_fixed_point a,2115png_int_32 multiplied_by, png_int_32 divided_by),PNG_EMPTY);2116#endif /* GAMMA || INCH_CONVERSIONS || READ_pHYs */21172118#ifdef PNG_READ_GAMMA_SUPPORTED2119/* Internal fixed point gamma correction. These APIs are called as2120* required to convert single values - they don't need to be fast,2121* they are not used when processing image pixel values.2122*/2123PNG_INTERNAL_FUNCTION(unsigned int,png_gamma_nxmbit_correct,2124(unsigned int value, png_fixed_point gamma_val, unsigned int n/*input bits*/,2125unsigned int m/*output bits */),PNG_EMPTY);2126/* In this case the value must have 'n' bits and the output will have 'm'2127* bits.2128*/21292130#if !PNG_RELEASE_BUILD2131PNG_INTERNAL_FUNCTION(int,png_gamma_check,(png_const_structrp png_ptr,2132png_const_transform_controlp tc),PNG_EMPTY);2133/* Debugging only routine to repeat the test used above to determine if the2134* gamma was insignificant.2135*/2136#endif /* !RELEASE_BUILD */2137#endif /* READ_GAMMA */21382139#ifdef PNG_SIMPLIFIED_READ_SUPPORTED2140/* Internal check function to saw if the gamma of the PNG data is far enough2141* from the given screen gamma to require gamma correction (only needed for a2142* bug work-round in the simplified API).2143* TODO: it should be possible to remove the bug work-round in 1.72144*/2145PNG_INTERNAL_FUNCTION(int,png_need_gamma_correction,(png_const_structrp png_ptr,2146png_fixed_point gamma, int sRGB_output),PNG_EMPTY);2147#endif /* SIMPLIFIED_READ */21482149/* This is a utility macro to say whether a gamma value is close enough to sRGB.2150* The test is now hardwired:2151*2152* API CHANGE: prior to 1.7 this would depend on the build-time2153* PNG_GAMMA_THRESHOLD_FIXED setting, which would cause inconsistent results2154* when the setting was changed. Since this setting can now be changed at2155* run-time it seems more sensible to have a single fixed definition of 'sRGB'.2156*2157* The test is approximately +/- 1%, it allows any decimal value from 0.45 (the2158* two digit rounded version of 1/2.2) to just under 0.46).2159*/2160#define PNG_GAMMA_IS_sRGB(g) ((g) >= 45000 && (g) < 46000)21612162/* SIMPLIFIED READ/WRITE SUPPORT */2163#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\2164defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)2165/* The internal structure that png_image::opaque points to. */2166typedef struct png_control2167{2168png_structp png_ptr;2169png_infop info_ptr;2170png_voidp error_buf; /* Always a jmp_buf at present. */21712172png_const_bytep memory; /* Memory buffer. */2173png_size_t size; /* Size of the memory buffer. */21742175unsigned int for_write :1; /* Otherwise it is a read structure */2176unsigned int owned_file :1; /* We own the file in io_ptr */2177} png_control;21782179/* Return the pointer to the jmp_buf from a png_control: necessary because C2180* does not reveal the type of the elements of jmp_buf.2181*/2182#ifdef __cplusplus2183# define png_control_jmp_buf(pc) (((jmp_buf*)((pc)->error_buf))[0])2184#else2185# define png_control_jmp_buf(pc) ((pc)->error_buf)2186#endif21872188/* Utility to safely execute a piece of libpng code catching and logging any2189* errors that might occur. Returns true on success, false on failure (either2190* of the function or as a result of a png_error.)2191*/2192PNG_INTERNAL_CALLBACK(void,png_safe_error,(png_structp png_ptr,2193png_const_charp error_message),PNG_NORETURN);21942195#ifdef PNG_WARNINGS_SUPPORTED2196PNG_INTERNAL_CALLBACK(void,png_safe_warning,(png_structp png_ptr,2197png_const_charp warning_message),PNG_EMPTY);2198#else2199# define png_safe_warning 0/*dummy argument*/2200#endif22012202PNG_INTERNAL_FUNCTION(int,png_safe_execute,(png_imagep image,2203int (*function)(png_voidp), png_voidp arg),PNG_EMPTY);22042205/* Utility to log an error; this also cleans up the png_image; the function2206* always returns 0 (false).2207*/2208PNG_INTERNAL_FUNCTION(int,png_image_error,(png_imagep image,2209png_const_charp error_message),PNG_EMPTY);22102211/* Safely initialize a stdio pointer - used by both the read and the write2212* code.2213*/2214#ifdef PNG_STDIO_SUPPORTED2215PNG_INTERNAL_FUNCTION(int,png_image_init_io,(png_imagep image, png_FILE_p file),2216PNG_EMPTY);2217#endif /* STDIO */22182219#ifndef PNG_SIMPLIFIED_READ_SUPPORTED2220/* png_image_free is used by the write code but not exported */2221PNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY);2222#endif /* !SIMPLIFIED_READ */22232224#endif /* SIMPLIFIED READ/WRITE */22252226#ifdef PNG_READ_SUPPORTED2227PNG_INTERNAL_FUNCTION(png_int_32, png_read_setting, (png_structrp png_ptr,2228png_uint_32 setting, png_uint_32 parameter, png_int_32 value), PNG_EMPTY);2229#endif /* READ */2230#ifdef PNG_WRITE_SUPPORTED2231PNG_INTERNAL_FUNCTION(png_int_32, png_write_setting, (png_structrp png_ptr,2232png_uint_32 setting, png_uint_32 parameter, png_int_32 value), PNG_EMPTY);2233/* Implementations of read and write settings, in pngrutil.c and pngwutil.c2234* respectively.2235*/2236#endif /* WRITE */22372238/* Maintainer: Put new private prototypes here ^ */22392240/* These are initialization functions for hardware specific PNG filter2241* optimizations; list these here then select the appropriate one at compile2242* time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined2243* the generic code is used.2244*/2245#ifdef PNG_FILTER_OPTIMIZATIONS2246PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structrp png_ptr,2247unsigned int bpp), PNG_EMPTY);2248/* Just declare the optimization that will be used */2249#else2250/* List *all* the possible optimizations here - this branch is required if2251* the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in2252* CFLAGS in place of CPPFLAGS *and* uses symbol prefixing.2253*/2254PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,2255(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);2256#endif22572258#include "pngdebug.h"22592260/* EXTENSION SPECIFIC FUNCTIONS */2261#include "arm/neon.h"22622263#ifdef __cplusplus2264}2265#endif22662267#endif /* PNG_VERSION_INFO_ONLY */2268#endif /* PNGPRIV_H */226922702271