/* pngpriv.h - private declarations for use inside libpng * *Copyright(c)2018-2025CosminTruta *Copyright(c)1998-2002,2004,2006-2018GlennRanders-Pehrson *Copyright(c)1996-1997AndreasDilger *Copyright(c)1995-1996GuyEricSchalnat,Group42,Inc. * *Thiscodeisreleasedunderthelibpnglicense. *Forconditionsofdistributionanduse,seethedisclaimer *andlicenseinpng.h
*/
/* The symbols declared in this file (including the functions declared *asextern)arePRIVATE.Theyarenotpartofthelibpngpublic *interface,andarenotrecommendedforusebyregularapplications. *Someofthemmaybecomepublicinthefuture;othersmaystayprivate, *changeinanincompatibleway,orevendisappear. *Althoughthelibpngusersarenotforbiddentoincludethisheader, *theyshouldbewellawareoftheissuesthatmayarisefromdoingso.
*/
/* pngpriv.h must be included first in each translation unit inside libpng. *Ontheotherhand,itmustnotbeincludedatall,directlyorindirectly, *byanyapplicationcodethatusesthelibpngAPI.
*/ #ifndef PNGPRIV_H # define PNGPRIV_H #else # error Duplicate inclusion of pngpriv.h; please check the libpng source files #endif
#ifdefined(PNG_H) || defined(PNGCONF_H) || defined(PNGLCONF_H) # error This file must not be included by applications; please include <png.h> #endif
/* Feature Test Macros. The following are defined here to ensure that correctly *implementedlibrariesrevealtheAPIslibpngneedstobuildandhidethose *thatarenotneededandpotentiallydamagingtothecompilation. * *FeatureTestMacrosmustbedefinedbeforeanysystemheaderisincluded(see *POSIX1003.12.8.2"POSIXSymbols." * *Thesemacrosonlyhaveaneffectiftheoperatingsystemsupportseither *POSIX1003.1orC99,orboth.Onotheroperatingsystems(particularly *Windows/VisualStudio)thereisnoeffect;theOSspecifictestsbeloware *stillrequired(asof2011-05-02.)
*/ #ifndef _POSIX_SOURCE # define _POSIX_SOURCE 1/* Just the POSIX 1003.1 and C89 APIs */ #endif
#ifndef PNG_VERSION_INFO_ONLY /* Standard library headers not required by png.h: */ # include <stdlib.h> # include <string.h> #endif
#define PNGLIB_BUILD /*libpng is being built, not used*/
/* If HAVE_CONFIG_H is defined during the build then the build system must *provideanappropriate"config.h"fileontheincludepath.Theheaderfile *mustprovidedefinitionsasrequiredbelow(searchfor"HAVE_CONFIG_H"); *seeconfigure.acformoredetailsoftherequirements.Themacro *"PNG_NO_CONFIG_H"isprovidedformaintainerstotestfordependencieson *'configure';definethismacrotopreventtheconfigurebuildincludingthe *configuregeneratedconfig.h.Libpngisexpectedtocompilewithout*any* *specialbuildsystemsupportonareasonablyANSI-Ccompliantsystem.
*/ #ifdefined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H) # include <config.h> /* Pick up the definition of 'restrict' from config.h if it was read: */ # define PNG_RESTRICT restrict #endif
/* To support symbol prefixing it is necessary to know *before* including png.h *whetherthefixedpoint(andmaybeother)APIsareexported,becauseifthey *arenotinternaldefinitionsmayberequired.Thisishandledbelowjust *beforepng.hisincluded,butloadtheconfigurationnowifitisavailable.
*/ #include"pnglibconf.h"
/* Local renames may change non-exported API functions from png.h */ #ifdefined(PNG_PREFIX) && !defined(PNGPREFIX_H) # include "pngprefix.h" #endif
#ifdef PNG_USER_CONFIG # include "pngusr.h" /* These should have been defined in pngusr.h */ # ifndef PNG_USER_PRIVATEBUILD # define PNG_USER_PRIVATEBUILD "Custom libpng build" # endif # ifndef PNG_USER_DLLFNAME_POSTFIX # define PNG_USER_DLLFNAME_POSTFIX "Cb" # endif #endif
#ifndef PNG_RISCV_RVV_OPT /* RISCV_RVV optimizations are being controlled by the compiler settings, *typicallythetargetcompilerwilldefine__riscvbutthervvextension *availabilityhastobeexplicitlystated.Thisiswhyifno *PNG_RISCV_RVV_OPTwasdefinedthenaruntimecheckwillbeexecuted. * *ToenableRISCV_RVVoptimizationsunconditionally,andcompilethe *associatedcode,pass--enable-riscv-rvv=yesor--enable-riscv-rvv=on *toconfigureorput-DPNG_RISCV_RVV_OPT=2inCPPFLAGS.
*/
# define PNG_RISCV_RVV_OPT 0 #endif
#if PNG_ARM_NEON_OPT > 0 /* NEON optimizations are to be at least considered by libpng, so enable the *callbackstodothis.
*/ # define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon # ifndef PNG_ARM_NEON_IMPLEMENTATION /* Use the intrinsics code by default. */ # define PNG_ARM_NEON_IMPLEMENTATION 1 # endif #else/* PNG_ARM_NEON_OPT == 0 */ # define PNG_ARM_NEON_IMPLEMENTATION 0 #endif/* PNG_ARM_NEON_OPT > 0 */
/* Is this a build of a DLL where compilation of the object modules requires *differentpreprocessorsettingstothoserequiredforasimplelibrary?If *soPNG_BUILD_DLLmustbeset. * *IflibpngisusedinsideaDLLbutthatDLLdoesnotexportthelibpngAPIs *PNG_BUILD_DLLmustnotbeset.Toavoidthecodebelowkickinginbuilda *staticlibraryoflibpngthenlinktheDLLagainstthat.
*/ #ifndef PNG_BUILD_DLL # ifdef DLL_EXPORT /* This is set by libtool when files are compiled for a DLL; libtool *alwayscompilestwice,evenonsystemswhereitisn'tnecessary.Set *PNG_BUILD_DLLincaseitisnecessary:
*/ # define PNG_BUILD_DLL # else # ifdef _WINDLL /* This is set by the Microsoft Visual Studio IDE in projects that *buildaDLL.Itcan'teasilyberemovedfromthoseprojects(it *isn'tvisibleintheVisualStudioUI)soitisafairlyreliable *indicationthatPNG_IMPEXPneedstobesettotheDLLexport *attributes.
*/ # define PNG_BUILD_DLL # else # ifdef __DLL__ /* This is set by the Borland C system when compiling for a DLL *(asabove.)
*/ # define PNG_BUILD_DLL # else /* Add additional compiler cases here. */ # endif # endif # endif #endif/* Setting PNG_BUILD_DLL if required */
/* See pngconf.h for more details: the builder of the library may set this on *thecommandlinetotherightthingforthespecificcompilationsystemorit *maybeautomagicallysetabove(atpresentweknowofnosystemwhereitdoes *needtobesetonthecommandline.) * *PNG_IMPEXPmustbesetherewhenbuildingthelibrarytopreventpngconf.h *settingittothe"import"settingforaDLLbuild.
*/ #ifndef PNG_IMPEXP # ifdef PNG_BUILD_DLL # define PNG_IMPEXP PNG_DLL_EXPORT # else /* Not building a DLL, or the DLL doesn't require specific export *definitions.
*/ # define PNG_IMPEXP # endif #endif
/* No warnings for private or deprecated functions in the build: */ #ifndef PNG_DEPRECATED # define PNG_DEPRECATED #endif #ifndef PNG_PRIVATE # define PNG_PRIVATE #endif
/* Symbol preprocessing support. * *Toenablelistingglobal,butinternal,symbolsthefollowingmacrosshould *alwaysbeusedtodeclareanexterndataorfunctionobjectinthisfile.
*/ #ifndef PNG_INTERNAL_DATA # define PNG_INTERNAL_DATA(type, name, array) PNG_LINKAGE_DATA type name array #endif
/* If floating or fixed point APIs are disabled they may still be compiled *internally.Tohandlethismakesuretheyaredeclaredastheappropriate *internalexternfunction(otherwisethesymbolprefixingstuffwon'tworkand *thefunctionswillbeusedwithoutdefinitions.) * *NOTE:althoughalltheAPIfunctionsaredeclaredheretheyarenotall *actuallybuilt!Becausethedeclarationsarestillmadeitisnecessaryto *fakeouttypesthattheydependon.
*/ #ifndef PNG_FP_EXPORT # ifndef PNG_FLOATING_POINT_SUPPORTED # define PNG_FP_EXPORT(ordinal, type, name, args)\
PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY); # ifndef PNG_VERSION_INFO_ONLY typedefstruct png_incomplete png_double; typedef png_double* png_doublep; typedefconst png_double* png_const_doublep; typedef png_double** png_doublepp; # endif # endif #endif #ifndef PNG_FIXED_EXPORT # ifndef PNG_FIXED_POINT_SUPPORTED # define PNG_FIXED_EXPORT(ordinal, type, name, args)\
PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY); # endif #endif
#include"png.h"
/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */ #ifndef PNG_DLL_EXPORT # define PNG_DLL_EXPORT #endif
/* This is a global switch to set the compilation for an installed system *(areleasebuild).Itcanbesetfortestingdebugbuildstoensurethat *theywillcompilewhenthebuildtypeisswitchedtoRCorSTABLE,the *defaultisjusttousePNG_LIBPNG_BUILD_BASE_TYPE.SetthisinCPPFLAGS *witheither: * *-DPNG_RELEASE_BUILDTurnsonthereleasecompilepath *-DPNG_RELEASE_BUILD=0Turnsitoff *orinyourpngusr.hwith *#definePNG_RELEASE_BUILD=1Turnsonthereleasecompilepath *#definePNG_RELEASE_BUILD=0Turnsitoff
*/ #ifndef PNG_RELEASE_BUILD # define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC) #endif
/* SECURITY and SAFETY: * *libpngisbuiltwithsupportforinternallimitsonimagedimensionsand *memoryusage.Thesearedocumentedinscripts/pnglibconf.dfaofthe *sourceandrecordedinthemachinegeneratedheaderfilepnglibconf.h.
*/
/* If you are running on a machine where you cannot allocate more *than64Kofmemoryatonce,uncommentthis.Whilelibpngwillnot *normallyneedthatmuchmemoryinachunk(unlessyouloadupavery *largefile),zlibneedstoknowhowbigofachunkitcanuse,and *libpngthusmakessuretocheckanymemoryallocationtoverifyit *willfitintomemory. * *zlibprovides'MAXSEG_64K'which,ifdefined,indicatesthe *samelimitandpngconf.h(alreadyincluded)setsthelimit *ifcertainoperatingsystemsaredetected.
*/ #ifdefined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) # define PNG_MAX_MALLOC_64K #endif
#ifndef PNG_UNUSED /* Unused formal parameter warnings are silenced using the following macro *whichisexpectedtohavenobadeffectsonperformance(optimizing *compilerswillprobablyremoveitentirely).Notethatifyoureplace *itwithsomethingotherthanwhitespace,youmustincludetheterminating *semicolon.
*/ # define PNG_UNUSED(param) (void)param; #endif
/* Just a little check that someone hasn't tried to define something *contradictory.
*/ #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K) # undef PNG_ZBUF_SIZE # define PNG_ZBUF_SIZE 65536L #endif
/* If warnings or errors are turned off the code is disabled or redirected here. *From1.5.4functionshavebeenaddedtoallowverylimitedformattingof *errorandwarningmessages-thiscodewillalsobedisabledhere.
*/ #ifdef PNG_WARNINGS_SUPPORTED # define PNG_WARNING_PARAMETERS(p) png_warning_parameters p; #else # define png_warning_parameter(p,number,string) ((void)0) # define png_warning_parameter_unsigned(p,number,format,value) ((void)0) # define png_warning_parameter_signed(p,number,format,value) ((void)0) # define png_formatted_warning(pp,p,message) ((void)(pp)) # define PNG_WARNING_PARAMETERS(p) #endif #ifndef PNG_ERROR_TEXT_SUPPORTED # define png_fixed_error(s1,s2) png_err(s1) #endif
/* Some fixed point APIs are still required even if not exported because *theygetusedbythecorrespondingfloatingpointAPIs.Thismagic *dealswiththis:
*/ #ifdef PNG_FIXED_POINT_SUPPORTED # define PNGFAPI PNGAPI #else # define PNGFAPI /* PRIVATE */ #endif
#ifndef PNG_VERSION_INFO_ONLY /* Other defines specific to compilers can go here. Try to keep *theminsideanappropriateifdef/endifpairforportability.
*/
/* C allows up-casts from (void*) to any pointer and (const void*) to any *pointertoaconstobject.C++regardsthisasatypeerrorandrequiresan *explicit,static,castandprovidesthestatic_cast<>runetoensurethat *constisnotcastaway.
*/ #ifdef __cplusplus # define png_voidcast(type, value) static_cast<type>(value) # define png_constcast(type, value) const_cast<type>(value) # define png_aligncast(type, value) \
static_cast<type>(static_cast<void*>(value)) # define png_aligncastconst(type, value) \
static_cast<type>(static_cast<constvoid*>(value)) #else # define png_voidcast(type, value) (value) # define png_constcast(type, value) ((type)(void*)(constvoid*)(value)) # define png_aligncast(type, value) ((void*)(value)) # define png_aligncastconst(type, value) ((constvoid*)(value)) #endif/* __cplusplus */
#ifdefined(PNG_FLOATING_POINT_SUPPORTED) ||\ defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) /* png.c requires the following ANSI-C constants if the conversion of *floatingpointtoASCIIisimplementedtherein: * *DBL_DIGMaximumnumberofdecimaldigits(canbesettoanyconstant) *DBL_MINSmallestnormalizedfpnumber(canbesettoanarbitraryvalue) *DBL_MAXMaximumfloatingpointnumber(canbesettoanarbitraryvalue)
*/ # include <float.h>
# include <math.h>
# ifdefined(_AMIGA) && defined(__SASC) && defined(_M68881) /* Amiga SAS/C: We must include builtin FPU functions when compiling using *MATH=68881
*/ # include <m68881.h> # endif #endif
/* This provides the non-ANSI (far) memory allocation routines. */ #ifdefined(__TURBOC__) && defined(__MSDOS__) # include <mem.h> # include <alloc.h> #endif
/* Moved here around 1.5.0beta36 from pngconf.h */ /* Users may want to use these so they are not private. Any library *functionsthatarepassedfardatamustbemodel-independent.
*/
/* These macros may need to be architecture dependent. */ #define PNG_ALIGN_NONE 0/* do not use data alignment */ #define PNG_ALIGN_ALWAYS 1/* assume unaligned accesses are OK */ #ifdef offsetof # define PNG_ALIGN_OFFSET 2/* use offsetof to determine alignment */ #else # define PNG_ALIGN_OFFSET -1/* prevent the use of this */ #endif #define PNG_ALIGN_SIZE 3/* use sizeof to determine alignment */
#ifndef PNG_ALIGN_TYPE /* Default to using aligned access optimizations and requiring alignment to a *multipleofthedatatypesize.Overrideinacompilerspecificfashion *ifnecessarybyinsertingtestshere:
*/ # define PNG_ALIGN_TYPE PNG_ALIGN_SIZE #endif
#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE /* This is used because in some compiler implementations non-aligned *structuremembersaresupported,sotheoffsetofapproachbelowfails. *SetPNG_ALIGN_SIZE=0forcompilercombinationswhereunalignedaccess *isgoodforperformance.Donotdothisunlessyouhavetestedthe *resultandunderstandit.
*/ # define png_alignof(type) (sizeof(type)) #else # if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET # define png_alignof(type) offsetof(struct{char c; type t;}, t) # else # if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS # define png_alignof(type) 1 # endif /* Else leave png_alignof undefined to prevent use thereof */ # endif #endif
/* This implicitly assumes alignment is always a multiple of 2. */ #ifdef png_alignof # define png_isaligned(ptr, type) \
(((type)(size_t)((constvoid*)(ptr)) & (type)(png_alignof(type)-1)) == 0) #else # define png_isaligned(ptr, type) 0 #endif
/* End of memory model/platform independent support */ /* End of 1.5.0beta36 move from pngconf.h */
/* CONSTANTS and UTILITY MACROS *TheseareusedinternallybylibpngandnotexposedintheAPI
*/
/* Various modes of operation. Note that after an init, mode is set to *zeroautomaticallywhenthestructureiscreated.Threeofthese *aredefinedinpng.hbecausetheyneedtobevisibletoapplications *thatcallpng_set_unknown_chunk().
*/ /* #define PNG_HAVE_IHDR 0x01U (defined in png.h) */ /* #define PNG_HAVE_PLTE 0x02U (defined in png.h) */ #define PNG_HAVE_IDAT 0x04U /* #define PNG_AFTER_IDAT 0x08U (defined in png.h) */ #define PNG_HAVE_IEND 0x10U /* 0x20U (unused) */ /* 0x40U (unused) */ /* 0x80U (unused) */ #define PNG_HAVE_CHUNK_HEADER 0x100U #define PNG_WROTE_tIME 0x200U #define PNG_WROTE_INFO_BEFORE_PLTE 0x400U #define PNG_BACKGROUND_IS_GRAY 0x800U #define PNG_HAVE_PNG_SIGNATURE 0x1000U #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000U /* Have another chunk after IDAT */ #define PNG_WROTE_eXIf 0x4000U #define PNG_IS_READ_STRUCT 0x8000U /* Else is a write struct */ #ifdef PNG_APNG_SUPPORTED #define PNG_HAVE_acTL 0x10000U #define PNG_HAVE_fcTL 0x20000U #endif
/* Added to libpng-1.6.0: scale a 16-bit value in the range 0..65535 to 0..255 *bydividingby257*withrounding*.Thismacroisexactforthegivenrange. *Seethediscourseinpngrtran.cpng_do_scale_16_to_8.Thevaluesinthe *macrowereestablishedbyexperiment(modifyingtheaddedvalue).Themacro *hasasecondvariantthattakesavaluealreadyscaledby255anddividesby *65535-thishasamaximumerrorof.502.Overtherange0..65535*65535it *onlygivesoff-by-oneerrorsandonlyfor0.5%(1in200)ofthevalues.
*/ #define PNG_DIV65535(v24) (((v24) + 32895) >> 16) #define PNG_DIV257(v16) PNG_DIV65535((png_uint_32)(v16) * 255)
/* This returns the number of trailing bits in the last byte of a row, 0 if the *lastbyteiscompletelyfullofpixels.Itis,inprinciple,(pixel_bitsx *width)%8,butthatwouldoverflowforlarge'width'.Thesecondmacrois *thesameexceptthatitreturnsthenumberofunusedbitsinthelastbyte; *(8-TRAILBITS),but0whenTRAILBITSis0. * *NOTE:thesemacrosareintendedtobeself-evidentlycorrectandnever *overflowontheassumptionthatpixel_bitsisintherange0..255.The *argumentsareevaluatedonlyonceandtheycanbesigned(e.g.asaresultof *theintegralpromotions).Theresultoftheexpressionalwayshastype *(png_uint_32),howeverthecompileralwaysknowsitisintherange0..7.
*/ #define PNG_TRAILBITS(pixel_bits, width) \
(((pixel_bits) * ((width) % (png_uint_32)8)) % 8)
/* PNG_OUT_OF_RANGE returns true if value is outside the range *ideal-delta..ideal+delta.Eachargumentisevaluatedtwice. *"ideal"and"delta"shouldbeconstants,normallysimple *integers,"value"avariable.Addedtolibpng-1.2.6JB
*/ #define PNG_OUT_OF_RANGE(value, ideal, delta) \
( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
/* Conversions between fixed and floating point, only defined if *required(tomakesurethecodedoesn'taccidentallyusefloat *whenitissupposedlydisabled.)
*/ #ifdef PNG_FLOATING_POINT_SUPPORTED /* The floating point conversion can't overflow, though it can and *doesloseaccuracyrelativetotheoriginalfixedpointvalue. *Inpracticethisdoesn'tmatterbecausepng_fixed_pointonly *storesnumberswithverylowprecision.Thepng_ptrands *argumentsareunusedbydefaultbutarethereincaseerror *checkingbecomesarequirement.
*/ #define png_float(png_ptr, fixed, s) (.00001 * (fixed))
/* The fixed point conversion performs range checking and evaluates *itsargumentmultipletimes,somustbeusedwithcare.The *rangecheckingusesthePNGspecificationvaluesforasigned *32-bitfixedpointvalueexceptthatthevaluesaredeliberately *rounded-to-zerotoanintegralvalue-21474(21474.83isroughly *(2^31-1)*100000).'s'isastringthatdescribesthevaluebeing *converted. * *NOTE:thismacrowillraiseapng_erroriftherangecheckfails, *thereforeitisnormallyonlyappropriatetousethisonvalues *thatcomefromAPIcallsorothersourceswhereanoutofrange *errorindicatesaprogrammingerror,notadataerror! * *NOTE:bydefaultthisisoff-themacroisnotused-becausethe *functioncallsavesalotofcode.
*/ #ifdef PNG_FIXED_POINT_MACRO_SUPPORTED #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0)) #define png_fixed_ITU(png_ptr, fp, s) ((fp) <= 214748 && (fp) >= 0 ?\
((png_uint_32)(10000 * (fp))) : (png_fixed_error(png_ptr, s),0)) #endif /* else the corresponding function is defined below, inside the scope of the *cplusplustest.
*/ #endif
/* Constants for known chunk types. If you need to add a chunk, define the name *here.Forhistoricalreasonstheseconstantshavetheformpng_<name>;i.e. *theprefixislowercase.Pleaseusedecimalvaluesastheparametersto *matchtheISOPNGspecificationandtoavoidrelyingontheClocale *interpretationofcharactervalues. * *Priorto1.5.6theseconstantswerestrings,asof1.5.6png_uint_32values *arecomputedandanewmacro(PNG_STRING_FROM_CHUNK)addedtoallowastring *tobegeneratedifrequired. * *PNG_32bcorrectlyproducesavalueshiftedbyupto24bits,evenon *architectureswhere(int)isonly16bits. * *1.6.47:PNG_32bwasmadeintoapreprocessorevaluablemacrobyreplacingthe *static_castwithapromotingbinaryoperationusingaguaranteed32-bit *(minimum)unsignedvalue.
*/ #define PNG_32b(b,s) (((0xFFFFFFFFU)&(b)) << (s)) #define PNG_U32(b1,b2,b3,b4) \
(PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
/* Chunk name validation. When using these macros all the arguments should be *constants,otherwisecodebloatmaywelloccur.Themacrosareprovided *primarilyforusein#ifchecks. * *PNG_32to8producesabytevaluewiththerightshift;usedtoextractthe *bytevaluefromachunkname.
*/ #define PNG_32to8(cn,s) (((cn) >> (s)) & 0xffU) #define PNG_CN_VALID_UPPER(b) ((b) >= 65 && (b) <= 90) /* upper-case ASCII */ #define PNG_CN_VALID_ASCII(b) PNG_CN_VALID_UPPER((b) & ~32U) #define PNG_CHUNK_NAME_VALID(cn) (\
PNG_CN_VALID_ASCII(PNG_32to8(cn,24)) && /* critical, !ancillary */\
PNG_CN_VALID_ASCII(PNG_32to8(cn,16)) && /* public, !privately defined */\
PNG_CN_VALID_UPPER(PNG_32to8(cn, 8)) && /* VALID, !reserved */\
PNG_CN_VALID_ASCII(PNG_32to8(cn, 0)) /* data-dependent, !copy ok */)
/* The following will work on (signed char*) strings, whereas the get_uint_32 *macrowillfailontop-bit-setvaluesbecauseofthesignextension.
*/ #define PNG_CHUNK_FROM_STRING(s)\
PNG_U32(0xff & (s)[0], 0xff & (s)[1], 0xff & (s)[2], 0xff & (s)[3])
/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is *signedandtheargumentisa(char[])Thismacrowillfailmiserablyon *systemswhere(char)ismorethan8bits.
*/ #define PNG_STRING_FROM_CHUNK(s,c)\
(void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \
((char*)(s))[1]=(char)(((c)>>16) & 0xff),\
((char*)(s))[2]=(char)(((c)>>8) & 0xff), \
((char*)(s))[3]=(char)((c & 0xff)))
/* Do the same but terminate with a null character. */ #define PNG_CSTRING_FROM_CHUNK(s,c)\
(void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
/* Test on flag values as defined in the spec (section 5.4): */ #define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29)) #define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c)) #define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21)) #define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13)) #define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
/* Almost everything below is C specific; the #defines above can be used in *non-Ccode(solongasitisC-preprocessed)therestofthisstuffcannot.
*/ #ifndef PNG_VERSION_INFO_ONLY
#include"pngstruct.h" #include"pnginfo.h"
/* Validate the include paths - the include path used to generate pnglibconf.h *mustmatchthatusedinthebuild,orwemustbeusingpnglibconf.h.prebuilt:
*/ #if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM # error The include path of <zlib.h> is incorrect /* When pnglibconf.h was built, the copy of zlib.h that it used was not the *sameastheonebeingusedhere.Consideringhowlibpngmakesdecisions *tousethezlibAPIbasedonthezlibversionnumber,the-Ioptionsmust *match. * *Apossiblecauseofthismismatchisthatyoupassedan-Ioptionin *CFLAGS,whichisunlikelytowork.Allthepreprocessoroptions,andall *the-Ioptionsinparticular,shouldbeinCPPFLAGS.
*/ #endif
/* This is used for 16-bit gamma tables -- only the top level pointers are *const;thiscouldbechanged:
*/ typedefconst png_uint_16p * png_const_uint_16pp;
/* Added to libpng-1.5.7: sRGB conversion tables */ #ifdefined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\ defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) #ifdef PNG_SIMPLIFIED_READ_SUPPORTED
PNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]); /* Convert from an sRGB encoded value 0..255 to a 16-bit linear value, *0..65535.Thistablegivestheclosest16-bitanswers(noerrors).
*/ #endif
#define PNG_sRGB_FROM_LINEAR(linear) \
((png_byte)(0xff & ((png_sRGB_base[(linear)>>15] \
+ ((((linear) & 0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8))) /* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB *encodedvaluewithmaximumerror0.646365.Notethattheinputisnota
* 16-bit value; it has been multiplied by 255! */ #endif/* SIMPLIFIED_READ/WRITE */
/* Inhibit C++ name-mangling for libpng functions but not for system calls. */ #ifdef __cplusplus extern"C" { #endif/* __cplusplus */
/* Internal functions; these are not exported from a DLL however because they *areusedwithinseveraloftheCsourcefilestheyhavetobeCextern. * *AllofthesefunctionsmustbedeclaredwithPNG_INTERNAL_FUNCTION.
*/ /* Zlib support */ #define PNG_UNEXPECTED_ZLIB_RETURN (-7)
PNG_INTERNAL_FUNCTION(void, png_zstream_error,
(png_structrp png_ptr, int ret),
PNG_EMPTY); /* Used by the zlib handling functions to ensure that z_stream::msg is always *setbeforetheyreturn.
*/
#ifdef PNG_WRITE_SUPPORTED
PNG_INTERNAL_FUNCTION(void, png_free_buffer_list,
(png_structrp png_ptr, png_compression_bufferp *list),
PNG_EMPTY); /* Free the buffer list used by the compressed write code. */ #endif
/* Check the user version string for compatibility, returns false if the version *numbersaren'tcompatible.
*/
PNG_INTERNAL_FUNCTION(int, png_user_version_check,
(png_structrp png_ptr, png_const_charp user_png_ver),
PNG_EMPTY);
#ifdef PNG_READ_SUPPORTED /* should only be used on read */ /* Security: read limits on the largest allocations while reading a PNG. This *avoidsverylargeallocationscausedbyPNGfileswithdamagedoraltered *chunk'length'fields.
*/ #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* run-time limit */ # define png_chunk_max(png_ptr) ((png_ptr)->user_chunk_malloc_max)
#else/* modern system limit SIZE_MAX (C99) */ # define png_chunk_max(png_ptr) ((void)png_ptr, PNG_SIZE_MAX) #endif #endif/* READ */
/* Internal base allocator - no messages, NULL on failure to allocate. This *does,however,calltheapplicationprovidedallocatorandthatcouldcall *png_error(althoughthatwouldbeabugintheapplicationimplementation.)
*/
PNG_INTERNAL_FUNCTION(png_voidp, png_malloc_base,
(png_const_structrp png_ptr, png_alloc_size_t size),
PNG_ALLOCATED);
#ifdefined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\ defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) /* Internal array allocator, outputs no error or warning messages on failure, *justreturnsNULL.
*/
PNG_INTERNAL_FUNCTION(png_voidp, png_malloc_array,
(png_const_structrp png_ptr, int nelements, size_t element_size),
PNG_ALLOCATED);
/* The same but an existing array is extended by add_elements. This function *alsomemsetsthenewelementsto0andcopiestheoldelements.Theold *arrayisnotfreedoraltered.
*/
PNG_INTERNAL_FUNCTION(png_voidp, png_realloc_array,
(png_const_structrp png_ptr,
png_const_voidp array, int old_elements, int add_elements,
size_t element_size),
PNG_ALLOCATED); #endif/* text, sPLT or unknown chunks */
/* Magic to create a struct when there is no struct to call the user supplied *memoryallocators.Becauseerrorhandlinghasnotbeensetupthememory *handlerscan'tsafelycallpng_error,butthisisanobscureandundocumented *restrictionsolibpnghastoassumethatthe'free'handler,atleast,might *callpng_error.
*/
PNG_INTERNAL_FUNCTION(png_structp, png_create_png_struct,
(png_const_charp user_png_ver,
png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn,
png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),
PNG_ALLOCATED);
/* Function to allocate memory for zlib. PNGAPI is disallowed. */
PNG_INTERNAL_FUNCTION(voidpf, png_zalloc,
(voidpf png_ptr, uInt items, uInt size),
PNG_ALLOCATED);
/* Function to free memory for zlib. PNGAPI is disallowed. */
PNG_INTERNAL_FUNCTION(void, png_zfree,
(voidpf png_ptr, voidpf ptr),
PNG_EMPTY);
/* Next four functions are used internally as callbacks. PNGCBAPI is required *butnotPNG_EXPORT.PNGAPIaddedatlibpngversion1.2.3,changedto *PNGCBAPIat1.5.0
*/
/* Write the "data" buffer to whatever output you are using */
PNG_INTERNAL_FUNCTION(void, png_write_data,
(png_structrp png_ptr, png_const_bytep data, size_t length),
PNG_EMPTY);
/* Read and check the PNG file signature */
PNG_INTERNAL_FUNCTION(void, png_read_sig,
(png_structrp png_ptr, png_inforp info_ptr),
PNG_EMPTY);
/* Read the chunk header (length + type name) */
PNG_INTERNAL_FUNCTION(png_uint_32, png_read_chunk_header,
(png_structrp png_ptr),
PNG_EMPTY);
/* Read data from whatever input you are using into the "data" buffer */
PNG_INTERNAL_FUNCTION(void, png_read_data,
(png_structrp png_ptr, png_bytep data, size_t length),
PNG_EMPTY);
/* Read bytes into buf, and update png_ptr->crc */
PNG_INTERNAL_FUNCTION(void, png_crc_read,
(png_structrp png_ptr, png_bytep buf, png_uint_32 length),
PNG_EMPTY);
/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
PNG_INTERNAL_FUNCTION(int, png_crc_finish,
(png_structrp png_ptr, png_uint_32 skip),
PNG_EMPTY);
/* Calculate the CRC over a section of data. Note that we are only *passingamaximumof64Konsystemsthathavethisasamemorylimit, *sincethisisthemaximumbuffersizewecanspecify.
*/
PNG_INTERNAL_FUNCTION(void, png_calculate_crc,
(png_structrp png_ptr, png_const_bytep ptr, size_t length),
PNG_EMPTY);
/* Write the IHDR chunk, and update the png_struct with the necessary *information.
*/
PNG_INTERNAL_FUNCTION(void, png_write_IHDR,
(png_structrp png_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int compression_method, int filter_method, int interlace_method),
PNG_EMPTY);
#ifdef PNG_WRITE_cHRM_SUPPORTED
PNG_INTERNAL_FUNCTION(void, png_write_cHRM_fixed,
(png_structrp png_ptr, const png_xy *xy),
PNG_EMPTY); /* The xy value must have been previously validated */ #endif
#ifdef PNG_WRITE_sCAL_SUPPORTED
PNG_INTERNAL_FUNCTION(void, png_write_sCAL_s,
(png_structrp png_ptr, int unit, png_const_charp width, png_const_charp height),
PNG_EMPTY); #endif
/* Called when finished processing a row of data */
PNG_INTERNAL_FUNCTION(void, png_write_finish_row,
(png_structrp png_ptr),
PNG_EMPTY);
/* Internal use only. Called before first row of data */
PNG_INTERNAL_FUNCTION(void, png_write_start_row,
(png_structrp png_ptr),
PNG_EMPTY);
/* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an *arrayofpng_ptr->widthpixels.Iftheimageisnotinterlacedorthis *isthefinalpassthisjustdoesamemcpy,otherwisethe"display"flag *isusedtodeterminewhethertocopypixelsthatarenotinthecurrentpass. * *Because'png_do_read_interlace'(below)replicatespixelsthisallowsthis *functiontoachievethedocumented'blocky'appearanceduringinterlacedread *ifdisplayis1andthe'sparkle'appearance,whereexistingpixelsin'row' *arenotchangediftheyarenotinthecurrentpass,whendisplayis0. * *'display'mustbe0or1,otherwisethememcpywillbedoneregardless. * *TheAPIalwaysreadsfromthepng_structrowbufferandalwaysassumesthat *itisfullwidth(png_do_read_interlacehasalreadybeencalled.) * *Thisfunctionisonlyeverusedtowritetorowbuffersprovidedbythe *calleroftherelevantlibpngAPIandtherowmusthavealreadybeen *transformedbythereadtransformations. * *ThePNG_USE_COMPILE_TIME_MASKSoptioncausesgenerationofpre-computed *bitmasksforusewithinthecode,otherwiseruntimegeneratedmasksareused. *Thedefaultiscompiletimemasks.
*/ #ifndef PNG_USE_COMPILE_TIME_MASKS # define PNG_USE_COMPILE_TIME_MASKS 1 #endif
PNG_INTERNAL_FUNCTION(void, png_combine_row,
(png_const_structrp png_ptr, png_bytep row, int display),
PNG_EMPTY);
#ifdef PNG_READ_INTERLACING_SUPPORTED /* Expand an interlaced row: the 'row_info' describes the pass data that has *beenreadinandmustcorrespondtothepixelsin'row',thepixelsare *expanded(movedapart)in'row'tomatchthefinallayout,whendoingthis *thepixelsare*replicated*totheinterveningspace.Thisisessentialfor *thecorrectoperationofpng_combine_row,above.
*/
PNG_INTERNAL_FUNCTION(void, png_do_read_interlace,
(png_row_infop row_info,
png_bytep row, int pass, png_uint_32 transformations),
PNG_EMPTY); #endif
/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */
#ifdef PNG_WRITE_INTERLACING_SUPPORTED /* Grab pixels out of a row for an interlaced pass */
PNG_INTERNAL_FUNCTION(void, png_do_write_interlace,
(png_row_infop row_info, png_bytep row, int pass),
PNG_EMPTY); #endif
/* Unfilter a row: check the filter value before calling this, there is no point *callingitforPNG_FILTER_VALUE_NONE.
*/
PNG_INTERNAL_FUNCTION(void, png_read_filter_row,
(png_structrp pp, png_row_infop row_info,
png_bytep row, png_const_bytep prev_row, int filter),
PNG_EMPTY);
/* Choose the best filter to use and filter the row data */
PNG_INTERNAL_FUNCTION(void, png_write_find_filter,
(png_structrp png_ptr, png_row_infop row_info),
PNG_EMPTY);
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
PNG_INTERNAL_FUNCTION(void, png_read_IDAT_data,
(png_structrp png_ptr, png_bytep output, png_alloc_size_t avail_out),
PNG_EMPTY); /* Read 'avail_out' bytes of data from the IDAT stream. If the output buffer *isNULLthefunctionchecks,instead,fortheendofthestream.Inthis *caseabenignerrorwillbeissuedifthestreamendisnotfoundorif *extradatahastobeconsumed.
*/
PNG_INTERNAL_FUNCTION(void, png_read_finish_IDAT,
(png_structrp png_ptr),
PNG_EMPTY); /* This cleans up when the IDAT LZ stream does not end when the last image *byteisread;thereisstillsomependinginput.
*/
PNG_INTERNAL_FUNCTION(void, png_read_finish_row,
(png_structrp png_ptr),
PNG_EMPTY); /* Finish a row while reading, dealing with interlacing passes, etc. */ #endif/* SEQUENTIAL_READ */
/* Initialize the row buffers, etc. */
PNG_INTERNAL_FUNCTION(void, png_read_start_row,
(png_structrp png_ptr),
PNG_EMPTY);
/* The following decodes the appropriate chunks, and does error correction,
* then calls the appropriate callback for the chunk if it is valid.
*/
typedef enum
{
/* Result of a call to png_handle_chunk made to handle the current chunk
* png_struct::chunk_name on read. Always informational, either the stream
* is read for the next chunk or the routine will call png_error.
*
* NOTE: order is important internally. handled_saved and above are regarded
* as handling the chunk.
*/
handled_error = 0, /* bad crc or known and bad format or too long */
handled_discarded, /* not saved in the unknown chunk list */
handled_saved, /* saved in the unknown chunk list */
handled_ok /* known, supported and handled without error */
} png_handle_result_code;
PNG_INTERNAL_FUNCTION(png_handle_result_code, png_handle_unknown,
(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length, int keep),
PNG_EMPTY);
/* This is the function that gets called for unknown chunks. The 'keep'
* argument is either non-zero for a known chunk that has been set to be
* handled as unknown or zero for an unknown chunk. By default the function
* just skips the chunk or errors out if it is critical.
*/
PNG_INTERNAL_FUNCTION(png_handle_result_code, png_handle_chunk,
(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length),
PNG_EMPTY);
/* This handles the current chunk png_ptr->chunk_name with unread
* data[length] and returns one of the above result codes.
*/
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\
defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
PNG_INTERNAL_FUNCTION(int, png_chunk_unknown_handling,
(png_const_structrp png_ptr, png_uint_32 chunk_name),
PNG_EMPTY);
/* Exactly as the API png_handle_as_unknown() except that the argument is a
* 32-bit chunk name, not a string.
*/
#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */
/* Handle the transformations for reading and writing */
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
PNG_INTERNAL_FUNCTION(void, png_do_read_transformations,
(png_structrp png_ptr, png_row_infop row_info),
PNG_EMPTY);
#endif
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
PNG_INTERNAL_FUNCTION(void, png_do_write_transformations,
(png_structrp png_ptr, png_row_infop row_info),
PNG_EMPTY);
#endif
#ifdef PNG_iCCP_SUPPORTED
/* Routines for checking parts of an ICC profile. */
#ifdef PNG_READ_iCCP_SUPPORTED
PNG_INTERNAL_FUNCTION(int, png_icc_check_length,
(png_const_structrp png_ptr,
png_const_charp name, png_uint_32 profile_length),
PNG_EMPTY);
#endif /* READ_iCCP */
PNG_INTERNAL_FUNCTION(int, png_icc_check_header,
(png_const_structrp png_ptr,
png_const_charp name, png_uint_32 profile_length,
png_const_bytep profile /* first 132 bytes only */, int color_type),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(int, png_icc_check_tag_table,
(png_const_structrp png_ptr,
png_const_charp name, png_uint_32 profile_length,
png_const_bytep profile /* header plus whole tag table */),
PNG_EMPTY);
#endif /* iCCP */
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
PNG_INTERNAL_FUNCTION(void, png_set_rgb_coefficients,
(png_structrp png_ptr),
PNG_EMPTY);
/* Set the rgb_to_gray coefficients from the cHRM Y values (if unset) */
#endif /* READ_RGB_TO_GRAY */
/* Added at libpng version 1.4.0 */
PNG_INTERNAL_FUNCTION(void, png_check_IHDR,
(png_const_structrp png_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth, int color_type,
int interlace_type, int compression_type, int filter_type),
PNG_EMPTY);
/* Added at libpng version 1.5.10 */
#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
PNG_INTERNAL_FUNCTION(void, png_do_check_palette_indexes,
(png_structrp png_ptr, png_row_infop row_info),
PNG_EMPTY);
#endif
/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite
* the end. Always leaves the buffer nul terminated. Never errors out (and
* there is no error code.)
*/
PNG_INTERNAL_FUNCTION(size_t, png_safecat,
(png_charp buffer, size_t bufsize, size_t pos, png_const_charp string),
PNG_EMPTY);
/* Various internal functions to handle formatted warning messages, currently
* only implemented for warnings.
*/
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
/* Utility to dump an unsigned value into a buffer, given a start pointer and
* and end pointer (which should point just *beyond* the end of the buffer!)
* Returns the pointer to the start of the formatted string. This utility only
* does unsigned values.
*/
PNG_INTERNAL_FUNCTION(png_charp, png_format_number,
(png_const_charp start, png_charp end, int format, png_alloc_size_t number),
PNG_EMPTY);
/* Convenience macro that takes an array: */
#define PNG_FORMAT_NUMBER(buffer,format,number) \
png_format_number(buffer, buffer + (sizeof buffer), format, number)
/* Suggested size for a number buffer (enough for 64 bits and a sign!) */
#define PNG_NUMBER_BUFFER_SIZE 24
/* These are the integer formats currently supported, the name is formed from
* the standard printf(3) format string.
*/
#define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */
#define PNG_NUMBER_FORMAT_02u 2
#define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */
#define PNG_NUMBER_FORMAT_02d 2
#define PNG_NUMBER_FORMAT_x 3
#define PNG_NUMBER_FORMAT_02x 4
#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */
#endif
#ifdef PNG_WARNINGS_SUPPORTED
/* New defines and members adding in libpng-1.5.4 */
# define PNG_WARNING_PARAMETER_SIZE 32
# define PNG_WARNING_PARAMETER_COUNT 8 /* Maximum 9; see pngerror.c */
/* An l-value of this type has to be passed to the APIs below to cache the
* values of the parameters to a formatted warning message.
*/
typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][
PNG_WARNING_PARAMETER_SIZE];
PNG_INTERNAL_FUNCTION(void, png_warning_parameter,
(png_warning_parameters p, int number, png_const_charp string),
PNG_EMPTY);
/* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters,
* including the trailing '\0'.
*/
PNG_INTERNAL_FUNCTION(void, png_warning_parameter_unsigned,
(png_warning_parameters p, int number, int format, png_alloc_size_t value),
PNG_EMPTY);
/* Use png_alloc_size_t because it is an unsigned type as big as any we
* need to output. Use the following for a signed value.
*/
PNG_INTERNAL_FUNCTION(void, png_warning_parameter_signed,
(png_warning_parameters p, int number, int format, png_int_32 value),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void, png_formatted_warning,
(png_const_structrp png_ptr,
png_warning_parameters p, png_const_charp message),
PNG_EMPTY);
/* 'message' follows the X/Open approach of using @1, @2 to insert
* parameters previously supplied using the above functions. Errors in
* specifying the parameters will simply result in garbage substitutions.
*/
#endif
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
/* Application errors (new in 1.6); use these functions (declared below) for
* errors in the parameters or order of API function calls on read. The
* 'warning' should be used for an error that can be handled completely; the
* 'error' for one which can be handled safely but which may lose application
* information or settings.
*
* By default these both result in a png_error call prior to release, while in a
* released version the 'warning' is just a warning. However if the application
* explicitly disables benign errors (explicitly permitting the code to lose
* information) they both turn into warnings.
*
* If benign errors aren't supported they end up as the corresponding base call
* (png_warning or png_error.)
*/
PNG_INTERNAL_FUNCTION(void, png_app_warning,
(png_const_structrp png_ptr, png_const_charp message),
PNG_EMPTY);
/* The application provided invalid parameters to an API function or called
* an API function at the wrong time, libpng can completely recover.
*/
PNG_INTERNAL_FUNCTION(void, png_app_error,
(png_const_structrp png_ptr, png_const_charp message),
PNG_EMPTY);
/* As above but libpng will ignore the call, or attempt some other partial
* recovery from the error.
*/
#else
# define png_app_warning(pp,s) png_warning(pp,s)
# define png_app_error(pp,s) png_error(pp,s)
#endif
PNG_INTERNAL_FUNCTION(void, png_chunk_report,
(png_const_structrp png_ptr, png_const_charp message, int error),
PNG_EMPTY);
/* Report a recoverable issue in chunk data. On read this is used to report
* a problem found while reading a particular chunk and the
* png_chunk_benign_error or png_chunk_warning function is used as
* appropriate. On write this is used to report an error that comes from
* data set via an application call to a png_set_ API and png_app_error or
* png_app_warning is used as appropriate.
*
* The 'error' parameter must have one of the following values:
*/
#define PNG_CHUNK_WARNING 0 /* never an error */
#define PNG_CHUNK_WRITE_ERROR 1 /* an error only on write */
#define PNG_CHUNK_ERROR 2 /* always an error */
/* ASCII to FP interfaces, currently only implemented if sCAL
* support is required.
*/
#if defined(PNG_sCAL_SUPPORTED)
/* MAX_DIGITS is actually the maximum number of characters in an sCAL
* width or height, derived from the precision (number of significant
* digits - a build time settable option) and assumptions about the
* maximum ridiculous exponent.
*/
#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)
#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
/* An internal API to validate the format of a floating point number.
* The result is the index of the next character. If the number is
* not valid it will be the index of a character in the supposed number.
*
* The format of a number is defined in the PNG extensions specification
* and this API is strictly conformant to that spec, not anyone else's!
*
* The format as a regular expression is:
*
* [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
*
* or:
*
* [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
*
* The complexity is that either integer or fraction must be present and the
* fraction is permitted to have no digits only if the integer is present.
*
* NOTE: The dangling E problem.
* There is a PNG valid floating point number in the following:
*
* PNG floating point numbers are not greedy.
*
* Working this out requires *TWO* character lookahead (because of the
* sign), the parser does not do this - it will fail at the 'r' - this
* doesn't matter for PNG sCAL chunk values, but it requires more care
* if the value were ever to be embedded in something more complex. Use
* ANSI-C strtod if you need the lookahead.
*/
/* State table for the parser. */
#define PNG_FP_INTEGER 0 /* before or in integer */
#define PNG_FP_FRACTION 1 /* before or in fraction */
#define PNG_FP_EXPONENT 2 /* before or in exponent */
#define PNG_FP_STATE 3 /* mask for the above */
#define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */
#define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */
#define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */
#define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */
#define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */
/* These three values don't affect the parser. They are set but not used.
*/
#define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */
#define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */
#define PNG_FP_NONZERO 256 /* A non-zero value */
#define PNG_FP_STICKY 448 /* The above three flags */
/* This is available for the caller to store in 'state' if required. Do not
* call the parser after setting it (the parser sometimes clears it.)
*/
#define PNG_FP_INVALID 512 /* Available for callers as a distinct value */
/* Result codes for the parser (boolean - true means ok, false means
* not ok yet.)
*/
#define PNG_FP_MAYBE 0 /* The number may be valid in the future */
#define PNG_FP_OK 1 /* The number is valid */
/* Tests on the sticky non-zero and negative flags. To pass these checks
* the state must also indicate that the whole number is valid - this is
* achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this
* is equivalent to PNG_FP_OK above.)
*/
#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO)
/* NZ_MASK: the string is valid and a non-zero negative value */
#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO)
/* Z MASK: the string is valid and a non-zero value. */
/* PNG_FP_SAW_DIGIT: the string is valid. */
#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT)
#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)
#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)
/* The actual parser. This can be called repeatedly. It updates
* the index into the string and the state variable (which must
* be initialized to 0). It returns a result code, as above. There
* is no point calling the parser any more if it fails to advance to
* the end of the string - it is stuck on an invalid character (or
* terminated by '\0').
*
* Note that the pointer will consume an E or even an E+ and then leave
* a 'maybe' state even though a preceding integer.fraction is valid.
* The PNG_FP_WAS_VALID flag indicates that a preceding substring was
* a valid number. It's possible to recover from this by calling
* the parser again (from the start, with state 0) but with a string
* that omits the last character (i.e. set the size to the index of
* the problem character.) This has not been tested within libpng.
*/
PNG_INTERNAL_FUNCTION(int, png_check_fp_number,
(png_const_charp string, size_t size, int *statep, size_t *whereami),
PNG_EMPTY);
/* This is the same but it checks a complete string and returns true
* only if it just contains a floating point number. As of 1.5.4 this
* function also returns the state at the end of parsing the number if
* it was valid (otherwise it returns 0.) This can be used for testing
* for negative or zero values using the sticky flag.
*/
PNG_INTERNAL_FUNCTION(int, png_check_fp_string,
(png_const_charp string, size_t size),
PNG_EMPTY);
#endif /* pCAL || sCAL */
#if defined(PNG_READ_GAMMA_SUPPORTED) ||\
defined(PNG_COLORSPACE_SUPPORTED) ||\
defined(PNG_INCH_CONVERSIONS_SUPPORTED) ||\
defined(PNG_READ_pHYs_SUPPORTED)
/* Added at libpng version 1.5.0 */
/* This is a utility to provide a*times/div (rounded) and indicate
* if there is an overflow. The result is a boolean - false (0)
* for overflow, true (1) if no overflow, in which case *res
* holds the result.
*/
PNG_INTERNAL_FUNCTION(int, png_muldiv,
(png_fixed_point_p res, png_fixed_point a,
png_int_32 multiplied_by, png_int_32 divided_by),
PNG_EMPTY);
/* Calculate a reciprocal - used for gamma values. This returns
* 0 if the argument is 0 in order to maintain an undefined value;
* there are no warnings.
*/
PNG_INTERNAL_FUNCTION(png_fixed_point, png_reciprocal,
(png_fixed_point a),
PNG_EMPTY);
#endif
#ifdef PNG_READ_GAMMA_SUPPORTED
/* The same but gives a reciprocal of the product of two fixed point
* values. Accuracy is suitable for gamma calculations but this is
* not exact - use png_muldiv for that. Only required at present on read.
*/
PNG_INTERNAL_FUNCTION(png_fixed_point, png_reciprocal2,
(png_fixed_point a, png_fixed_point b),
PNG_EMPTY);
/* Return true if the gamma value is significantly different from 1.0 */
PNG_INTERNAL_FUNCTION(int, png_gamma_significant,
(png_fixed_point gamma_value),
PNG_EMPTY);
/* PNGv3: 'resolve' the file gamma according to the new PNGv3 rules for colour
* space information.
*
* NOTE: this uses precisely those chunks that libpng supports. For example it
* doesn't use iCCP and it can only use cICP for known and manageable
* transforms. For this reason a gamma specified by png_set_gamma always takes
* precedence.
*/
PNG_INTERNAL_FUNCTION(png_fixed_point, png_resolve_file_gamma,
(png_const_structrp png_ptr),
PNG_EMPTY);
/* Internal fixed point gamma correction. These APIs are called as
* required to convert single values - they don't need to be fast,
* they are not used when processing image pixel values.
*
* While the input is an 'unsigned' value it must actually be the
* correct bit value - 0..255 or 0..65535 as required.
*/
PNG_INTERNAL_FUNCTION(png_uint_16, png_gamma_correct,
(png_structrp png_ptr, unsigned int value, png_fixed_point gamma_value),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(png_uint_16, png_gamma_16bit_correct,
(unsigned int value, png_fixed_point gamma_value),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(png_byte, png_gamma_8bit_correct,
(unsigned int value, png_fixed_point gamma_value),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void, png_destroy_gamma_table,
(png_structrp png_ptr),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void, png_build_gamma_table,
(png_structrp png_ptr, int bit_depth),
PNG_EMPTY);
#endif /* READ_GAMMA */
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
/* Set the RGB coefficients if not already set by png_set_rgb_to_gray */
PNG_INTERNAL_FUNCTION(void, png_set_rgb_coefficients,
(png_structrp png_ptr),
PNG_EMPTY);
#endif
/* SIMPLIFIED READ/WRITE SUPPORT */
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
/* The internal structure that png_image::opaque points to. */
typedef struct png_control
{
png_structp png_ptr;
png_infop info_ptr;
png_voidp error_buf; /* Always a jmp_buf at present. */
png_const_bytep memory; /* Memory buffer. */
size_t size; /* Size of the memory buffer. */
unsigned int for_write :1; /* Otherwise it is a read structure */
unsigned int owned_file :1; /* We own the file in io_ptr */
} png_control;
/* Return the pointer to the jmp_buf from a png_control: necessary because C
* does not reveal the type of the elements of jmp_buf.
*/
#ifdef __cplusplus
# define png_control_jmp_buf(pc) (((jmp_buf*)((pc)->error_buf))[0])
#else
# define png_control_jmp_buf(pc) ((pc)->error_buf)
#endif
/* Utility to safely execute a piece of libpng code catching and logging any
* errors that might occur. Returns true on success, false on failure (either
* of the function or as a result of a png_error.)
*/
PNG_INTERNAL_CALLBACK(void, png_safe_error,
(png_structp png_ptr, png_const_charp error_message),
PNG_NORETURN);
PNG_INTERNAL_FUNCTION(int, png_safe_execute,
(png_imagep image, int (*function)(png_voidp), png_voidp arg),
PNG_EMPTY);
/* Utility to log an error; this also cleans up the png_image; the function
* always returns 0 (false).
*/
PNG_INTERNAL_FUNCTION(int, png_image_error,
(png_imagep image, png_const_charp error_message),
PNG_EMPTY);
#ifndef PNG_SIMPLIFIED_READ_SUPPORTED
/* png_image_free is used by the write code but not exported */
PNG_INTERNAL_FUNCTION(void, png_image_free,
(png_imagep image),
PNG_EMPTY);
#endif /* !SIMPLIFIED_READ */
#endif /* SIMPLIFIED READ/WRITE */
/* These are initialization functions for hardware specific PNG filter
* optimizations; list these here then select the appropriate one at compile
* time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined
* the generic code is used.
*/
#ifdef PNG_FILTER_OPTIMIZATIONS
PNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS,
(png_structp png_ptr, unsigned int bpp),
PNG_EMPTY);
/* Just declare the optimization that will be used */
#else
/* List *all* the possible optimizations here - this branch is required if
* the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in
* CFLAGS in place of CPPFLAGS *and* uses symbol prefixing.
*/
# if PNG_ARM_NEON_OPT > 0
PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
(png_structp png_ptr, unsigned int bpp),
PNG_EMPTY);
#endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.