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/png.h
Views: 1401
1/* png.h - header file for PNG reference library2*3* libpng version 1.7.0beta90, August 28, 20174*5* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson6* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)7* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)8*9* This code is released under the libpng license (See LICENSE, below)10*11* Authors and maintainers:12* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat13* libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger14* libpng versions 0.97, January 1998, through 1.7.0beta90, August 28, 2017:15* Glenn Randers-Pehrson.16* See also "Contributing Authors", below.17*/1819/*20* COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:21*22* If you modify libpng you may insert additional notices immediately following23* this sentence.24*25* This code is released under the libpng license.26*27* libpng versions 1.0.7, July 1, 2000 through 1.7.0beta90, August 28, 2017 are28* Copyright (c) 2000-2002, 2004, 2006-2017 Glenn Randers-Pehrson, are29* derived from libpng-1.0.6, and are distributed according to the same30* disclaimer and license as libpng-1.0.6 with the following individuals31* added to the list of Contributing Authors:32*33* Simon-Pierre Cadieux34* Eric S. Raymond35* Mans Rullgard36* Cosmin Truta37* Gilles Vollant38* James Yu39*40* and with the following additions to the disclaimer:41*42* There is no warranty against interference with your enjoyment of the43* library or against infringement. There is no warranty that our44* efforts or the library will fulfill any of your particular purposes45* or needs. This library is provided with all faults, and the entire46* risk of satisfactory quality, performance, accuracy, and effort is with47* the user.48*49* Some files in the "contrib" directory and some configure-generated50* files that are distributed with libpng have other copyright owners and51* are released under other open source licenses.52*53* libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are54* Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from55* libpng-0.96, and are distributed according to the same disclaimer and56* license as libpng-0.96, with the following individuals added to the list57* of Contributing Authors:58*59* Tom Lane60* Glenn Randers-Pehrson61* Willem van Schaik62*63* libpng versions 0.89, June 1996, through 0.96, May 1997, are64* Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,65* and are distributed according to the same disclaimer and license as66* libpng-0.88, with the following individuals added to the list of67* Contributing Authors:68*69* John Bowler70* Kevin Bracey71* Sam Bushell72* Magnus Holmgren73* Greg Roelofs74* Tom Tanner75*76* Some files in the "scripts" directory have other copyright owners77* but are released under this license.78*79* libpng versions 0.5, May 1995, through 0.88, January 1996, are80* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.81*82* For the purposes of this copyright and license, "Contributing Authors"83* is defined as the following set of individuals:84*85* Andreas Dilger86* Dave Martindale87* Guy Eric Schalnat88* Paul Schmidt89* Tim Wegner90*91* The PNG Reference Library is supplied "AS IS". The Contributing Authors92* and Group 42, Inc. disclaim all warranties, expressed or implied,93* including, without limitation, the warranties of merchantability and of94* fitness for any purpose. The Contributing Authors and Group 42, Inc.95* assume no liability for direct, indirect, incidental, special, exemplary,96* or consequential damages, which may result from the use of the PNG97* Reference Library, even if advised of the possibility of such damage.98*99* Permission is hereby granted to use, copy, modify, and distribute this100* source code, or portions hereof, for any purpose, without fee, subject101* to the following restrictions:102*103* 1. The origin of this source code must not be misrepresented.104*105* 2. Altered versions must be plainly marked as such and must not106* be misrepresented as being the original source.107*108* 3. This Copyright notice may not be removed or altered from any109* source or altered source distribution.110*111* The Contributing Authors and Group 42, Inc. specifically permit, without112* fee, and encourage the use of this source code as a component to113* supporting the PNG file format in commercial products. If you use this114* source code in a product, acknowledgment is not required but would be115* appreciated.116*117* END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.118*119* TRADEMARK:120*121* The name "libpng" has not been registered by the Copyright owner122* as a trademark in any jurisdiction. However, because libpng has123* been distributed and maintained world-wide, continually since 1995,124* the Copyright owner claims "common-law trademark protection" in any125* jurisdiction where common-law trademark is recognized.126*127* OSI CERTIFICATION:128*129* Libpng is OSI Certified Open Source Software. OSI Certified Open Source is130* a certification mark of the Open Source Initiative. OSI has not addressed131* the additional disclaimers inserted at version 1.0.7.132*133* EXPORT CONTROL:134*135* The Copyright owner believes that the Export Control Classification136* Number (ECCN) for libpng is EAR99, which means not subject to export137* controls or International Traffic in Arms Regulations (ITAR) because138* it is open source, publicly available software, that does not contain139* any encryption software. See the EAR, paragraphs 734.3(b)(3) and140* 734.7(b).141*/142143/*144* A "png_get_copyright" function is available, for convenient use in "about"145* boxes and the like:146*147* printf("%s", png_get_copyright(NULL));148*149* Also, the PNG logo (in PNG format, of course) is supplied in the150* files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).151*/152153/*154* The contributing authors would like to thank all those who helped155* with testing, bug fixes, and patience. This wouldn't have been156* possible without all of you.157*158* Thanks to Frank J. T. Wojcik for helping with the documentation.159*/160161/* Note about libpng version numbers:162*163* Due to various miscommunications, unforeseen code incompatibilities164* and occasional factors outside the authors' control, version numbering165* on the library has not always been consistent and straightforward.166* The following table summarizes matters since version 0.89c, which was167* the first widely used release:168*169* source png.h png.h shared-lib170* version string int version171* ------- ------ ----- ----------172* 0.89c "1.0 beta 3" 0.89 89 1.0.89173* 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90]174* 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95]175* 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96]176* 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97]177* 0.97c 0.97 97 2.0.97178* 0.98 0.98 98 2.0.98179* 0.99 0.99 98 2.0.99180* 0.99a-m 0.99 99 2.0.99181* 1.00 1.00 100 2.1.0 [100 should be 10000]182* 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000]183* 1.0.1 png.h string is 10001 2.1.0184* 1.0.1a-e identical to the 10002 from here on, the shared library185* 1.0.2 source version) 10002 is 2.V where V is the source code186* 1.0.2a-b 10003 version, except as noted.187* 1.0.3 10003188* 1.0.3a-d 10004189* 1.0.4 10004190* 1.0.4a-f 10005191* 1.0.5 (+ 2 patches) 10005192* 1.0.5a-d 10006193* 1.0.5e-r 10100 (not source compatible)194* 1.0.5s-v 10006 (not binary compatible)195* 1.0.6 (+ 3 patches) 10006 (still binary incompatible)196* 1.0.6d-f 10007 (still binary incompatible)197* 1.0.6g 10007198* 1.0.6h 10007 10.6h (testing xy.z so-numbering)199* 1.0.6i 10007 10.6i200* 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0)201* 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible)202* 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible)203* 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible)204* 1.0.7 1 10007 (still compatible)205* ...206* 1.0.19 10 10019 10.so.0.19[.0]207* ...208* 1.2.56 13 10253 12.so.0.53[.0]209* ...210* 1.5.27 15 10523 15.so.15.23[.0]211* ...212* 1.6.22 16 10622 16.so.16.22[.0]213* ...214* 1.7.0alpha01-10 17 10700 17.so.17.0[.0]215* 1.7.0beta01-84 17 10700 17.so.17.0[.0]216*217* Henceforth the source version will match the shared-library major218* and minor numbers; the shared-library major version number will be219* used for changes in backward compatibility, as it is intended. The220* PNG_LIBPNG_VER macro, which is not used within libpng but is available221* for applications, is an unsigned integer of the form xyyzz corresponding222* to the source version x.y.z (leading zeros in y and z). Beta versions223* were given the previous public release number plus a letter, until224* version 1.0.6j; from then on they were given the upcoming public225* release number plus "betaNN" or "rcNN".226*227* Binary incompatibility exists only when applications make direct access228* to the info_ptr or png_ptr members through png.h, and the compiled229* application is loaded with a different version of the library.230*231* DLLNUM will change each time there are forward or backward changes232* in binary compatibility (e.g., when a new feature is added).233*234* See libpng.txt or libpng.3 for more information. The PNG specification235* is available as a W3C Recommendation and as an ISO Specification,236* <https://www.w3.org/TR/2003/REC-PNG-20031110/237*/238239/*240* Y2K compliance in libpng:241* =========================242*243* August 28, 2017244*245* Since the PNG Development group is an ad-hoc body, we can't make246* an official declaration.247*248* This is your unofficial assurance that libpng from version 0.71 and249* upward through 1.7.0beta90 are Y2K compliant. It is my belief that250* earlier versions were also Y2K compliant.251*252* Libpng only has two year fields. One is a 2-byte unsigned integer253* that will hold years up to 65535. The other, which is deprecated,254* holds the date in text format, and will hold years up to 9999.255*256* The integer is257* "png_uint_16 year" in png_time_struct.258*259* The string is260* "char time_buffer[29]" in png_struct. This is no longer used261* in libpng-1.6.x and will be removed from libpng-1.7.0.262*263* There are seven time-related functions:264* png.c: png_convert_to_rfc_1123_buffer() in png.c265* (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and266* png_convert_to_rfc_1152() in error prior to libpng-0.98)267* png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c268* png_convert_from_time_t() in pngwrite.c269* png_get_tIME() in pngget.c270* png_handle_tIME() in pngrutil.c, called in pngread.c271* png_set_tIME() in pngset.c272* png_write_tIME() in pngwutil.c, called in pngwrite.c273*274* All handle dates properly in a Y2K environment. The275* png_convert_from_time_t() function calls gmtime() to convert from system276* clock time, which returns (year - 1900), which we properly convert to277* the full 4-digit year. There is a possibility that libpng applications278* are not passing 4-digit years into the png_convert_to_rfc_1123_buffer()279* function, or that they are incorrectly passing only a 2-digit year280* instead of "year - 1900" into the png_convert_from_struct_tm() function,281* but this is not under our control. The libpng documentation has always282* stated that it works with 4-digit years, and the APIs have been283* documented as such.284*285* The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned286* integer to hold the year, and can hold years as large as 65535.287*288* zlib, upon which libpng depends, is also Y2K compliant. It contains289* no date-related code.290*291* Glenn Randers-Pehrson292* libpng maintainer293* PNG Development Group294*/295296#ifndef PNG_H297#define PNG_H298299/* This is not the place to learn how to use libpng. The file libpng-manual.txt300* describes how to use libpng, and the file example.c summarizes it301* with some code on which to build. This file is useful for looking302* at the actual function definitions and structure components. If that303* file has been stripped from your copy of libpng, you can find it at304* <http://www.libpng.org/pub/png/libpng-manual.txt>305*306* If you just need to read a PNG file and don't want to read the documentation307* skip to the end of this file and read the section entitled 'simplified API'.308*/309310/* Version information for png.h - this should match the version in png.c */311#define PNG_LIBPNG_VER_STRING "1.7.0beta90"312#define PNG_HEADER_VERSION_STRING " libpng version 1.7.0beta90 - August 28, 2017\n"313314#define PNG_LIBPNG_VER_SONUM 17315#define PNG_LIBPNG_VER_DLLNUM 17316317/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */318#define PNG_LIBPNG_VER_MAJOR 1319#define PNG_LIBPNG_VER_MINOR 7320#define PNG_LIBPNG_VER_RELEASE 0321322/* This should match the numeric part of the final component of323* PNG_LIBPNG_VER_STRING, omitting any leading zero:324*/325326#define PNG_LIBPNG_VER_BUILD 90327328/* Release Status */329#define PNG_LIBPNG_BUILD_ALPHA 1330#define PNG_LIBPNG_BUILD_BETA 2331#define PNG_LIBPNG_BUILD_RC 3332#define PNG_LIBPNG_BUILD_STABLE 4333#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7334335/* Release-Specific Flags */336#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with337PNG_LIBPNG_BUILD_STABLE only */338#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with339PNG_LIBPNG_BUILD_SPECIAL */340#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with341PNG_LIBPNG_BUILD_PRIVATE */342343#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA344345/* Careful here. At one time, Guy wanted to use 082, but that would be octal.346* We must not include leading zeros.347* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only348* version 1.0.0 was mis-numbered 100 instead of 10000). From349* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release350*/351#define PNG_LIBPNG_VER 10700 /* 1.7.0 */352353/* Library configuration: these options cannot be changed after354* the library has been built.355*/356#ifndef PNGLCONF_H357/* If pnglibconf.h is missing, you can358* copy scripts/pnglibconf.h.prebuilt to pnglibconf.h359*/360# include "pnglibconf.h"361#endif362363#ifndef PNG_VERSION_INFO_ONLY364/* Machine specific configuration. */365# include "pngconf.h"366#endif367368/*369* Added at libpng-1.2.8370*371* Ref MSDN: Private as priority over Special372* VS_FF_PRIVATEBUILD File *was not* built using standard release373* procedures. If this value is given, the StringFileInfo block must374* contain a PrivateBuild string.375*376* VS_FF_SPECIALBUILD File *was* built by the original company using377* standard release procedures but is a variation of the standard378* file of the same version number. If this value is given, the379* StringFileInfo block must contain a SpecialBuild string.380*/381382#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */383# define PNG_LIBPNG_BUILD_TYPE \384(PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)385#else386# ifdef PNG_LIBPNG_SPECIALBUILD387# define PNG_LIBPNG_BUILD_TYPE \388(PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)389# else390# define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)391# endif392#endif393394#ifndef PNG_VERSION_INFO_ONLY395396/* Version information for C files, stored in png.c. This had better match397* the version above.398*/399#define png_libpng_ver png_get_header_ver(NULL)400401/* This file is arranged in several sections:402*403* 1. ISO-PNG constants and definitions; values defined by PNG and not specific404* to the libpng API.405* 2. Any configuration options that can be specified by for the application406* code when it is built. (Build time configuration is in pnglibconf.h)407* 3. Type definitions (base types are defined in pngconf.h), structure408* definitions.409* 4. Exported library functions.410* 5. Simplified API.411* 6. Implementation options412*413* The library source code has additional files (principally pngpriv.h) that414* allow configuration of the library.415*/416417/* Section 1: ISO PNG constants and macros. */418419/* ISO-PNG defines byte encodings for 16 and 32-bit unsigned values and 32-bit420* signed values. The macros PNG_U16, PNG_U32 and PNG_S32 return values of type421* (png_uint_16), (png_uint_32) and (png_int_32) which are target machine422* specific representations of these values, using the types defined in423* pngconf.h. The macros take two or four byte values in the order in which424* they would occur in a PNG stream.425*426* These macros must return compile time constants if passed constant values -427* machine specific implementations are not permitted. These macros are used by428* default in the API functions/macros png_get_uint_16, png_get_uint_32,429* png_get_uint_31 and png_get_int_32 declared below: these functions or macros430* are the correct places for machine specific implementations (such as hardware431* specific instructions.)432*433* The macros defined here are generic and intended to give maximum flexibility434* in implementation to the compiler; only PNG_S32 contains a sequence point,435* there are no side effects and the expressions used permit the maximum436* parallelization (relevant because the four bytes may be loaded in parallel.)437*/438#define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))439440#define PNG_U16(b1, b2) ((png_uint_16)/*SAFE*/PNG_u2(b1, b2))441#define PNG_U32(b1, b2, b3, b4)\442(((png_uint_32)/*SAFE*/PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))443444/* ISO-PNG states that signed 32-bit values are stored in two's complement445* format. There is no guarantee that (png_int_32) is exactly 32 bits, so the446* following macro tests for a negative number and generates the machine format447* directly by portable arithmetic operations. The cost is that the argument448* 'b1' is evaluated twice.449*450* NOTE: the 0x7fffffffU BIC is there to ensure that potential overflow in the451* cast does not occur. This fixes the case where 1's complement machines could452* be forced into an overflow by an invalid value in the stream and, therefore,453* potentially raise an arithmetic exception; the invalid value is converted to454* 0 and any resultant problems will be caught later in the libpng checking.455*/456#define PNG_S32(b1, b2, b3, b4) ((b1) & 0x80\457? -(png_int_32)(((PNG_U32(b1, b2, b3, b4)^0xffffffffU)+1U)&0x7fffffffU)\458: (png_int_32)PNG_U32(b1, b2, b3, b4))459460/* Constants for known chunk types.461*462* MAINTAINERS: If you need to add a chunk, define the name here.463* For historical reasons these constants have the form png_<name>; i.e.464* the prefix is lower case. Please use decimal values as the parameters to465* match the ISO PNG specification and to avoid relying on the C locale466* interpretation of character values. Please keep the list sorted.467*468* Notice that PNG_U32 is used to define a 32-bit value for the 4 byte chunk469* type. In fact the specification does not express chunk types this way,470* however using a 32-bit value means that the chunk type can be read from the471* stream using exactly the same code as used for a 32-bit unsigned value and472* can be examined far more efficiently (using one arithmetic compare).473*474* Prior to 1.5.6 the chunk type constants were expressed as C strings. The475* libpng API still uses strings for 'unknown' chunks and a macro,476* PNG_STRING_FROM_CHUNK, allows a string to be generated if required. Notice477* that for portable code numeric values must still be used; the string "IHDR"478* is not portable and neither is PNG_U32('I', 'H', 'D', 'R').479*480* In 1.7.0 the definitions were made public in png.h to avoid having to481* duplicate the same definitions in application code.482*483* SOURCE: http://www.libpng.org/pub/png/spec/register/484* "Register of PNG Public Chunks and Keywords, version 1.4.6"485* "Extensions to the PNG Specification, version 1.4.0"486*/487#define png_IDAT PNG_U32( 73, 68, 65, 84)488#define png_IEND PNG_U32( 73, 69, 78, 68)489#define png_IHDR PNG_U32( 73, 72, 68, 82)490#define png_PLTE PNG_U32( 80, 76, 84, 69)491#define png_bKGD PNG_U32( 98, 75, 71, 68)492#define png_cHRM PNG_U32( 99, 72, 82, 77)493#define png_dSIG PNG_U32(100, 83, 73, 71) /* separate spec */494#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */495#define png_gAMA PNG_U32(103, 65, 77, 65)496#define png_gIFg PNG_U32(103, 73, 70, 103)497#define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */498#define png_gIFx PNG_U32(103, 73, 70, 120)499#define png_hIST PNG_U32(104, 73, 83, 84)500#define png_iCCP PNG_U32(105, 67, 67, 80)501#define png_iTXt PNG_U32(105, 84, 88, 116)502#define png_oFFs PNG_U32(111, 70, 70, 115)503#define png_pCAL PNG_U32(112, 67, 65, 76)504#define png_pHYs PNG_U32(112, 72, 89, 115)505#define png_sBIT PNG_U32(115, 66, 73, 84)506#define png_sCAL PNG_U32(115, 67, 65, 76)507#define png_sPLT PNG_U32(115, 80, 76, 84)508#define png_sRGB PNG_U32(115, 82, 71, 66)509#define png_sTER PNG_U32(115, 84, 69, 82)510#define png_tEXt PNG_U32(116, 69, 88, 116)511#define png_tIME PNG_U32(116, 73, 77, 69)512#define png_tRNS PNG_U32(116, 82, 78, 83)513#define png_zTXt PNG_U32(122, 84, 88, 116)514515/* The following will work on (signed char*) strings, whereas the PNG_U32 macro516* used directory would fail on top-bit-set values because of the sign517* extension.518*/519#define PNG_CHUNK_FROM_STRING(s)\520PNG_U32(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3])521522/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is523* signed and the argument is a (char[]) This macro will fail miserably on524* systems where (char) is more than 8 bits.525*/526#define PNG_STRING_FROM_CHUNK(s,c)\527(void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \528((char*)(s))[1]=(char)(((c)>>16) & 0xff),\529((char*)(s))[2]=(char)(((c)>>8) & 0xff), \530((char*)(s))[3]=(char)((c & 0xff)))531532/* Do the same but terminate with a null character. */533#define PNG_CSTRING_FROM_CHUNK(s,c)\534(void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)535536/* Test on flag values as defined in the spec (section 5.4): */537#define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29))538#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c))539#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))540#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))541#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))542543/* Section 2: run time configuration544* See pnglibconf.h for build time configuration545*546* Run time configuration allows the application to choose between547* implementations of certain arithmetic APIs. The default is set548* at build time and recorded in pnglibconf.h, but it is safe to549* override these (and only these) settings. Note that this won't550* change what the library does, only application code, and the551* settings can (and probably should) be made on a per-file basis552* by setting the #defines before including png.h553*554* Use macros to read integers from PNG data or use the exported555* functions?556* PNG_USE_READ_MACROS: use the macros (see below) Note that557* the macros evaluate their argument multiple times.558* PNG_NO_USE_READ_MACROS: call the relevant library function.559*560* Use the alternative algorithm for compositing alpha samples that561* does not use division?562* PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division'563* algorithm.564* PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm.565*566* How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is567* false?568* PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error569* APIs to png_warning.570* Otherwise the calls are mapped to png_error.571*/572573/* Inhibit C++ name-mangling for libpng functions but not for system calls. */574#ifdef __cplusplus575extern "C" {576#endif /* __cplusplus */577578/* Section 3: type definitions, including structures and compile time579* constants.580* See pngconf.h for base types that vary by machine/system581*/582583/* This triggers a compiler error in png.c, if png.c and png.h584* do not agree upon the version number.585*/586typedef char* png_libpng_version_1_7_0beta90;587588/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.589*590* png_struct is the cache of information used while reading or writing a single591* PNG file. One of these is always required, although the simplified API592* (below) hides the creation and destruction of it.593*/594typedef struct png_struct_def png_struct;595typedef const png_struct * png_const_structp;596typedef png_struct * png_structp;597typedef png_struct * * png_structpp;598599/* png_info contains information read from or to be written to a PNG file. One600* or more of these must exist while reading or creating a PNG file. The601* information is not used by libpng during read but is used to control what602* gets written when a PNG file is created. "png_get_" function calls read603* information during read and "png_set_" functions calls write information604* when creating a PNG.605* been moved into a separate header file that is not accessible to606* applications. Read libpng-manual.txt or libpng.3 for more info.607*/608typedef struct png_info_def png_info;609typedef png_info * png_infop;610typedef const png_info * png_const_infop;611typedef png_info * * png_infopp;612613/* Types with names ending 'p' are pointer types. The corresponding types with614* names ending 'rp' are identical pointer types except that the pointer is615* marked 'restrict', which means that it is the only pointer to the object616* passed to the function. Applications should not use the 'restrict' types;617* it is always valid to pass 'p' to a pointer with a function argument of the618* corresponding 'rp' type. Different compilers have different rules with619* regard to type matching in the presence of 'restrict'. For backward620* compatibility libpng callbacks never have 'restrict' in their parameters and,621* consequentially, writing portable application code is extremely difficult if622* an attempt is made to use 'restrict'.623*/624typedef png_struct * PNG_RESTRICT png_structrp;625typedef const png_struct * PNG_RESTRICT png_const_structrp;626typedef png_info * PNG_RESTRICT png_inforp;627typedef const png_info * PNG_RESTRICT png_const_inforp;628629/* Three color definitions. The order of the red, green, and blue, (and the630* exact size) is not important, although the size of the fields need to631* be png_byte or png_uint_16 (as defined below).632*/633typedef struct png_color_struct634{635png_byte red;636png_byte green;637png_byte blue;638} png_color;639typedef png_color * png_colorp;640typedef const png_color * png_const_colorp;641typedef png_color * * png_colorpp;642643typedef struct png_color_16_struct644{645png_byte index; /* used for palette files */646png_uint_16 red; /* for use in red green blue files */647png_uint_16 green;648png_uint_16 blue;649png_uint_16 gray; /* for use in grayscale files */650} png_color_16;651typedef png_color_16 * png_color_16p;652typedef const png_color_16 * png_const_color_16p;653typedef png_color_16 * * png_color_16pp;654655typedef struct png_color_8_struct656{657png_byte red; /* for use in red green blue files */658png_byte green;659png_byte blue;660png_byte gray; /* for use in grayscale files */661png_byte alpha; /* for alpha channel files */662} png_color_8;663typedef png_color_8 * png_color_8p;664typedef const png_color_8 * png_const_color_8p;665typedef png_color_8 * * png_color_8pp;666667/*668* The following two structures are used for the in-core representation669* of sPLT chunks.670*/671typedef struct png_sPLT_entry_struct672{673png_uint_16 red;674png_uint_16 green;675png_uint_16 blue;676png_uint_16 alpha;677png_uint_16 frequency;678} png_sPLT_entry;679typedef png_sPLT_entry * png_sPLT_entryp;680typedef const png_sPLT_entry * png_const_sPLT_entryp;681typedef png_sPLT_entry * * png_sPLT_entrypp;682683/* When the depth of the sPLT palette is 8 bits, the color and alpha samples684* occupy the LSB of their respective members, and the MSB of each member685* is zero-filled. The frequency member always occupies the full 16 bits.686*/687688typedef struct png_sPLT_struct689{690png_charp name; /* palette name */691png_byte depth; /* depth of palette samples */692png_sPLT_entryp entries; /* palette entries */693png_int_32 nentries; /* number of palette entries */694} png_sPLT_t;695typedef png_sPLT_t * png_sPLT_tp;696typedef const png_sPLT_t * png_const_sPLT_tp;697typedef png_sPLT_t * * png_sPLT_tpp;698699#ifdef PNG_TEXT_SUPPORTED700/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,701* and whether that contents is compressed or not. The "key" field702* points to a regular zero-terminated C string. The "text" fields can be a703* regular C string, an empty string, or a NULL pointer.704* However, the structure returned by png_get_text() will always contain705* the "text" field as a regular zero-terminated C string (possibly706* empty), never a NULL pointer, so it can be safely used in printf() and707* other string-handling functions. Note that the "itxt_length", "lang", and708* "lang_key" members of the structure only exist when the library is built709* with iTXt chunk support. Prior to libpng-1.4.0 the library was built by710* default without iTXt support. Also note that when iTXt *is* supported,711* the "lang" and "lang_key" fields contain NULL pointers when the712* "compression" field contains * PNG_TEXT_COMPRESSION_NONE or713* PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the714* same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag"715* which is always 0 or 1, or its "compression method" which is always 0.716*717* The location field (added in libpng 1.7.0) records where the text chunk was718* found when png_get_text is used. When png_set_text is used the field in the719* structure passed in is ignored and, instead, the field is set to the current720* write position.721*722* Prior to 1.7.0 the write behavior was the same; the text fields were written723* (once) at the next write_info call, however the read mechanism did not record724* the chunk location so if an info_struct from read was passed to the write725* APIs the text chunks would all be written at the start (before PLTE).726*/727typedef struct png_text_struct728{729int compression; /* compression value:730-1: tEXt, none7310: zTXt, deflate7321: iTXt, none7332: iTXt, deflate */734png_byte location; /* 1: PNG_HAVE_IHDR7352: PNG_HAVE_PLTE7368: PNG_AFTER_IDAT */737png_charp key; /* keyword, 1-79 character description of "text" */738png_charp text; /* comment, may be an empty string (ie "")739or a NULL pointer */740size_t text_length; /* length of the text string */741size_t itxt_length; /* length of the itxt string */742png_charp lang; /* language code, 0-79 characters743or a NULL pointer */744png_charp lang_key; /* keyword translated UTF-8 string, 0 or more745chars or a NULL pointer */746} png_text;747typedef png_text * png_textp;748typedef const png_text * png_const_textp;749typedef png_text * * png_textpp;750#endif751752/* Supported compression types for text in PNG files (tEXt, and zTXt).753* The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */754#ifdef PNG_OLD_COMPRESSION_CODES_SUPPORTED755/* These values were used to prevent double write of text chunks in versions756* prior to 1.7.0. They are never set now; if you need them #define the757* _SUPPORTED macro.758*/759#define PNG_TEXT_COMPRESSION_NONE_WR -3760#define PNG_TEXT_COMPRESSION_zTXt_WR -2761#endif /* OLD_COMPRESSION_CODES */762#define PNG_TEXT_COMPRESSION_NONE -1763#define PNG_TEXT_COMPRESSION_zTXt 0764#define PNG_ITXT_COMPRESSION_NONE 1765#define PNG_ITXT_COMPRESSION_zTXt 2766#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */767768/* png_time is a way to hold the time in an machine independent way.769* Two conversions are provided, both from time_t and struct tm. There770* is no portable way to convert to either of these structures, as far771* as I know. If you know of a portable way, send it to me. As a side772* note - PNG has always been Year 2000 compliant!773*/774typedef struct png_time_struct775{776png_uint_16 year; /* full year, as in, 1995 */777png_byte month; /* month of year, 1 - 12 */778png_byte day; /* day of month, 1 - 31 */779png_byte hour; /* hour of day, 0 - 23 */780png_byte minute; /* minute of hour, 0 - 59 */781png_byte second; /* second of minute, 0 - 60 (for leap seconds) */782} png_time;783typedef png_time * png_timep;784typedef const png_time * png_const_timep;785typedef png_time * * png_timepp;786787#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\788defined(PNG_USER_CHUNKS_SUPPORTED)789/* png_unknown_chunk is a structure to hold queued chunks for which there is790* no specific support. The idea is that we can use this to queue791* up private chunks for output even though the library doesn't actually792* know about their semantics.793*794* The data in the structure is set by libpng on read and used on write.795*/796typedef struct png_unknown_chunk_t797{798png_byte *data; /* Data, should not be modified on read! */799png_uint_32 size; /* Size of data, must not exceed 0x7fffffff.800* API CHANGE 1.7.0: changed from 'size_t'801*/802png_byte name[5]; /* Textual chunk name with '\0' terminator */803804/* On write 'location' must be set using the flag values listed below.805* Notice that on read it is set by libpng however the values stored have806* more bits set than are listed below. Always treat the value as a807* bitmask. On write set only one bit - setting multiple bits may cause the808* chunk to be written in multiple places.809*/810png_byte location; /* mode of operation at read time */811}812png_unknown_chunk;813814typedef png_unknown_chunk * png_unknown_chunkp;815typedef const png_unknown_chunk * png_const_unknown_chunkp;816typedef png_unknown_chunk * * png_unknown_chunkpp;817#endif818819/* Flag values for the chunk location byte. */820#define PNG_HAVE_IHDR 0x01U821#define PNG_HAVE_PLTE 0x02U822#define PNG_AFTER_IDAT 0x08U823824/* Maximum positive integer used in PNG is (2^31)-1 */825#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)826#define PNG_UINT_32_MAX ((png_uint_32)(-1))827#define PNG_SIZE_MAX ((size_t)(-1))828829/* These are constants for fixed point values encoded in the830* PNG specification manner (x100000)831*/832#define PNG_FP_1 100000833#define PNG_FP_HALF 50000834#define PNG_FP_MAX ((png_fixed_point)0x7fffffffL)835#define PNG_FP_MIN (-PNG_FP_MAX)836837/* These describe the color_type field in png_info. */838/* color type masks */839#define PNG_COLOR_MASK_PALETTE 1U840#define PNG_COLOR_MASK_COLOR 2U841#define PNG_COLOR_MASK_ALPHA 4U842843/* color types. Note that not all combinations are legal */844#define PNG_COLOR_TYPE_GRAY 0U845#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)846#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)847#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)848#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)849/* aliases */850#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA851#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA852853/* This is for compression type. PNG 1.0-1.2 only define the single type. */854#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */855#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE856857/* This is for filter method. PNG 1.0-1.2 only defines a single method.858*859* NOTE: CONFUSING NAME. The specification refers to a 'method', one of the860* defines below, and a 'type', one of the FILTER_VALUE defines.861* Historically libpng uses TYPE for 'method' and VALUE for 'type'.862*/863#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */864#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */865#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE866867/* Filter values defined for method '0' (PNG_FILTER_TYPE_BASE) in the PNG868* specification.869*/870#define PNG_FILTER_VALUE_NONE 0871#define PNG_FILTER_VALUE_SUB 1872#define PNG_FILTER_VALUE_UP 2873#define PNG_FILTER_VALUE_AVG 3874#define PNG_FILTER_VALUE_PAETH 4875#define PNG_FILTER_VALUE_LAST 5 /* Not a valid value */876877/* These are for the interlacing type. These values should NOT be changed. */878#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */879#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */880#define PNG_INTERLACE_LAST 2 /* Not a valid value */881882/* These are for the oFFs chunk. These values should NOT be changed. */883#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */884#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */885#define PNG_OFFSET_LAST 2 /* Not a valid value */886887/* These are for the pCAL chunk. These values should NOT be changed. */888#define PNG_EQUATION_LINEAR 0 /* Linear transformation */889#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */890#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */891#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */892#define PNG_EQUATION_LAST 4 /* Not a valid value */893894/* These are for the sCAL chunk. These values should NOT be changed. */895#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */896#define PNG_SCALE_METER 1 /* meters per pixel */897#define PNG_SCALE_RADIAN 2 /* radians per pixel */898#define PNG_SCALE_LAST 3 /* Not a valid value */899900/* These are for the pHYs chunk. These values should NOT be changed. */901#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */902#define PNG_RESOLUTION_METER 1 /* pixels/meter */903#define PNG_RESOLUTION_LAST 2 /* Not a valid value */904905/* These are for the sRGB chunk. These values should NOT be changed. */906#define PNG_sRGB_INTENT_PERCEPTUAL 0907#define PNG_sRGB_INTENT_RELATIVE 1908#define PNG_sRGB_INTENT_SATURATION 2909#define PNG_sRGB_INTENT_ABSOLUTE 3910#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */911912/* This is for text chunks */913#define PNG_KEYWORD_MAX_LENGTH 79914915/* Maximum number of entries in PLTE/sPLT/tRNS arrays */916#define PNG_MAX_PALETTE_LENGTH 256917918/* These determine if an ancillary chunk's data has been successfully read919* from the PNG header, or if the application has filled in the corresponding920* data in the info_struct to be written into the output file. The values921* of the PNG_INFO_<chunk> defines should NOT be changed.922*/923#define PNG_INFO_gAMA 0x0001U924#define PNG_INFO_sBIT 0x0002U925#define PNG_INFO_cHRM 0x0004U926#define PNG_INFO_PLTE 0x0008U927#define PNG_INFO_tRNS 0x0010U928#define PNG_INFO_bKGD 0x0020U929#define PNG_INFO_hIST 0x0040U930#define PNG_INFO_pHYs 0x0080U931#define PNG_INFO_oFFs 0x0100U932#define PNG_INFO_tIME 0x0200U933#define PNG_INFO_pCAL 0x0400U934#define PNG_INFO_sRGB 0x0800U /* GR-P, 0.96a */935#define PNG_INFO_iCCP 0x1000U /* ESR, 1.0.6 */936#define PNG_INFO_sPLT 0x2000U /* ESR, 1.0.6 */937#define PNG_INFO_sCAL 0x4000U /* ESR, 1.0.6 */938#define PNG_INFO_IDAT 0x8000U /* ESR, 1.0.6 */939940/* This is used for the transformation routines, as some of them941* change these values for the row. It also should enable using942* the routines for other purposes.943*/944typedef struct png_row_info_struct945{946png_uint_32 width; /* width of row */947size_t rowbytes; /* number of bytes in row */948png_byte color_type; /* color type of row */949png_byte bit_depth; /* bit depth of row */950png_byte channels; /* number of channels (1, 2, 3, or 4) */951png_byte pixel_depth; /* bits per pixel (depth * channels) */952} png_row_info;953954typedef png_row_info * png_row_infop;955typedef png_row_info * * png_row_infopp;956957/* These are the function types for the I/O functions and for the functions958* that allow the user to override the default I/O functions with his or her959* own. The png_error_ptr type should match that of user-supplied warning960* and error functions, while the png_rw_ptr type should match that of the961* user read/write data functions. Note that the 'write' function must not962* modify the buffer it is passed. The 'read' function, on the other hand, is963* expected to return the read data in the buffer.964*/965typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));966typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, size_t));967typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));968typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32,969int));970typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32,971int));972973#ifdef PNG_PROGRESSIVE_READ_SUPPORTED974typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));975typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));976977/* WARNING: the API for this callback is poorly documented and produces978* unexpected results when dealing with interlaced images. For non-interlaced979* images the parameters are straightforward:980*981* next_row: a pointer to the transformed row read from the PNG input982* stream, it has png_get_image_width() pixels.983* row_y: the y ordinate of the image; 0..png_get_image_height()-1984* pass: 0985*986* For interlaced images if png_set_interlace_handling has been called (libpng987* does *not* call this itself) the parameters are the same except that the988* pass will be the pass in the range 0..6 (NOTE: one less than the PNG spec)989* and 'next_row' will be NULL if (and only if) the row does not contribute990* to the output in 'blocky' display mode.991*992* pass: 0..6993*994* If 'next_row' is not NULL it is necessary for the application to combine the995* pixels with the output. This can most easily be done by calling996* png_progressive_combine_row(). Note that the 'next_row' data cannot be997* changed; even though the value is passed to png_progressive_combine_row the998* pointer is not used, it is just a flag , if it is NULL nothing will happen.999*1000* If png_set_interlace_handling has not been called the callback only gets1001* called for original PNG interlaced row:1002*1003* row_y: the y ordinate in the pass; 0..PNG_PASS_ROWS()-11004*1005* What is more if PNG_PASS_COLS() is 0 the entire pass will be skipped. The1006* row data is not full width and there is no guarantee that the buffer passed1007* in 'next_row' is able to accomodate the full width of output pixels, however1008* 'next_row' will never be NULL.1009*1010* Use PNG_ROW_FROM_PASS_ROW(row_y, pass) and PNG_COL_FROM_PASS_COL(col, pass)1011* to find the output pixel (x,y) given an interlaced sub-image pixel1012* (row_y,col,pass). (See below for these macros.)1013*1014* Note that in this latter case if you want to do the 'blocky' display update1015* method you have to work out all the details yourself with regard to which1016* pixels to set for each row and whether to replicate it to the following1017* rows of the image.1018*/1019typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp,1020png_bytep next_row, png_uint_32 row_y, int pass));1021#endif10221023#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED1024typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop,1025png_bytep));1026#endif10271028#ifdef PNG_USER_CHUNKS_SUPPORTED1029typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp,1030png_unknown_chunkp));1031#endif1032#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED1033/* not used anywhere */1034/* typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); */1035#endif10361037#ifdef PNG_SETJMP_SUPPORTED1038/* This must match the function definition in <setjmp.h>, and the application1039* must include this before png.h to obtain the definition of jmp_buf. The1040* function is required to be PNG_NORETURN, but this is not checked. If the1041* function does return the application will crash via an abort() or similar1042* system level call.1043*1044* If you get a warning here while building the library you may need to make1045* changes to ensure that pnglibconf.h records the calling convention used by1046* your compiler. This may be very difficult - try using a different compiler1047* to build the library!1048*/1049PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef);1050#endif10511052/* Transform masks for the high-level interface */1053#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */1054#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */1055#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */1056#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */1057#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */1058#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */1059#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */1060#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */1061#define PNG_TRANSFORM_BGR 0x0080 /* read and write */1062#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */1063#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */1064#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */1065#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */1066/* Added to libpng-1.2.34 */1067#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER1068#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */1069/* Added to libpng-1.4.0 */1070#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */1071/* Added to libpng-1.5.4 */1072#define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */1073#define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */10741075/* Flags for MNG supported features */1076#define PNG_FLAG_MNG_EMPTY_PLTE 0x011077#define PNG_FLAG_MNG_FILTER_64 0x041078#define PNG_ALL_MNG_FEATURES 0x0510791080/* NOTE: prior to 1.5 these functions had no 'API' style declaration,1081* this allowed the zlib default functions to be used on Windows1082* platforms. In 1.5 the zlib default malloc (which just calls malloc and1083* ignores the first argument) should be completely compatible with the1084* following.1085*/1086typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp,1087png_alloc_size_t));1088typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));10891090/* Section 4: exported functions1091* Here are the function definitions most commonly used. This is not1092* the place to find out how to use libpng. See libpng-manual.txt for the1093* full explanation, see example.c for the summary. This just provides1094* a simple one line description of the use of each function.1095*1096* The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in1097* pngconf.h and in the *.dfn files in the scripts directory.1098*1099* PNG_EXPORT(ordinal, type, name, (args));1100*1101* ordinal: ordinal that is used while building1102* *.def files. The ordinal value is only1103* relevant when preprocessing png.h with1104* the *.dfn files for building symbol table1105* entries, and are removed by pngconf.h.1106* type: return type of the function1107* name: function name1108* args: function arguments, with types1109*1110* When we wish to append attributes to a function prototype we use1111* the PNG_EXPORTA() macro instead.1112*1113* PNG_EXPORTA(ordinal, type, name, (args), attributes);1114*1115* ordinal, type, name, and args: same as in PNG_EXPORT().1116* attributes: function attributes1117*/11181119/* Returns the version number of the library */1120PNG_EXPORT(1, png_uint_32, png_access_version_number, (void));11211122/* Tell lib we have already handled the first <num_bytes> magic bytes.1123* Handling more than 8 bytes from the beginning of the file is an error.1124*/1125PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes));11261127/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a1128* PNG file. Returns zero if the supplied bytes match the 8-byte PNG1129* signature, and non-zero otherwise. Having num_to_check == 0 or1130* start > 7 will always fail (ie return non-zero).1131*/1132PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, size_t start,1133size_t num_to_check));11341135/* Simple signature checking function. This is the same as calling1136* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).1137*/1138#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))11391140/* Allocate and initialize png_ptr struct for reading, and any other memory. */1141PNG_EXPORTA(4, png_structp, png_create_read_struct,1142(png_const_charp user_png_ver, png_voidp error_ptr,1143png_error_ptr error_fn, png_error_ptr warn_fn),1144PNG_ALLOCATED);11451146/* Allocate and initialize png_ptr struct for writing, and any other memory */1147PNG_EXPORTA(5, png_structp, png_create_write_struct,1148(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,1149png_error_ptr warn_fn),1150PNG_ALLOCATED);11511152/* These APIs control the size of the buffer used for reading IDAT chunks in the1153* sequential read code and the size of the IDAT chunks produced when writing.1154* They have no effect on the progressive read code. In both read and write1155* cases it will be necessary to allocate at least this amount of buffer space.1156* The default value is PNG_IDAT_READ_SIZE on read and PNG_ZBUF_SIZE on write.1157*1158* The valid range is 1..0x7FFFFFFF on write and 1..max(uInt) on read, where1159* uInt is the type declared by zlib.h. On write setting the largest value will1160* typically cause the PNG image data to be written in one chunk; this gives the1161* smallest PNG and has little or no effect on applications that read the PNG.1162*1163* DEPRECATED: use png_set_IDAT_size on write and png_set_read_buffer_size on1164* read.1165*/1166PNG_EXPORTA(6, png_alloc_size_t, png_get_compression_buffer_size,1167(png_const_structrp png_ptr), PNG_DEPRECATED);1168PNG_EXPORTA(7, void, png_set_compression_buffer_size, (png_structrp png_ptr,1169png_alloc_size_t size), PNG_DEPRECATED);1170#define png_set_read_buffer_size(p,size) (png_setting((p),\1171PNG_SR_COMPRESS_buffer_size, (size), 0))1172/* The size of the buffer used while processing compressed data, both single1173* chunk data (zTXt, iTXt, iCCP) and IDAT data. With IDAT data in libpng 1.71174* IDATs are read until the end or until the buffer is full; this means that1175* you can optimize the buffer size for the particular memory behavior of1176* your system and, possibly, your application.1177*1178* NOTE: the result (on success) is 0, which is actually an invalid value.1179* Retrieving the current value is not possible.1180*/11811182/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp1183* match up.1184*/1185#ifdef PNG_SETJMP_SUPPORTED1186/* This function returns the jmp_buf built in to *png_ptr. It must be1187* supplied with an appropriate 'longjmp' function to use on that jmp_buf1188* unless the default error function is overridden in which case NULL is1189* acceptable. The size of the jmp_buf is checked against the actual size1190* allocated by the library - the call will return NULL on a mismatch1191* indicating an ABI mismatch.1192*/1193PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr,1194png_longjmp_ptr longjmp_fn, size_t jmp_buf_size));1195# define png_jmpbuf(png_ptr) \1196(*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf))))1197#else1198# define png_jmpbuf(png_ptr) \1199(LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)1200#endif1201/* This function should be used by libpng applications in place of1202* longjmp(png_ptr->jmpbuf, val). If longjmp_fn() has been set, it1203* will use it; otherwise it will call PNG_ABORT(). This function was1204* added in libpng-1.5.0.1205*/1206PNG_EXPORTA(9, void, png_longjmp, (png_const_structrp png_ptr, int val),1207PNG_NORETURN);12081209#ifdef PNG_READ_SUPPORTED1210/* Reset the compression stream -- Removed from libpng-1.7.0 */1211PNG_REMOVED(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED)1212#endif12131214/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */1215#ifdef PNG_USER_MEM_SUPPORTED1216PNG_EXPORTA(11, png_structp, png_create_read_struct_2,1217(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,1218png_error_ptr warn_fn,1219png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),1220PNG_ALLOCATED);1221PNG_EXPORTA(12, png_structp, png_create_write_struct_2,1222(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,1223png_error_ptr warn_fn,1224png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),1225PNG_ALLOCATED);1226#endif12271228/* Write the PNG file signature. */1229PNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr));12301231/* Write a PNG chunk - size, type, (optional) data, CRC. */1232PNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr,1233png_const_bytep chunk_name, png_const_voidp data, size_t length));12341235/* Write the start of a PNG chunk - length and chunk name. */1236PNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr,1237png_const_bytep chunk_name, png_uint_32 length));12381239/* Write the data of a PNG chunk started with png_write_chunk_start(). */1240PNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr,1241png_const_voidp data, size_t length));12421243/* Finish a chunk started with png_write_chunk_start() (includes CRC). */1244PNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr));12451246/* Allocate and initialize the info structure */1247PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr),1248PNG_ALLOCATED);12491250/* Removed from libpng-1.7.0 */1251PNG_REMOVED(19, void, png_info_init_3, (png_infopp info_ptr,1252size_t png_info_struct_size), PNG_DEPRECATED)12531254/* Writes all the PNG information before the image. */1255PNG_EXPORT(20, void, png_write_info_before_PLTE,1256(png_structrp png_ptr, png_const_inforp info_ptr));1257PNG_EXPORT(21, void, png_write_info,1258(png_structrp png_ptr, png_const_inforp info_ptr));12591260#ifdef PNG_SEQUENTIAL_READ_SUPPORTED1261/* Read the information before the actual image data. */1262PNG_EXPORT(22, void, png_read_info,1263(png_structrp png_ptr, png_inforp info_ptr));1264#endif12651266#ifdef PNG_TIME_RFC1123_SUPPORTED1267/* Convert to a US string format: there is no localization support in this1268* routine. The original implementation used a 29 character buffer in1269* png_struct, this has been removed (in libpng 1.7.0).1270*/1271PNG_REMOVED(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr,1272png_const_timep ptime),PNG_DEPRECATED)1273PNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29],1274png_const_timep ptime));1275#endif12761277#ifdef PNG_CONVERT_tIME_SUPPORTED1278/* Convert from a struct tm to png_time */1279PNG_EXPORT(24, PNG_DEPRECATED void, png_convert_from_struct_tm,1280(png_timep ptime, const struct tm * ttime));12811282/* Convert from time_t to png_time. Uses gmtime() */1283PNG_EXPORT(25, PNG_DEPRECATED void, png_convert_from_time_t, (png_timep ptime,1284time_t ttime));1285#endif /* CONVERT_tIME */12861287#ifdef PNG_READ_EXPAND_SUPPORTED1288/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */1289PNG_EXPORT(26, void, png_set_expand, (png_structrp png_ptr));1290PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structrp png_ptr));1291PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structrp png_ptr));1292PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structrp png_ptr));1293#endif12941295#ifdef PNG_READ_EXPAND_16_SUPPORTED1296/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion1297* of a tRNS chunk if present.1298*/1299PNG_EXPORT(221, void, png_set_expand_16, (png_structrp png_ptr));1300#endif13011302#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)1303/* Use blue, green, red order for pixels. */1304PNG_EXPORT(30, void, png_set_bgr, (png_structrp png_ptr));1305#endif13061307#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED1308/* Expand the grayscale to 24-bit RGB if necessary. */1309PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structrp png_ptr));1310#endif13111312#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED1313/* Reduce RGB to grayscale. */1314#define PNG_ERROR_ACTION_NO_CHECK 01315#define PNG_ERROR_ACTION_NONE 11316#define PNG_ERROR_ACTION_WARN 21317#define PNG_ERROR_ACTION_ERROR 31318#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/13191320PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structrp png_ptr,1321int error_action, double red, double green))1322PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structrp png_ptr,1323int error_action, png_fixed_point red, png_fixed_point green))1324/* Convert RGB pixels to gray (CIE Y) values, the red and green value must be1325* less than or equal to 1, if either is negative a set of defaults1326* corresponding to the sRGB standard are used.1327*1328* The error action specifies whether to check for r==g==b in each pixel, if1329* it is 0 (PNG_ERROR_ACTION_NO_CHECK; added in libpng 1.7.0) no check will1330* be performed, otherwise a check is performed and the result can be1331* retrieved using png_get_rgb_to_gray_status (which just returns a1332* true if a non-gray pixel was encountered).1333*1334* Pass PNG_ERROR_ACTION_ERROR if you are confident that the image only1335* contains gray pixels (you have already checked); the check is still1336* performed but a very optimized code path is used for RGB to gray1337* convertion.1338*1339* If you want to extract a single channel pass PNG_FP_1 for the coefficient1340* for that channel and 0 for the rest (0 for both red and green to extract1341* blue).1342*1343* NOTE: the default coefficients used if negative values are passed for red1344* or green are based on the cHRM chunk if available, otherwise sRGB. The1345* calculation returns the Y (luminance value) corresponding to the white1346* point of the PNG. UNLESS THE WHITE POINT IS D50 THIS IS NOT A CIEXYZ Y1347* VALUE. It is the luminance of the pixel perceived by a viewer completely1348* adapted to the white point of the PNG, this may not be what you want1349* because to interpret it you have to also record the white point of the1350* PNG. To obtain CIEXYZ Y values read the cHRM chunk XYZ values and1351* chromatically adapt them to D501352*/13531354PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structrp1355png_ptr));1356#endif13571358#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED1359PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth,1360png_colorp palette));1361#endif13621363#ifdef PNG_READ_ALPHA_MODE_SUPPORTED1364/* How the alpha channel is interpreted - this affects how the color channels1365* of a PNG file are returned to the calling application when an alpha channel,1366* or a tRNS chunk in a palette file, is present.1367*1368* This has no effect on the way pixels are written into a PNG output1369* datastream. The color samples in a PNG datastream are never premultiplied1370* with the alpha samples.1371*1372* The default is to return data according to the PNG specification: the alpha1373* channel is a linear measure of the contribution of the pixel to the1374* corresponding composited pixel, and the color channels are unassociated1375* (not premultiplied). The gamma encoded color channels must be scaled1376* according to the contribution and to do this it is necessary to undo1377* the encoding, scale the color values, perform the composition and reencode1378* the values. This is the 'PNG' mode.1379*1380* The alternative is to 'associate' the alpha with the color information by1381* storing color channel values that have been scaled by the alpha.1382* image. These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes1383* (the latter being the two common names for associated alpha color channels).1384*1385* For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha1386* value is equal to the maximum value.1387*1388* The final choice is to gamma encode the alpha channel as well. This is1389* broken because, in practice, no implementation that uses this choice1390* correctly undoes the encoding before handling alpha composition. Use this1391* choice only if other serious errors in the software or hardware you use1392* mandate it; the typical serious error is for dark halos to appear around1393* opaque areas of the composited PNG image because of arithmetic overflow.1394*1395* The API function png_set_alpha_mode specifies which of these choices to use1396* with an enumerated 'mode' value and the gamma of the required output:1397*/1398#define PNG_ALPHA_PNG 0 /* according to the PNG standard */1399#define PNG_ALPHA_STANDARD 1 /* according to Porter/Duff */1400#define PNG_ALPHA_ASSOCIATED 1 /* as above; this is the normal practice */1401#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */1402#define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */1403#define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */14041405PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structrp png_ptr, int mode,1406double output_gamma))1407PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr,1408int mode, png_fixed_point output_gamma))1409#endif14101411#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED)1412/* The output_gamma value is a screen gamma in libpng terminology: it expresses1413* how to decode the output values, not how they are encoded.1414*/1415#define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */1416#define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */1417#define PNG_GAMMA_sRGB 220000 /* Television standards--matches sRGB gamma */1418#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */1419#endif14201421/* The following are examples of calls to png_set_alpha_mode to achieve the1422* required overall gamma correction and, where necessary, alpha1423* premultiplication.1424*1425* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);1426* This is the default libpng handling of the alpha channel - it is not1427* pre-multiplied into the color components. In addition the call states1428* that the output is for a sRGB system and causes all PNG files without gAMA1429* chunks to be assumed to be encoded using sRGB.1430*1431* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);1432* In this case the output is assumed to be something like an sRGB conformant1433* display preceeded by a power-law lookup table of power 1.45. This is how1434* early Mac systems behaved.1435*1436* png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);1437* This is the classic Jim Blinn approach and will work in academic1438* environments where everything is done by the book. It has the shortcoming1439* of assuming that input PNG data with no gamma information is linear - this1440* is unlikely to be correct unless the PNG files where generated locally.1441* Most of the time the output precision will be so low as to show1442* significant banding in dark areas of the image.1443*1444* png_set_expand_16(pp);1445* png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB);1446* This is a somewhat more realistic Jim Blinn inspired approach. PNG files1447* are assumed to have the sRGB encoding if not marked with a gamma value and1448* the output is always 16 bits per component. This permits accurate scaling1449* and processing of the data. If you know that your input PNG files were1450* generated locally you might need to replace PNG_DEFAULT_sRGB with the1451* correct value for your system.1452*1453* png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB);1454* If you just need to composite the PNG image onto an existing background1455* and if you control the code that does this you can use the optimization1456* setting. In this case you just copy completely opaque pixels to the1457* output. For pixels that are not completely transparent (you just skip1458* those) you do the composition math using png_composite or png_composite_161459* below then encode the resultant 8-bit or 16-bit values to match the output1460* encoding.1461*1462* Other cases1463* If neither the PNG nor the standard linear encoding work for you because1464* of the software or hardware you use then you have a big problem. The PNG1465* case will probably result in halos around the image. The linear encoding1466* will probably result in a washed out, too bright, image (it's actually too1467* contrasty.) Try the ALPHA_OPTIMIZED mode above - this will probably1468* substantially reduce the halos. Alternatively try:1469*1470* png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB);1471* This option will also reduce the halos, but there will be slight dark1472* halos round the opaque parts of the image where the background is light.1473* In the OPTIMIZED mode the halos will be light halos where the background1474* is dark. Take your pick - the halos are unavoidable unless you can get1475* your hardware/software fixed! (The OPTIMIZED approach is slightly1476* faster.)1477*1478* When the default gamma of PNG files doesn't match the output gamma.1479* If you have PNG files with no gamma information png_set_alpha_mode allows1480* you to provide a default gamma, but it also sets the ouput gamma to the1481* matching value. If you know your PNG files have a gamma that doesn't1482* match the output you can take advantage of the fact that1483* png_set_alpha_mode always sets the output gamma but only sets the PNG1484* default if it is not already set:1485*1486* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);1487* png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);1488* The first call sets both the default and the output gamma values, the1489* second call overrides the output gamma without changing the default. This1490* is easier than achieving the same effect with png_set_gamma. You must use1491* PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will1492* fire if more than one call to png_set_alpha_mode and png_set_background is1493* made in the same read operation, however multiple calls with PNG_ALPHA_PNG1494* are ignored.1495*/14961497#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED1498PNG_EXPORT(36, void, png_set_strip_alpha, (png_structrp png_ptr));1499#endif15001501#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \1502defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)1503PNG_EXPORT(37, void, png_set_swap_alpha, (png_structrp png_ptr));1504#endif15051506#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \1507defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)1508PNG_EXPORT(38, void, png_set_invert_alpha, (png_structrp png_ptr));1509#endif15101511#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)1512/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */1513PNG_EXPORT(39, void, png_set_filler, (png_structrp png_ptr, png_uint_32 filler,1514int flags));1515/* The values of the PNG_FILLER_ defines should NOT be changed */1516# define PNG_FILLER_BEFORE 01517# define PNG_FILLER_AFTER 11518/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */1519PNG_EXPORT(40, void, png_set_add_alpha, (png_structrp png_ptr,1520png_uint_32 filler, int flags));1521#endif /* READ_FILLER || WRITE_FILLER */15221523#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)1524/* Swap bytes in 16-bit depth files. */1525PNG_EXPORT(41, void, png_set_swap, (png_structrp png_ptr));1526#endif15271528#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)1529/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */1530PNG_EXPORT(42, void, png_set_packing, (png_structrp png_ptr));1531#endif15321533#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \1534defined(PNG_WRITE_PACKSWAP_SUPPORTED)1535/* Swap packing order of pixels in bytes. */1536PNG_EXPORT(43, void, png_set_packswap, (png_structrp png_ptr));1537#endif15381539#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)1540/* Converts files to legal bit depths. */1541PNG_EXPORT(44, void, png_set_shift, (png_structrp png_ptr, png_const_color_8p1542true_bits));1543#endif15441545#if defined(PNG_READ_INTERLACING_SUPPORTED) || \1546defined(PNG_WRITE_INTERLACING_SUPPORTED)1547/* Have the code handle the interlacing. Returns the number of passes.1548* MUST be called before png_read_update_info or png_start_read_image,1549* otherwise it will not have the desired effect. Note that it is still1550* necessary to call png_read_row or png_read_rows png_get_image_height1551* times for each pass.1552*/1553PNG_EXPORT(45, int, png_set_interlace_handling, (png_structrp png_ptr));1554#endif15551556#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)1557/* Invert monochrome files */1558PNG_EXPORT(46, void, png_set_invert_mono, (png_structrp png_ptr));1559#endif15601561#ifdef PNG_READ_BACKGROUND_SUPPORTED1562/* Handle alpha and tRNS by replacing with a background color. Prior to1563* libpng-1.5.4 this API must not be called before the PNG file header has been1564* read. Doing so will result in unexpected behavior and possible warnings or1565* errors if the PNG file contains a bKGD chunk.1566*/1567PNG_FP_EXPORT(47, void, png_set_background, (png_structrp png_ptr,1568png_const_color_16p background_color, int background_gamma_code,1569int need_expand, double background_gamma))1570PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structrp png_ptr,1571png_const_color_16p background_color, int background_gamma_code,1572int need_expand, png_fixed_point background_gamma))1573#endif1574#ifdef PNG_READ_BACKGROUND_SUPPORTED1575# define PNG_BACKGROUND_GAMMA_UNKNOWN 01576# define PNG_BACKGROUND_GAMMA_SCREEN 11577# define PNG_BACKGROUND_GAMMA_FILE 21578# define PNG_BACKGROUND_GAMMA_UNIQUE 31579#endif15801581#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED1582/* Scale a 16-bit depth file down to 8-bit, accurately. */1583PNG_EXPORT(229, void, png_set_scale_16, (png_structrp png_ptr));1584#endif15851586#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED1587#define PNG_READ_16_TO_8_SUPPORTED /* Name prior to 1.5.4 */1588/* Strip the second byte of information from a 16-bit depth file. */1589PNG_EXPORT(48, void, png_set_strip_16, (png_structrp png_ptr));1590#endif15911592#ifdef PNG_READ_QUANTIZE_SUPPORTED1593/* Turn on quantizing, and reduce the palette to the number of colors1594* available.1595*/1596PNG_EXPORT(49, void, png_set_quantize, (png_structrp png_ptr,1597png_colorp palette, int num_palette, int maximum_colors,1598png_const_uint_16p histogram, int full_quantize));1599#endif16001601#ifdef PNG_READ_GAMMA_SUPPORTED1602/* The threshold on gamma processing is configurable but hard-wired into the1603* library. The following is the floating point variant.1604*/1605#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001)16061607/* Handle gamma correction. Screen_gamma=(display_exponent).1608* NOTE: this API simply sets the screen and file gamma values. It will1609* therefore override the value for gamma in a PNG file if it is called after1610* the file header has been read - use with care - call before reading the PNG1611* file for best results!1612*1613* These routines accept the same gamma values as png_set_alpha_mode (described1614* above). The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either1615* API (floating point or fixed.) Notice, however, that the 'file_gamma' value1616* is the inverse of a 'screen gamma' value.1617*/1618PNG_FP_EXPORT(50, void, png_set_gamma, (png_structrp png_ptr,1619double screen_gamma, double override_file_gamma))1620PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structrp png_ptr,1621png_fixed_point screen_gamma, png_fixed_point override_file_gamma))1622#endif16231624#ifdef PNG_WRITE_FLUSH_SUPPORTED1625PNG_REMOVED(51, void, png_set_flush, (png_structrp png_ptr, int nrows),1626PNG_EMPTY)1627#define png_set_flush(p,v) (png_setting((p), PNG_SW_FLUSH, 0, (v)))1628/* Set how many lines between output flushes - 0 for no flushing. The result1629* on success is always 0.1630*/16311632/* Flush the current PNG output buffer */1633PNG_EXPORT(52, void, png_write_flush, (png_structrp png_ptr));1634#endif /* WRITE_FLUSH */16351636/* Optional update palette with requested transformations */1637PNG_EXPORT(53, void, png_start_read_image, (png_structrp png_ptr));16381639/* Optional call to update the users info structure */1640PNG_EXPORT(54, void, png_read_update_info, (png_structrp png_ptr,1641png_inforp info_ptr));16421643#ifdef PNG_SEQUENTIAL_READ_SUPPORTED1644/* Read one or more rows of image data. */1645PNG_EXPORT(55, void, png_read_rows, (png_structrp png_ptr, png_bytepp row,1646png_bytepp display_row, png_uint_32 num_rows));1647#endif16481649#ifdef PNG_SEQUENTIAL_READ_SUPPORTED1650/* Read a row of data. */1651PNG_EXPORT(56, void, png_read_row, (png_structrp png_ptr, png_bytep row,1652png_bytep display_row));1653#endif16541655#ifdef PNG_READ_IMAGE_SUPPORTED1656/* Read the whole image into memory at once. */1657PNG_EXPORT(57, void, png_read_image, (png_structrp png_ptr, png_bytepp image));1658#endif16591660/* Write a row of image data */1661PNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr,1662png_const_bytep row));16631664/* Write a few rows of image data: (*row) is not written; however, the type1665* is declared as writeable to maintain compatibility with previous versions1666* of libpng and to allow the 'display_row' array from read_rows to be passed1667* unchanged to write_rows.1668*/1669PNG_EXPORT(59, void, png_write_rows, (png_structrp png_ptr, png_bytepp row,1670png_uint_32 num_rows));16711672/* Write the image data */1673PNG_EXPORT(60, void, png_write_image, (png_structrp png_ptr, png_bytepp image));16741675/* Write the end of the PNG file. */1676PNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr,1677png_inforp info_ptr));16781679#ifdef PNG_SEQUENTIAL_READ_SUPPORTED1680/* Read the end of the PNG file. */1681PNG_EXPORT(62, void, png_read_end, (png_structrp png_ptr, png_inforp info_ptr));1682#endif16831684/* Free any memory associated with the png_info_struct */1685PNG_EXPORT(63, void, png_destroy_info_struct, (png_const_structrp png_ptr,1686png_infopp info_ptr_ptr));16871688/* Free any memory associated with the png_struct and the png_info_structs */1689PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr,1690png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));16911692/* Free any memory associated with the png_struct and the png_info_structs */1693PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr,1694png_infopp info_ptr_ptr));16951696/* Set the libpng method of handling chunk CRC errors on read */1697PNG_REMOVED(66, void, png_set_crc_action, (png_structrp png_ptr,1698int crit_action, int ancil_action), PNG_EMPTY)1699#define png_set_crc_action(png_ptr, crit, ancil)\1700(png_setting((png_ptr), PNG_SR_CRC_ACTION, (crit), (ancil)))17011702/* Values for png_set_crc_action() say how to handle CRC errors in1703* ancillary and critical chunks, and whether to use the data contained1704* therein. Note that it is impossible to "discard" data in a critical1705* chunk. For versions prior to 0.90, the action was always error/quit,1706* whereas in version 0.90 and later, the action for CRC errors in ancillary1707* chunks is warn/discard. These values should NOT be changed.1708*1709* value action:critical action:ancillary1710*/1711#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */1712#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */1713#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */1714#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */1715#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */1716#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */17171718/* Write image filtering and compression options.1719*1720* These settings just change the very low level encoding of a PNG. The changes1721* make no difference to the image or the meta-data stored in the PNG. The API1722* used to make these changes can be disabled in a very minimal configuration,1723* if it is your compiler will report undefined values when the APIs below are1724* used.1725*1726* Write settings defined here, in order of ease of use:1727*1728* 1) Write compression settings: whether to optimize the write and the PNG1729* that results for read speed, final PNG size, write speed or memory1730* usage.1731* 2) IDAT size: What size to make the IDAT chunks in the PNG.1732* 3) PNG row filters to consider when writing the PNG.1733* 4) Very low level control over the deflate compression (useful mainly for1734* programs that want to try every option to find which gives the smallest1735* PNG.)1736*/1737#ifdef PNG_WRITE_SUPPORTED1738/* (1) Write compression settings: */1739#define png_set_compression(p, v) (png_setting((p), PNG_SW_COMPRESS_png_level,\17400, (v)))1741/* Control the write compression of all chunks. This affects five basic1742* pieces of behavior:1743*1744* 1) The size of the PNG produced.1745* 2) The amount of memory the write code takes to produce the PNG.1746* 3) The amount of time the write code takes to produce the PNG.1747* 4) The amount of memory required to read the resultant PNG.1748* 5) The amount of time required to read the resultant PNG.1749*1750* There is considerable interdependence between these variables. As a1751* result there are a limited number of options:1752*/1753# define PNG_COMPRESSION_LOW_MEMORY (1)1754/* Minimize the memory required both when reading (4) and writing (2) the1755* PNG. This results in a significantly larger PNG (which may itself have1756* the opposite effect of slowing down either read or write) however the1757* memory overhead is reduced and, apart from the extra time to read the1758* data, the read time is likely to be reduced too.1759*1760* Use this when both read and write will happen on a memory starved1761* (really, very low memory) system. Note that this sets a high deflate1762* compression setting because that does not affect zlib memory usage.1763*/1764# define PNG_COMPRESSION_HIGH_SPEED (2)1765/* Minimize the time to both read (5) and write (3) the PNG. This uses1766* slightly more memory on read and potentially significantly more on1767* write but is optimized for maximum speed in both cases.1768*1769* Use this when both read and write need to be fast and PNG size is not1770* likely to be an issue. An example would be if you are using PNG to1771* pass intermediate data between applications on the same machine.1772*/1773# define PNG_COMPRESSION_HIGH_READ_SPEED (3)1774/* Minimize the time to read (5) the PNG. This also reduces the amount1775* of memory on read, however some options which require more memory but1776* are likely to decrease PNG size, therefore improve read spead, are1777* used.1778*1779* This is one of the 'normal' options; options that are used when a1780* reasonably capable write machine is producing PNG files that will be1781* read many times. In this case the option is optimizing for speed on1782* read even if it increases the size of the PNG.1783*/1784# define PNG_COMPRESSION_LOW (4)1785/* This switches on options which do affect speed of both compression and1786* decompression, but biases the choice towards higher performance in both1787* cases. (So it is something of a compromise between all-out speed and1788* PNG compression).1789*1790* This is a good default to use in typical usages where PNG file size is1791* less of an issue than the overheads on reading a PNG file.1792*1793* Use this option when producing PNG files that are not expected to be1794* distributed widely or where read speed is more important than size.1795* This is also a good default for small images where the slight increase1796* in size of the compressed data doesn't change the file size much.1797*/1798# define PNG_COMPRESSION_MEDIUM (5)1799/* This is a compromise which switches on the options found most helpful1800* across a wide range of files without switching on the full range of1801* options which would decrease file size only a little while taking a lot1802* more time. PNG read memory (4) or time (5) is not a factor in the1803* choice of options; only write time (3).1804*1805* This is closest to the default used in prior versions of libpng. There1806* seems no logic to using it if the actual requirements are known and,1807* even if they aren't, it is probably better to guess 'LOW' or 'HIGH'.1808*1809* This is the normal libpng default.1810*/1811# define PNG_COMPRESSION_HIGH (6)1812/* This turns on everything which reduces file size on aggregate across a1813* large test set of files. It optimizes solely for the size of the1814* resultant PNG (1).1815*1816* This is a good default to use if file size is all important; it was the1817* stated original default in the PNG design, but the implementation of1818* libpng never used it.1819*1820* Use this setting in image authoring applications when writing the1821* finished image in PNG format.1822*1823* NOTE: several PNG file size optimizers exist (see the web-site1824* libpng.org). libpng does not perform the same functions as these1825* optimizers; libpng does not search for the best compression settings.1826* For this reason if you really want to minimize the size of the PNG files1827* produced use PNG_COMPRESSION_HIGH_SPEED then post-process the result1828* with one of the many PNG optimization programs.1829*/1830# define PNG_COMPRESSION_COMPAT (0)1831/* DEPRECATED: this is provided as a setting to aid transition of test1832* suites between major library versions (1.5 or 1.6 moving to 1.7). The1833* default settings change in 1.7 so, while the PNG files produced do not1834* change, their encoding does. Test systems that rely on constant1835* encoding can use this to verify that this is all that has changed.1836*1837* NOTE: the option will be removed at some point. It is difficult to1838* maintain and adds to libpng code size.1839*1840* NOTE: there are other changes in major and minor releases, such as1841* better ancillary chunk error handling, that also cause binary changes1842* to the PNG files libpng generates. Furthermore versions of libpng1843* prior to 1.7 included random data from uninitialized memory in the1844* image data under certain circumstances; this meant that earlier1845* versions were often not even consistent across two writes of the same1846* PNG file!1847*/18481849/* png_set_compression sets the default for all libpng compression operations.1850* While the setting is the same for all chunks it results in different1851* compression options for different chunks. The setting can be applied1852* separately to each class of chunks as follows:1853*/1854#define png_set_image_compression(p, v) (png_setting((p),\1855PNG_SW_COMPRESS_png_level, png_IDAT, (v)))1856/* Control the compression of the image data (IDAT) chunks. */18571858#define png_set_ICC_profile_compression(p, v) (png_setting((p),\1859PNG_SW_COMPRESS_png_level, png_iCCP, (v)))1860/* Control the compression of ICC profiles (iCCP chunks.) */18611862#define png_set_text_compression(p, v) (png_setting((p),\1863PNG_SW_COMPRESS_png_level, png_zTXt, (v)))1864/* Control the compression of text (png_zTXt and png_iTXt) chunks. */18651866/* (2) IDAT size: */1867#define png_set_IDAT_size(p, v) (png_setting((p), PNG_SW_IDAT_size, (v), 0))1868/* Set the maximum size of the IDAT chunks libpng writes. Valid values are1869* in the range 1U..0x7fffffffU, the default is 'PNG_ZBUF_SIZE' (a1870* historically confusing name) and this default *also* controls the size of1871* the buffer the read code uses when reading IDAT chunks.1872*1873* libpng has to buffer the data in the IDAT chunk before it writes any of1874* it, therefore this number directly controls that part of the memory1875* overhead while writing a PNG. There is a 12 byte per chunk overhead, so1876* the number also directly affects the size of the PNG. The number has no1877* significant effect (beyond the latter size effect) on the read code.1878*/1879#endif /* WRITE */18801881/* These functions give the user control over the scan-line filtering in1882* libpng and the compression methods used by zlib. These functions are1883* mainly useful for testing, as the defaults should work with most users.1884* Those users who are tight on memory or want faster performance at the1885* expense of compression can modify them. See the compression library1886* header file (zlib.h) for an explination of the compression functions.1887*/18881889#ifdef PNG_WRITE_FILTER_SUPPORTED1890/* (3) PNG row filters to consider when writing the PNG.1891*1892* Control the filtering method(s) used by libpng for the write of subsequent1893* rows of the image. The argument is either a single filter value (one of the1894* PNG_FILTER_VALUE_ defines above), in which case that filter will be used on1895* following rows, or a mask of filter values (logical or of the PNG_FILTER_1896* bit masks that follow PNG_FILTER_VALUE_*). Support for selection of a filter1897* from a mask with more than one bit set is dependent on1898* PNG_SELECT_FILTER_SUPPORTED, however support is the default configuration of1899* libpng. If support is not available the lowest bit set in the mask (the1900* lowest numbered filter) is used.1901*1902* The set of filters may be changed at any time, the new values will affect the1903* next row written.1904*1905* The 'method' must match that passed to png_set_IHDR; it cannot be changed and1906* is ignored in 1.7 and later.1907*1908* If multiple filters are enabled libpng will select one according to the1909* following rules:1910*1911* 1) On the first row of a pass UP is ignored if NONE is set and PAETH is1912* ignored if SUB is set; this is because these filter pairs are equivalent1913* when there is no previous row.1914*1915* 2) PNG_SELECT_FILTER_SUPPORTED:1916* If the PNG rows are long enough (have enough bytes) libpng will process a1917* row at a time; it will buffer the row if necessary. It uses a heuristic1918* based on the closeness of the filtered values to 0 to determine which1919* filter to use.1920*1921* 3) !PNG_SELECT_FILTER_SUPPORTED:1922* libpng selects the first filter in the list (there is no warning that this1923* will happen - check the #defines if you need to know.)1924*1925* The 'up', 'avg' and 'Paeth' filters require the previous image row to work.1926* If it is not available they are removed from the set of filters to try. The1927* first time the filter mask includes one of these filters libpng turns on1928* saving of the row. The filters do work on the first row of a pass, where1929* there is no previous row from the image. The PNG standard defines the1930* previous row as consisting of all 0 bytes in this case. That definition1931* causes the filters to have the following properties on the first row of a1932* pass:1933*1934* UP: The same as NONE (i.e. no filtering).1935* AVG: Uses the arithmetic (not modular arithmetc!) half of the preceding1936* pixel as the predictor. This is unique and not typically very1937* useful.1938* PAETH: The same as SUB.1939*1940* As a result with all versions of libpng if you want to use any of these1941* filters anywhere in the image you need only turn on one of them on the first1942* row of the image, or of a pass for interlaced images. For example if you1943* want to use 'sub' on the first row simply set 'sub'+'Paeth' in the mask;1944* libpng will automatically eliminate the Paeth algorithm from consideration1945* because it knows that 'sub' will rank equal or (if the filter byte is taken1946* into account) better.1947*1948* This approach is portable to earlier versions of libpng, however it may be1949* difficult to program. 1.7 allows you to directly specify whether or not to1950* retain the previous row. This is simpler and allows you to turn off previous1951* row retention if you want to.1952*/1953PNG_REMOVED(67, void, png_set_filter, (png_structrp png_ptr, int method,1954int filters), PNG_EMPTY)19551956#define png_set_filter(p, m, f) (png_setting((p), PNG_SW_COMPRESS_filters,\1957(m), (f)))1958/* 'm' is the method and must be 0 (PNG_FILTER_TYPE_BASE) unless MNG1959* processing is supported (very unusual). 'f' is either a single value,1960* PNG_FILTER_VALUE_* below, or a combination of one or more PNG_FILTER_MASK1961* values.1962*1963* This sets the filter mask (or value) for the *next* row that is written.1964* It may be called at any time but does not have any effect until the next1965* row starts to be written.1966*1967* The return value is the mask that is set (or, with PNG_SF_GET, the1968* currently set mask). When PNG_SELECT_FILTER_SUPPORTED is not defined this1969* mask will have only one bit.1970*1971* NOTE: with PNG_SF_GET the result will be PNG_UNSET if png_set_filter has1972* not been called before and row writing has not started.1973*/19741975#define png_set_row_buffers(p, onoff) (png_setting((p),\1976PNG_SW_COMPRESS_row_buffers, (onoff), 0))1977/* If you intend to change the filter list after the first row using the1978* previous API call png_set_row_buffers(png_ptr, 1) if you intend to use UP,1979* AVG or Paeth filters.1980*1981* You can turn the buffering on and off dynamically, just as with1982* png_set_filter.1983*1984* The second argument should be 0 (off) or 1 (on). In the future it may be1985* used to control the maximum number of rows buffered.1986*/1987#endif /* WRITE_FILTER */19881989/* The PNG_FILTER_VALUE_ definitions (the filter values from the base PNG spec)1990* are valid arguments to png_set_filter() if only a single filter is to be1991* used. If multiple filters are to be allowed (the default is to allow any of1992* them) then a combination of the following masks must be used and the low1993* three bits of the argument to png_set_filter must be 0.1994*1995* The resultant argument fits in a single byte in either case.1996*/1997#define PNG_FILTER_MASK(value) (0x08 << (value))1998#define PNG_FILTER_NONE PNG_FILTER_MASK(PNG_FILTER_VALUE_NONE)1999#define PNG_FILTER_SUB PNG_FILTER_MASK(PNG_FILTER_VALUE_SUB)2000#define PNG_FILTER_UP PNG_FILTER_MASK(PNG_FILTER_VALUE_UP)2001#define PNG_FILTER_AVG PNG_FILTER_MASK(PNG_FILTER_VALUE_AVG)2002#define PNG_FILTER_PAETH PNG_FILTER_MASK(PNG_FILTER_VALUE_PAETH)20032004/* Then three convenience values. PNG_NO_FILTERS is the same as2005* PNG_FILTER_VALUE_NONE, but this is harmless because they mean the same thing.2006*/2007#define PNG_NO_FILTERS 0x002008#define PNG_FAST_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP)2009#define PNG_ALL_FILTERS (PNG_FAST_FILTERS | PNG_FILTER_AVG | PNG_FILTER_PAETH)20102011#ifdef PNG_WRITE_SUPPORTED2012#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */2013PNG_REMOVED(68, void, png_set_filter_heuristics,2014(png_structrp png_ptr, int heuristic_method, int num_weights,2015png_const_doublep filter_weights, png_const_doublep filter_costs),2016PNG_DEPRECATED)2017PNG_REMOVED(209, void, png_set_filter_heuristics_fixed,2018(png_structrp png_ptr, int heuristic_method, int num_weights,2019png_const_fixed_point_p filter_weights,2020png_const_fixed_point_p filter_costs),2021PNG_DEPRECATED)2022/* Neither of these API calls did anything in libpng 1.6, however they were2023* not marked PNG_DEPRECATED, so they are converted to no-op function-like2024* macros here. (NOTE: the macro arguments are evaluated once each, this2025* will probably cause warnings with some compiler options: simply remove the2026* function call after ensuring that the arguments had no side effects.)2027*/2028#define png_set_filter_heuristics(p,m,w,fw,fc) ((void)(p,m,w,fw,fc))2029#define png_set_filter_heuristics_fixed(p,m,w,fw,fc) ((void)(p,m,w,fw,fc))2030#endif /* WRITE_WEIGHTED_FILTER */20312032#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED2033PNG_REMOVED(69, void, png_set_compression_level, (png_structrp png_ptr,2034int level), PNG_EMPTY)2035#define png_set_compression_level(p, v) (png_setting((p),\2036PNG_SW_COMPRESS_zlib_level, png_IDAT, (v)))20372038PNG_REMOVED(70, void, png_set_compression_mem_level, (png_structrp png_ptr,2039int mem_level), PNG_EMPTY)2040#define png_set_compression_mem_level(p, v) (png_setting((p),\2041PNG_SW_COMPRESS_memLevel, png_IDAT, (v)))20422043PNG_REMOVED(71, void, png_set_compression_strategy, (png_structrp png_ptr,2044int strategy), PNG_EMPTY)2045#define png_set_compression_strategy(p, v) (png_setting((p),\2046PNG_SW_COMPRESS_strategy, png_IDAT, (v)))20472048PNG_REMOVED(72, void, png_set_compression_window_bits, (png_structrp png_ptr,2049int window_bits), PNG_EMPTY)2050#define png_set_compression_window_bits(p, v) (png_setting((p),\2051PNG_SW_COMPRESS_windowBits, png_IDAT, (v)))20522053PNG_REMOVED(73, void, png_set_compression_method, (png_structrp png_ptr,2054int method), PNG_EMPTY)2055#define png_set_compression_method(p, v) (png_setting((p),\2056PNG_SW_COMPRESS_method, png_IDAT, (v)))2057#endif /* WRITE_CUSTOMIZE_COMPRESSION */20582059#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED2060/* Also set zlib parameters for compressing non-IDAT chunks */2061PNG_REMOVED(222, void, png_set_text_compression_level, (png_structrp png_ptr,2062int level), PNG_EMPTY)2063#define png_set_text_compression_level(p, v) (png_setting((p),\2064PNG_SW_COMPRESS_zlib_level, png_zTXt, (v)))20652066PNG_REMOVED(223, void, png_set_text_compression_mem_level,2067(png_structrp png_ptr, int mem_level), PNG_EMPTY)2068#define png_set_text_compression_mem_level(p, v) (png_setting((p),\2069PNG_SW_COMPRESS_memLevel, png_zTXt, (v)))20702071PNG_REMOVED(224, void, png_set_text_compression_strategy, (png_structrp png_ptr,2072int strategy), PNG_EMPTY)2073#define png_set_text_compression_strategy(p, v) (png_setting((p),\2074PNG_SW_COMPRESS_strategy, png_zTXt, (v)))20752076PNG_REMOVED(225, void, png_set_text_compression_window_bits,2077(png_structrp png_ptr, int window_bits), PNG_EMPTY)2078#define png_set_text_compression_window_bits(p, v) (png_setting((p),\2079PNG_SW_COMPRESS_windowBits, png_zTXt, (v)))20802081PNG_REMOVED(226, void, png_set_text_compression_method, (png_structrp png_ptr,2082int method), PNG_EMPTY)2083#define png_set_text_compression_method(p, v) (png_setting((p),\2084PNG_SW_COMPRESS_method, png_zTXt, (v)))20852086/* NOTE: in versions of libpng prior to 1.7 iCCP compression was controlled by2087* the text settings, hence the controls were only available if2088* PNG_WRITE_CUSTOMIZIZE_ZTXT_COMPRESSION_SUPPORTED. In 1.7 the text settings2089* no longer affect iCCP compression, the following macros must be used (if2090* necessary):2091*/2092#define png_set_ICC_profile_compression_level(p, v) (png_setting((p),\2093PNG_SW_COMPRESS_zlib_level, png_iCCP, (v)))2094#define png_set_ICC_profile_compression_mem_level(p, v) (png_setting((p),\2095PNG_SW_COMPRESS_memLevel, png_iCCP, (v)))2096#define png_set_ICC_profile_compression_strategy(p, v) (png_setting((p),\2097PNG_SW_COMPRESS_strategy, png_iCCP, (v)))2098#define png_set_ICC_profile_compression_window_bits(p, v) (png_setting((p),\2099PNG_SW_COMPRESS_windowBits, png_iCCP, (v)))2100#define png_set_ICC_profile_compression_method(p, v) (png_setting((p),\2101PNG_SW_COMPRESS_method, png_iCCP, (v)))2102#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */2103#endif /* WRITE */21042105/* These next functions are called for input/output, memory, and error2106* handling. They are in the file pngrio.c, pngwio.c, and pngerror.c,2107* and call standard C I/O routines such as fread(), fwrite(), and2108* fprintf(). These functions can be made to use other I/O routines2109* at run time for those applications that need to handle I/O in a2110* different manner by calling png_set_???_fn(). See libpng-manual.txt for2111* more information.2112*/21132114#ifdef PNG_STDIO_SUPPORTED2115/* Initialize the input/output for the PNG file to the default functions. */2116PNG_EXPORT(74, void, png_init_io, (png_structrp png_ptr, png_FILE_p fp));2117#endif21182119/* Replace the (error and abort), and warning functions with user2120* supplied functions. If no messages are to be printed you must still2121* write and use replacement functions. The replacement error_fn should2122* still do a longjmp to the last setjmp location if you are using this2123* method of error handling. If error_fn or warning_fn is NULL, the2124* default function will be used.2125*/21262127PNG_EXPORT(75, void, png_set_error_fn, (png_structrp png_ptr,2128png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));21292130/* Return the user pointer associated with the error functions */2131PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structrp png_ptr));21322133/* Replace the default data output functions with a user supplied one(s).2134* If buffered output is not used, then output_flush_fn can be set to NULL.2135* If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time2136* output_flush_fn will be ignored (and thus can be NULL).2137* It is probably a mistake to use NULL for output_flush_fn if2138* write_data_fn is not also NULL unless you have built libpng with2139* PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's2140* default flush function, which uses the standard *FILE structure, will2141* be used.2142*/2143PNG_EXPORT(77, void, png_set_write_fn, (png_structrp png_ptr, png_voidp io_ptr,2144png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));21452146/* Replace the default data input function with a user supplied one. */2147PNG_EXPORT(78, void, png_set_read_fn, (png_structrp png_ptr, png_voidp io_ptr,2148png_rw_ptr read_data_fn));21492150/* Return the user pointer associated with the I/O functions */2151PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_const_structrp png_ptr));21522153PNG_EXPORT(80, void, png_set_read_status_fn, (png_structrp png_ptr,2154png_read_status_ptr read_row_fn));21552156PNG_EXPORT(81, void, png_set_write_status_fn, (png_structrp png_ptr,2157png_write_status_ptr write_row_fn));21582159#ifdef PNG_USER_MEM_SUPPORTED2160/* Replace the default memory allocation functions with user supplied one(s). */2161PNG_EXPORT(82, void, png_set_mem_fn, (png_structrp png_ptr, png_voidp mem_ptr,2162png_malloc_ptr malloc_fn, png_free_ptr free_fn));2163/* Return the user pointer associated with the memory functions */2164PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structrp png_ptr));2165#endif21662167#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED2168PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structrp png_ptr,2169png_user_transform_ptr read_user_transform_fn));2170#endif21712172#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED2173PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structrp png_ptr,2174png_user_transform_ptr write_user_transform_fn));2175#endif21762177#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED2178PNG_EXPORT(86, void, png_set_user_transform_info, (png_structrp png_ptr,2179png_voidp user_transform_ptr, int user_transform_depth,2180int user_transform_channels));2181/* Return the user pointer associated with the user transform functions */2182PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr,2183(png_const_structrp png_ptr));2184#endif21852186#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED2187/* Return information about the row currently being processed. Note that these2188* APIs do not fail but will return unexpected results if called outside a user2189* transform callback. Also note that when transforming an interlaced image the2190* row number is the row number within the sub-image of the interlace pass, so2191* the value will increase to the height of the sub-image (not the full image)2192* then reset to 0 for the next pass.2193*2194* Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to2195* find the output pixel (x,y) given an interlaced sub-image pixel2196* (row,col,pass). (See below for these macros.)2197*/2198PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structrp));2199PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp));2200#endif22012202#ifdef PNG_READ_USER_CHUNKS_SUPPORTED2203/* This callback is called only for *unknown* chunks. If2204* PNG_HANDLE_AS_UNKNOWN_SUPPORTED is set then it is possible to set known2205* chunks to be treated as unknown, however in this case the callback must do2206* any processing required by the chunk and this is not possible for any chunk2207* that affects the image reading (e.g. PLTE, tRNS).2208*2209* There is no write support - on write, by default, all the chunks in the2210* 'unknown' list are written in the specified position.2211*2212* The integer return from the callback function is interpreted thus:2213*2214* negative: An error occurred; png_chunk_error will be called.2215* zero: The chunk was not handled, the default unknown handling is used2216* (even if this was a chunk that would otherwise be known.)2217* NOTE: prior to libpng 1.7 handling values of2218* PNG_HANDLE_CHUNK_AS_DEFAULT and PNG_HANDLE_CHUNK_NEVER were2219* converted to PNG_HANDLE_CHUNK_IF_SAFE (libpng 1.6.0 warns if this2220* happens) so it was not possible to discard unknown chunk data if a2221* user callback was installed.2222* positive: The chunk was handled, libpng will ignore/discard it.2223*2224* WARNING: if this callback is set every chunk in the stream is temporarily2225* read into a memory buffer. This has potential performance implications,2226* particularly for small PNG images with large amounts of ancilliary2227* information.2228*/2229PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr,2230png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));2231#endif22322233#ifdef PNG_USER_CHUNKS_SUPPORTED2234PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structrp png_ptr));2235#endif22362237#ifdef PNG_PROGRESSIVE_READ_SUPPORTED2238/* Sets the function callbacks for the push reader, and a pointer to a2239* user-defined structure available to the callback functions.2240*/2241PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structrp png_ptr,2242png_voidp progressive_ptr, png_progressive_info_ptr info_fn,2243png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn));22442245/* Returns the user pointer associated with the push read functions */2246PNG_EXPORT(91, png_voidp, png_get_progressive_ptr,2247(png_const_structrp png_ptr));22482249/* Function to be called when data becomes available */2250PNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr,2251png_inforp info_ptr, png_bytep buffer, size_t buffer_size));22522253/* A function which may be called *only* within png_process_data to stop the2254* processing of any more data. The function returns the number of bytes2255* remaining, excluding any that libpng has cached internally. A subsequent2256* call to png_process_data must supply these bytes again. If the argument2257* 'save' is set to true the routine will first save all the pending data and2258* will always return 0.2259*/2260PNG_EXPORT(219, size_t, png_process_data_pause, (png_structrp, int save));22612262/* A function which may be called *only* outside (after) a call to2263* png_process_data. It returns the number of bytes of data to skip in the2264* input. Normally it will return 0, but if it returns a non-zero value the2265* application must skip than number of bytes of input data and pass the2266* following data to the next call to png_process_data.2267*/2268PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structrp));22692270#ifdef PNG_READ_INTERLACING_SUPPORTED2271/* Function that combines rows. 'new_row' is a flag that should come from2272* the callback and be non-NULL if anything needs to be done; the library2273* stores its own version of the new data internally and ignores the passed2274* in value.2275*/2276PNG_EXPORT(93, void, png_progressive_combine_row, (png_const_structrp png_ptr,2277png_bytep old_row, png_const_bytep new_row));2278#endif /* READ_INTERLACING */2279#endif /* PROGRESSIVE_READ */22802281PNG_EXPORTA(94, png_voidp, png_malloc, (png_const_structrp png_ptr,2282png_alloc_size_t size), PNG_ALLOCATED);2283/* Added at libpng version 1.4.0 */2284PNG_EXPORTA(95, png_voidp, png_calloc, (png_const_structrp png_ptr,2285png_alloc_size_t size), PNG_ALLOCATED);22862287/* Added at libpng version 1.2.4 */2288PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_const_structrp png_ptr,2289png_alloc_size_t size), PNG_ALLOCATED);22902291/* Frees a pointer allocated by png_malloc() */2292PNG_EXPORT(97, void, png_free, (png_const_structrp png_ptr, png_voidp ptr));22932294/* Free data that was allocated internally */2295PNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr,2296png_inforp info_ptr, png_uint_32 free_me, int num));22972298/* Reassign responsibility for freeing existing data, whether allocated2299* by libpng or by the application; this works on the png_info structure passed2300* in, it does not change the state for other png_info structures.2301*2302* It is unlikely that this function works correctly as of 1.6.0 and using it2303* may result either in memory leaks or double free of allocated data. It was2304* removed in libpng 1.7.0.2305*/2306PNG_REMOVED(99, void, png_data_freer, (png_const_structrp png_ptr,2307png_inforp info_ptr, int freer, png_uint_32 mask), PNG_DEPRECATED)23082309/* Flags for png_free_data */2310#define PNG_FREE_HIST 0x0008U2311#define PNG_FREE_ICCP 0x0010U2312#define PNG_FREE_SPLT 0x0020U2313#define PNG_FREE_ROWS 0x0040U2314#define PNG_FREE_PCAL 0x0080U2315#define PNG_FREE_SCAL 0x0100U2316#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED2317# define PNG_FREE_UNKN 0x0200U2318#endif2319/* PNG_FREE_LIST 0x0400U removed in 1.6.0 because it is ignored */2320#define PNG_FREE_PLTE 0x1000U2321#define PNG_FREE_TRNS 0x2000U2322#define PNG_FREE_TEXT 0x4000U2323#define PNG_FREE_ALL 0x7fffU2324#define PNG_FREE_MUL 0x4220U /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */23252326#ifdef PNG_USER_MEM_SUPPORTED2327/* These were deprecated in libpng 1.6.0 and have been removed from libpng2328* 1.7.0; the functionality should be accessed by calling malloc or free2329* directly or, if png_error handling is required, calling png_malloc.2330*/2331PNG_REMOVED(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr,2332png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED)2333PNG_REMOVED(101, void, png_free_default, (png_const_structrp png_ptr,2334png_voidp ptr), PNG_DEPRECATED)2335#endif23362337#ifdef PNG_ERROR_TEXT_SUPPORTED2338/* Fatal error in PNG image of libpng - can't continue */2339PNG_EXPORTA(102, void, png_error, (png_const_structrp png_ptr,2340png_const_charp error_message), PNG_NORETURN);2341#else2342/* Fatal error in PNG image of libpng - can't continue */2343PNG_EXPORTA(104, void, png_err, (png_const_structrp png_ptr), PNG_NORETURN);2344# define png_error(s1,s2) png_err(s1)2345#endif23462347#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)2348/* The same, but the chunk name is prepended to the error string. */2349PNG_EXPORTA(103, void, png_chunk_error, (png_const_structrp png_ptr,2350png_const_charp error_message), PNG_NORETURN);2351#else2352# define png_chunk_error(s1,s2) png_error(s1,s2)2353#endif23542355#ifdef PNG_WARNINGS_SUPPORTED2356/* Non-fatal error in libpng. Can continue, but may have a problem. */2357PNG_EXPORT(105, void, png_warning, (png_const_structrp png_ptr,2358png_const_charp warning_message));23592360/* Non-fatal error in libpng, chunk name is prepended to message. */2361PNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr,2362png_const_charp warning_message));2363#else2364# define png_warning(s1,s2) ((void)(s1))2365# define png_chunk_warning(s1,s2) ((void)(s1))2366#endif23672368#ifdef PNG_BENIGN_ERRORS_SUPPORTED2369/* Benign error in libpng. Can continue, but may have a problem.2370* User can choose whether to handle as a fatal error or as a warning. */2371PNG_EXPORT(107, void, png_benign_error, (png_const_structrp png_ptr,2372png_const_charp warning_message));23732374#ifdef PNG_READ_SUPPORTED2375/* Same, chunk name is prepended to message (only during read) */2376PNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structrp png_ptr,2377png_const_charp warning_message));2378#endif23792380#define png_set_error_action(png_ptr, what, action)\2381(png_setting((png_ptr), PNG_SRW_ERROR_HANDLING, (what), (action)))2382/* Control the handling of 'benign' errors; errors that can be handled in2383* some way. The action is one of the following values:2384*/2385#define PNG_IGNORE 0 /* ignore the error; no warning or error message */2386#define PNG_WARN 1 /* call png_warning with an appropriate error message */2387#define PNG_ERROR 2 /* call png_error with the error message */2388/* 'what' is a list (bit mask) of the errors to set: */2389#define PNG_BENIGN_ERRORS (1U)2390#define PNG_APP_WARNINGS (2U)2391#define PNG_APP_ERRORS (4U)2392#define PNG_IDAT_ERRORS (8U)2393#define PNG_SAFE_ERRORS (PNG_BENIGN_ERRORS+PNG_APP_WARNINGS+PNG_APP_ERRORS)2394#define PNG_ALL_ERRORS (PNG_SAFE_ERRORS+PNG_IDAT_ERRORS)23952396PNG_REMOVED(109, void, png_set_benign_errors,2397(png_structrp png_ptr, int allowed), PNG_EMPTY)2398#define png_set_benign_errors(png_ptr, allowed) (png_setting((png_ptr),\2399PNG_SRW_ERROR_HANDLING, PNG_SAFE_ERRORS,\2400(allowed) ? PNG_WARN : PNG_ERROR))2401/* Turn all errors that can be handled into warnings, or turn them back into2402* errors if 'allowed' is false.2403*/24042405#else2406# ifdef PNG_ALLOW_BENIGN_ERRORS2407# define png_benign_error(pp,e) png_warning(pp,e)2408# define png_chunk_benign_error(pp,e) png_chunk_warning(pp,e)2409# else2410# define png_benign_error(pp,e) png_error(pp,e)2411# define png_chunk_benign_error(pp,e) png_chunk_error(pp,e)2412# endif2413#endif24142415/* The png_set_<chunk> functions are for storing values in the png_info_struct.2416* Similarly, the png_get_<chunk> calls are used to read values from the2417* png_info_struct, either storing the parameters in the passed variables, or2418* setting pointers into the png_info_struct where the data is stored. The2419* png_get_<chunk> functions return a non-zero value if the data was available2420* in info_ptr, or return zero and do not change any of the parameters if the2421* data was not available.2422*2423* These functions should be used instead of directly accessing png_info2424* to avoid problems with future changes in the size and internal layout of2425* png_info_struct.2426*/2427/* Returns "flag" if chunk data is valid in info_ptr. */2428PNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr,2429png_const_inforp info_ptr, png_uint_32 flag));24302431/* Returns number of bytes needed to hold a transformed row. */2432PNG_EXPORT(111, png_alloc_size_t, png_get_rowbytes, (png_const_structrp png_ptr,2433png_const_inforp info_ptr));24342435#ifdef PNG_READ_PNG_SUPPORTED2436/* Returns row_pointers, which is an array of pointers to scanlines that was2437* returned from png_read_png().2438*/2439PNG_EXPORT(112, png_bytepp, png_get_rows, (png_const_structrp png_ptr,2440png_const_inforp info_ptr));2441#endif24422443#ifdef PNG_WRITE_PNG_SUPPORTED2444/* Set row_pointers, which is an array of pointers to scanlines for use2445* by png_write_png().2446*/2447PNG_EXPORT(113, void, png_set_rows, (png_const_structrp png_ptr,2448png_inforp info_ptr, png_bytepp row_pointers));2449#endif24502451/* Returns number of color channels in image. */2452PNG_EXPORT(114, png_byte, png_get_channels, (png_const_structrp png_ptr,2453png_const_inforp info_ptr));24542455#ifdef PNG_EASY_ACCESS_SUPPORTED2456/* Returns image width in pixels. */2457PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structrp png_ptr,2458png_const_inforp info_ptr));24592460/* Returns image height in pixels. */2461PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structrp png_ptr,2462png_const_inforp info_ptr));24632464/* Returns image bit_depth. */2465PNG_EXPORT(117, png_byte, png_get_bit_depth, (png_const_structrp png_ptr,2466png_const_inforp info_ptr));24672468/* Returns image color_type. */2469PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structrp png_ptr,2470png_const_inforp info_ptr));24712472/* Returns image filter_type. */2473PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structrp png_ptr,2474png_const_inforp info_ptr));24752476/* Returns image interlace_type. */2477PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structrp png_ptr,2478png_const_inforp info_ptr));24792480/* Returns image compression_type. */2481PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structrp png_ptr,2482png_const_inforp info_ptr));24832484/* Returns image resolution in pixels per meter, from pHYs chunk data. */2485PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter,2486(png_const_structrp png_ptr, png_const_inforp info_ptr));2487PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter,2488(png_const_structrp png_ptr, png_const_inforp info_ptr));2489PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter,2490(png_const_structrp png_ptr, png_const_inforp info_ptr));24912492/* Returns pixel aspect ratio, computed from pHYs chunk data. */2493PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio,2494(png_const_structrp png_ptr, png_const_inforp info_ptr))2495PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed,2496(png_const_structrp png_ptr, png_const_inforp info_ptr))24972498/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */2499PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels,2500(png_const_structrp png_ptr, png_const_inforp info_ptr));2501PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels,2502(png_const_structrp png_ptr, png_const_inforp info_ptr));2503PNG_EXPORT(128, png_int_32, png_get_x_offset_microns,2504(png_const_structrp png_ptr, png_const_inforp info_ptr));2505PNG_EXPORT(129, png_int_32, png_get_y_offset_microns,2506(png_const_structrp png_ptr, png_const_inforp info_ptr));25072508#endif /* EASY_ACCESS */25092510#ifdef PNG_READ_SUPPORTED2511/* Returns pointer to signature string read from PNG header */2512PNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structrp png_ptr,2513png_const_inforp info_ptr));2514#endif25152516#ifdef PNG_bKGD_SUPPORTED2517PNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structrp png_ptr,2518png_inforp info_ptr, png_color_16p *background));2519#endif25202521#ifdef PNG_bKGD_SUPPORTED2522PNG_EXPORT(132, void, png_set_bKGD, (png_const_structrp png_ptr,2523png_inforp info_ptr, png_const_color_16p background));2524#endif25252526#ifdef PNG_cHRM_SUPPORTED2527PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structrp png_ptr,2528png_const_inforp info_ptr, double *white_x, double *white_y, double *red_x,2529double *red_y, double *green_x, double *green_y, double *blue_x,2530double *blue_y))2531PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structrp png_ptr,2532png_const_inforp info_ptr, double *red_X, double *red_Y, double *red_Z,2533double *green_X, double *green_Y, double *green_Z, double *blue_X,2534double *blue_Y, double *blue_Z))2535PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed,2536(png_const_structrp png_ptr, png_const_inforp info_ptr,2537png_fixed_point *int_white_x, png_fixed_point *int_white_y,2538png_fixed_point *int_red_x, png_fixed_point *int_red_y,2539png_fixed_point *int_green_x, png_fixed_point *int_green_y,2540png_fixed_point *int_blue_x, png_fixed_point *int_blue_y))2541PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed,2542(png_const_structrp png_ptr, png_const_inforp info_ptr,2543png_fixed_point *int_red_X, png_fixed_point *int_red_Y,2544png_fixed_point *int_red_Z, png_fixed_point *int_green_X,2545png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,2546png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,2547png_fixed_point *int_blue_Z))2548#endif25492550#ifdef PNG_cHRM_SUPPORTED2551PNG_FP_EXPORT(135, void, png_set_cHRM, (png_const_structrp png_ptr,2552png_inforp info_ptr,2553double white_x, double white_y, double red_x, double red_y, double green_x,2554double green_y, double blue_x, double blue_y))2555PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_const_structrp png_ptr,2556png_inforp info_ptr, double red_X, double red_Y, double red_Z,2557double green_X, double green_Y, double green_Z, double blue_X,2558double blue_Y, double blue_Z))2559PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_const_structrp png_ptr,2560png_inforp info_ptr, png_fixed_point int_white_x,2561png_fixed_point int_white_y, png_fixed_point int_red_x,2562png_fixed_point int_red_y, png_fixed_point int_green_x,2563png_fixed_point int_green_y, png_fixed_point int_blue_x,2564png_fixed_point int_blue_y))2565PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr,2566png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y,2567png_fixed_point int_red_Z, png_fixed_point int_green_X,2568png_fixed_point int_green_Y, png_fixed_point int_green_Z,2569png_fixed_point int_blue_X, png_fixed_point int_blue_Y,2570png_fixed_point int_blue_Z))2571#endif25722573#ifdef PNG_gAMA_SUPPORTED2574PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr,2575png_const_inforp info_ptr, double *file_gamma))2576PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed,2577(png_const_structrp png_ptr, png_const_inforp info_ptr,2578png_fixed_point *int_file_gamma))2579#endif25802581#ifdef PNG_gAMA_SUPPORTED2582PNG_FP_EXPORT(139, void, png_set_gAMA, (png_const_structrp png_ptr,2583png_inforp info_ptr, double file_gamma))2584PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr,2585png_inforp info_ptr, png_fixed_point int_file_gamma))2586#endif25872588#ifdef PNG_hIST_SUPPORTED2589PNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr,2590png_inforp info_ptr, png_uint_16p *hist));2591#endif25922593#ifdef PNG_hIST_SUPPORTED2594PNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr,2595png_inforp info_ptr, png_const_uint_16p hist));2596#endif25972598PNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_const_structrp png_ptr,2599png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height,2600int *bit_depth, int *color_type, int *interlace_method,2601int *compression_method, int *filter_method));26022603PNG_EXPORT(144, void, png_set_IHDR, (png_const_structrp png_ptr,2604png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,2605int color_type, int interlace_method, int compression_method,2606int filter_method));26072608#ifdef PNG_oFFs_SUPPORTED2609PNG_EXPORT(145, png_uint_32, png_get_oFFs, (png_const_structrp png_ptr,2610png_const_inforp info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,2611int *unit_type));2612#endif26132614#ifdef PNG_oFFs_SUPPORTED2615PNG_EXPORT(146, void, png_set_oFFs, (png_const_structrp png_ptr,2616png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y,2617int unit_type));2618#endif26192620#ifdef PNG_pCAL_SUPPORTED2621PNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structrp png_ptr,2622png_inforp info_ptr, png_charp *purpose, png_int_32 *X0,2623png_int_32 *X1, int *type, int *nparams, png_charp *units,2624png_charpp *params));2625#endif26262627#ifdef PNG_pCAL_SUPPORTED2628PNG_EXPORT(148, void, png_set_pCAL, (png_const_structrp png_ptr,2629png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1,2630int type, int nparams, png_const_charp units, png_charpp params));2631#endif26322633#ifdef PNG_pHYs_SUPPORTED2634PNG_EXPORT(149, png_uint_32, png_get_pHYs, (png_const_structrp png_ptr,2635png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,2636int *unit_type));2637#endif26382639#ifdef PNG_pHYs_SUPPORTED2640PNG_EXPORT(150, void, png_set_pHYs, (png_const_structrp png_ptr,2641png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));2642#endif26432644PNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structrp png_ptr,2645png_inforp info_ptr, png_colorp *palette, int *num_palette));26462647PNG_EXPORT(152, void, png_set_PLTE, (png_structrp png_ptr,2648png_inforp info_ptr, png_const_colorp palette, int num_palette));26492650#ifdef PNG_sBIT_SUPPORTED2651PNG_EXPORT(153, png_uint_32, png_get_sBIT, (png_const_structrp png_ptr,2652png_inforp info_ptr, png_color_8p *sig_bit));2653#endif26542655#ifdef PNG_sBIT_SUPPORTED2656PNG_EXPORT(154, void, png_set_sBIT, (png_const_structrp png_ptr,2657png_inforp info_ptr, png_const_color_8p sig_bit));2658#endif26592660#ifdef PNG_sRGB_SUPPORTED2661PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structrp png_ptr,2662png_const_inforp info_ptr, int *file_srgb_intent));2663#endif26642665#ifdef PNG_sRGB_SUPPORTED2666PNG_EXPORT(156, void, png_set_sRGB, (png_const_structrp png_ptr,2667png_inforp info_ptr, int srgb_intent));2668PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_const_structrp png_ptr,2669png_inforp info_ptr, int srgb_intent));2670#endif26712672#ifdef PNG_iCCP_SUPPORTED2673PNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structrp png_ptr,2674png_inforp info_ptr, png_charpp name, int *compression_type,2675png_bytepp profile, png_uint_32 *proflen));2676#endif26772678#ifdef PNG_iCCP_SUPPORTED2679PNG_EXPORT(159, void, png_set_iCCP, (png_const_structrp png_ptr,2680png_inforp info_ptr, png_const_charp name, int compression_type,2681png_const_bytep profile, png_uint_32 proflen));2682#endif26832684#ifdef PNG_sPLT_SUPPORTED2685PNG_EXPORT(160, int, png_get_sPLT, (png_const_structrp png_ptr,2686png_inforp info_ptr, png_sPLT_tpp entries));2687#endif26882689#ifdef PNG_sPLT_SUPPORTED2690PNG_EXPORT(161, void, png_set_sPLT, (png_structrp png_ptr,2691png_inforp info_ptr, png_const_sPLT_tp entries, int nentries));2692#endif26932694#ifdef PNG_TEXT_SUPPORTED2695/* png_get_text also returns the number of text chunks in *num_text */2696PNG_EXPORT(162, int, png_get_text, (png_const_structrp png_ptr,2697png_inforp info_ptr, png_textp *text_ptr, int *num_text));2698#endif26992700/* Note while png_set_text() will accept a structure whose text,2701* language, and translated keywords are NULL pointers, the structure2702* returned by png_get_text will always contain regular2703* zero-terminated C strings. They might be empty strings but2704* they will never be NULL pointers.2705*/27062707#ifdef PNG_TEXT_SUPPORTED2708PNG_EXPORT(163, void, png_set_text, (png_structrp png_ptr,2709png_inforp info_ptr, png_const_textp text_ptr, int num_text));2710#endif27112712#ifdef PNG_tIME_SUPPORTED2713PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr,2714png_inforp info_ptr, png_timep *mod_time));2715#endif27162717#ifdef PNG_tIME_SUPPORTED2718PNG_EXPORT(165, void, png_set_tIME, (png_const_structrp png_ptr,2719png_inforp info_ptr, png_const_timep mod_time));2720#endif27212722#ifdef PNG_tRNS_SUPPORTED2723PNG_EXPORT(166, png_uint_32, png_get_tRNS, (png_const_structrp png_ptr,2724png_inforp info_ptr, png_bytep *trans_alpha, int *num_trans,2725png_color_16p *trans_color));2726#endif27272728#ifdef PNG_tRNS_SUPPORTED2729PNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr,2730png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans,2731png_const_color_16p trans_color));2732#endif27332734#ifdef PNG_sCAL_SUPPORTED2735#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED2736/* NOTE: these API are currently implemented using floating point arithmetic,2737* consequently they can only be used on systems with floating point support.2738* In any case the range of values supported by png_fixed_point is small and it2739* is highly recommended that png_get_sCAL_s be used instead.2740*/2741PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr,2742png_const_inforp info_ptr, int *unit, double *width, double *height))2743PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed,2744(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,2745png_fixed_point *width, png_fixed_point *height))2746#endif2747PNG_EXPORT(169, png_uint_32, png_get_sCAL_s,2748(png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,2749png_charpp swidth, png_charpp sheight));27502751#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED2752/* This also requires internal floating point arithmetic support - i.e. it2753* requires a full math library, not just floating point handling.2754*/2755PNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr,2756png_inforp info_ptr, int unit, double width, double height))2757#endif2758PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr,2759png_inforp info_ptr, int unit, png_fixed_point width,2760png_fixed_point height))2761PNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr,2762png_inforp info_ptr, int unit,2763png_const_charp swidth, png_const_charp sheight));2764#endif /* sCAL */27652766#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED2767/* Provide the default handling for all unknown chunks or, optionally, for2768* specific unknown chunks.2769*2770* NOTE: prior to 1.6.0 the handling specified for particular chunks on read was2771* ignored and the default was used, the per-chunk setting only had an effect on2772* write. If you wish to have chunk-specific handling on read in code that must2773* work on earlier versions you must use a user chunk callback to implement the2774* desired handling (keep or discard.)2775*2776* NOTE: prior to 1.7.0 when a user callback returned '0', indicating that the2777* chunk had not been handled, libpng would preserve it regardless of the2778* default or per-chunk settings. For compatibility with earlier versions2779* simply return '1' (handled) from the callback to discard the chunk.2780*2781* The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below. The2782* parameter is interpreted as follows:2783*2784* READ:2785* PNG_HANDLE_CHUNK_AS_DEFAULT:2786* Known chunks: do normal libpng processing, do not keep the chunk (but2787* see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED)2788* Unknown chunks: for a specific chunk use the global default, when used2789* as the default discard the chunk data.2790* PNG_HANDLE_CHUNK_NEVER:2791* Discard the chunk data.2792* PNG_HANDLE_CHUNK_IF_SAFE:2793* Keep the chunk data if the chunk is not critical else raise a chunk2794* error.2795* PNG_HANDLE_CHUNK_ALWAYS:2796* Keep the chunk data.2797*2798* If the chunk data is saved it can be retrieved using png_get_unknown_chunks,2799* below. Notice that specifying "AS_DEFAULT" as a global default is equivalent2800* to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks2801* it simply resets the behavior to the libpng default.2802*2803* The per-chunk handling is always used when there is a png_user_chunk_ptr2804* callback and the callback returns 0; the chunk is then always stored *unless*2805* it is critical and the per-chunk setting is other than ALWAYS. Notice that2806* the global default is *not* used in this case. (In effect the per-chunk2807* value is incremented to at least IF_SAFE.)2808*2809* PNG_HANDLE_AS_UNKNOWN_SUPPORTED:2810* If this is *not* set known chunks will always be handled by libpng and2811* will never be stored in the unknown chunk list. Known chunks listed to2812* png_set_keep_unknown_chunks will have no effect. If it is set then known2813* chunks listed with a keep other than AS_DEFAULT will *never* be processed2814* by libpng, in addition critical chunks must either be processed by the2815* callback or saved.2816*2817* The IHDR and IEND chunks must not be listed. Because this turns off the2818* default handling for chunks that would otherwise be recognized the2819* behavior of libpng transformations may well become incorrect!2820*2821* WRITE:2822* When writing chunks the options only apply to the chunks specified by2823* png_set_unknown_chunks (below), libpng will *always* write known chunks2824* required by png_set_ calls and will always write the core critical chunks2825* (as required for PLTE).2826*2827* Each chunk in the png_set_unknown_chunks list is looked up in the2828* png_set_keep_unknown_chunks list to find the keep setting, this is then2829* interpreted as follows:2830*2831* PNG_HANDLE_CHUNK_AS_DEFAULT:2832* Write safe-to-copy chunks and write other chunks if the global2833* default is set to _ALWAYS, otherwise don't write this chunk.2834* PNG_HANDLE_CHUNK_NEVER:2835* Do not write the chunk.2836* PNG_HANDLE_CHUNK_IF_SAFE:2837* Write the chunk if it is safe-to-copy, otherwise do not write it.2838* PNG_HANDLE_CHUNK_ALWAYS:2839* Write the chunk.2840*2841* Note that the default behavior is effectively the opposite of the read case -2842* in read unknown chunks are not stored by default, in write they are written2843* by default. Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different2844* - on write the safe-to-copy bit is checked, on read the critical bit is2845* checked and on read if the chunk is critical an error will be raised.2846*2847* num_chunks:2848* ===========2849* If num_chunks is positive, then the "keep" parameter specifies the manner2850* for handling only those chunks appearing in the chunk_list array,2851* otherwise the chunk list array is ignored.2852*2853* If num_chunks is 0 the "keep" parameter specifies the default behavior for2854* unknown chunks, as described above.2855*2856* If num_chunks is negative, then the "keep" parameter specifies the manner2857* for handling all unknown chunks plus all chunks recognized by libpng2858* except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to2859* be processed by libpng.2860*/2861#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED2862PNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr,2863int keep, png_const_bytep chunk_list, int num_chunks));2864#endif /* HANDLE_AS_UNKNOWN */28652866/* The "keep" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned;2867* the result is therefore true (non-zero) if special handling is required,2868* false for the default handling.2869*/2870PNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr,2871png_const_bytep chunk_name));2872#endif /* SET_UNKNOWN_CHUNKS */28732874#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED2875PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structrp png_ptr,2876png_inforp info_ptr, png_const_unknown_chunkp unknowns,2877int num_unknowns));2878/* NOTE: prior to 1.6.0 this routine set the 'location' field of the added2879* unknowns to the location currently stored in the png_struct. This is2880* invariably the wrong value on write. To fix this call the following API2881* for each chunk in the list with the correct location. If you know your2882* code won't be compiled on earlier versions you can rely on2883* png_set_unknown_chunks(write-ptr, png_get_unknown_chunks(read-ptr)) doing2884* the correct thing.2885*2886* API CHANGE: in 1.7.0 this API will not work on read unless2887* PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED is set; it may be necessary to change2888* code to check the latter SUPPORTED flag. png_set_keep_unknown_chunks2889* will issue a warning if it is asked to save a chunk and there is no read2890* support.2891*/28922893PNG_EXPORT(175, void, png_set_unknown_chunk_location,2894(png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location));28952896PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structrp png_ptr,2897png_inforp info_ptr, png_unknown_chunkpp entries));2898#endif28992900/* Png_free_data() will turn off the "valid" flag for anything it frees.2901* If you need to turn it off for a chunk that your application has freed,2902* you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK);2903*/2904PNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr,2905png_inforp info_ptr, int mask));29062907/* The "params" pointer is currently not used and is for future expansion. */2908#ifdef PNG_READ_PNG_SUPPORTED2909PNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr,2910int transforms, png_voidp params));2911#endif2912#ifdef PNG_WRITE_PNG_SUPPORTED2913PNG_EXPORT(179, void, png_write_png, (png_structrp png_ptr, png_inforp info_ptr,2914int transforms, png_voidp params));2915#endif29162917PNG_EXPORT(180, png_const_charp, png_get_copyright,2918(png_const_structrp png_ptr));2919PNG_EXPORT(181, png_const_charp, png_get_header_ver,2920(png_const_structrp png_ptr));2921PNG_EXPORT(182, png_const_charp, png_get_header_version,2922(png_const_structrp png_ptr));2923PNG_EXPORT(183, png_const_charp, png_get_libpng_ver,2924(png_const_structrp png_ptr));29252926#ifdef PNG_MNG_FEATURES_SUPPORTED2927PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structrp png_ptr,2928png_uint_32 mng_features_permitted));2929#endif29302931/* For use in png_set_keep_unknown, added to version 1.2.6 */2932#define PNG_HANDLE_CHUNK_AS_DEFAULT 02933#define PNG_HANDLE_CHUNK_NEVER 12934#define PNG_HANDLE_CHUNK_IF_SAFE 22935#define PNG_HANDLE_CHUNK_ALWAYS 32936#define PNG_HANDLE_CHUNK_LAST 429372938#ifdef PNG_ERROR_NUMBERS_SUPPORTED2939/* This was never implemented: */2940PNG_REMOVED(185, void, png_set_strip_error_numbers, (png_structrp png_ptr,2941png_uint_32 strip_mode), PNG_EMPTY)2942#endif29432944/* Added in libpng-1.2.6 */2945#ifdef PNG_SET_USER_LIMITS_SUPPORTED2946PNG_EXPORT(186, void, png_set_user_limits, (png_structrp png_ptr,2947png_uint_32 user_width_max, png_uint_32 user_height_max));2948PNG_EXPORT(187, png_uint_32, png_get_user_width_max,2949(png_const_structrp png_ptr));2950PNG_EXPORT(188, png_uint_32, png_get_user_height_max,2951(png_const_structrp png_ptr));2952/* Added in libpng-1.4.0 */2953PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structrp png_ptr,2954png_uint_32 user_chunk_cache_max));2955PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max,2956(png_const_structrp png_ptr));2957/* Added in libpng-1.4.1 */2958PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structrp png_ptr,2959png_alloc_size_t user_chunk_cache_max));2960PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max,2961(png_const_structrp png_ptr));2962#endif29632964#if defined(PNG_INCH_CONVERSIONS_SUPPORTED)2965PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch,2966(png_const_structrp png_ptr, png_const_inforp info_ptr));29672968PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch,2969(png_const_structrp png_ptr, png_const_inforp info_ptr));29702971PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch,2972(png_const_structrp png_ptr, png_const_inforp info_ptr));29732974PNG_FP_EXPORT(196, float, png_get_x_offset_inches,2975(png_const_structrp png_ptr, png_const_inforp info_ptr))2976#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */2977PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed,2978(png_const_structrp png_ptr, png_const_inforp info_ptr))2979#endif29802981PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structrp png_ptr,2982png_const_inforp info_ptr))2983#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */2984PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed,2985(png_const_structrp png_ptr, png_const_inforp info_ptr))2986#endif29872988# ifdef PNG_pHYs_SUPPORTED2989PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structrp png_ptr,2990png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,2991int *unit_type));2992# endif /* pHYs */2993#endif /* INCH_CONVERSIONS */29942995/* Added in libpng-1.4.0 */2996#ifdef PNG_IO_STATE_SUPPORTED2997PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_const_structrp png_ptr));29982999/* Removed from libpng 1.6; use png_get_io_chunk_type. */3000PNG_REMOVED(200, png_const_bytep, png_get_io_chunk_name, (png_structrp png_ptr),3001PNG_DEPRECATED)30023003PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,3004(png_const_structrp png_ptr));30053006/* The flags returned by png_get_io_state() are the following: */3007# define PNG_IO_NONE 0x0000U /* no I/O at this moment */3008# define PNG_IO_READING 0x0001U /* currently reading */3009# define PNG_IO_WRITING 0x0002U /* currently writing */3010# define PNG_IO_SIGNATURE 0x0010U /* currently at the file signature */3011# define PNG_IO_CHUNK_HDR 0x0020U /* currently at the chunk header */3012# define PNG_IO_CHUNK_DATA 0x0040U /* currently at the chunk data */3013# define PNG_IO_CHUNK_CRC 0x0080U /* currently at the chunk crc */3014# define PNG_IO_MASK_OP 0x000fU /* current operation: reading/writing */3015# define PNG_IO_MASK_LOC 0x00f0U /* current location: sig/hdr/data/crc */3016#endif /* IO_STATE */30173018/* Interlace support. The following macros are always defined so that if3019* libpng interlace handling is turned off the macros may be used to handle3020* interlaced images within the application.3021*/3022#define PNG_INTERLACE_ADAM7_PASSES 730233024/* Two macros to return the first row and first column of the original,3025* full, image which appears in a given pass. 'pass' is in the range 03026* to 6 and the result is in the range 0 to 7.3027*/3028#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7)3029#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7)30303031/* A macro to return the offset between pixels in the output row for a pair of3032* pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that3033* follows. Note that ROW_OFFSET is the offset from one row to the next whereas3034* COL_OFFSET is from one column to the next, within a row.3035*/3036#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8)3037#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1))30383039/* Two macros to help evaluate the number of rows or columns in each3040* pass. This is expressed as a shift - effectively 3-log2 of the number or3041* rows or columns in each 8x8 tile of the original image.3042*/3043#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)3044#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)30453046/* Hence two macros to determine the number of rows or columns in a given3047* pass of an image given its height or width. In fact these macros may3048* return non-zero even though the sub-image is empty, because the other3049* dimension may be empty for a small image.3050*/3051#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\3052-1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))3053#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\3054-1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))30553056/* For the reader row callbacks (both progressive and sequential) it is3057* necessary to find the row in the output image given a row in an interlaced3058* image, so two more macros:3059*/3060#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \3061(((y_in)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))3062#define PNG_COL_FROM_PASS_COL(x_in, pass) \3063(((x_in)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))30643065/* Two macros which return a boolean (0 or 1) saying whether the given row3066* or column is in a particular pass. These use a common utility macro that3067* returns a mask for a given pass - the offset 'off' selects the row or3068* column version. The mask has the appropriate bit set for each column in3069* the tile.3070*/3071#define PNG_PASS_MASK(pass,off) ( \3072((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \3073((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0))30743075#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \3076((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)3077#define PNG_COL_IN_INTERLACE_PASS(x, pass) \3078((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)30793080/* Whether the pass is in the image at all, taking into account the full image3081* width and height, evaluates 'pass' lots of times, but width and height at3082* most once each.3083*/3084#define PNG_PASS_IN_IMAGE(width, height, pass)\3085((height) > PNG_PASS_START_ROW(pass) && (width) > PNG_PASS_START_COL(pass))30863087/* A macro to find the last pass (in the range 0 to 6) given an image width and3088* height. Then two macros two find whether a given image row or column which3089* is present in the pass is the last row or column in the pass. Note that3090* these macros return 'true' for earlier rows or columns of the image that are3091* *not* in the pass.3092*/3093#define PNG_LAST_PASS(width, height) ((height) > 1 ? 6 : ((width) > 1 ? 5 : 0))3094#define PNG_LAST_PASS_ROW(y, pass, height)\3095((y) + PNG_PASS_ROW_OFFSET(pass) >= (height))3096#define PNG_LAST_PASS_COL(x, pass, width)\3097((x) + PNG_PASS_COL_OFFSET(pass) >= (width))30983099#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED3100/* With these routines we avoid an integer divide, which will be slower on3101* most machines. However, it does take more operations than the corresponding3102* divide method, so it may be slower on a few RISC systems. There are two3103* shifts (by 8 or 16 bits) and an addition, versus a single integer divide.3104*3105* Note that the rounding factors are NOT supposed to be the same! 128 and3106* 32768 are correct for the NODIV code; 127 and 32767 are correct for the3107* standard method.3108*3109* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]3110*/31113112/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */31133114# define png_composite(composite, fg, alpha, bg) \3115{ png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \3116* (png_uint_16)(alpha) \3117+ (png_uint_16)(bg)*(png_uint_16)(255 \3118- (png_uint_16)(alpha)) + 128); \3119(composite) = (png_byte)((temp + (temp >> 8)) >> 8); }31203121# define png_composite_16(composite, fg, alpha, bg) \3122{ png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \3123* (png_uint_32)(alpha) \3124+ (png_uint_32)(bg)*(65535 \3125- (png_uint_32)(alpha)) + 32768); \3126(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }31273128#else /* Standard method using integer division */31293130# define png_composite(composite, fg, alpha, bg) \3131(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \3132(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \3133127) / 255)31343135# define png_composite_16(composite, fg, alpha, bg) \3136(composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \3137(png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \313832767) / 65535)3139#endif /* READ_COMPOSITE_NODIV */31403141#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED3142PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf));3143PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf));3144PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf));3145#endif31463147PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_const_structrp png_ptr,3148png_const_bytep buf));3149/* No png_get_int_16 -- may be added if there's a real need for it. */31503151/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */3152#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED3153PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i));31543155/* This becomes a macro in 1.7 because the old implementation was wrong; it3156* failed to do the cast. ANSI C requires the cast to convert a negative number3157* to the 2's complement form, so this just works:3158*/3159#define png_save_int_32(b, i) png_save_uint_32(b, i);3160#endif /* WRITE_INT_FUNCTIONS */31613162/* Apps that used this will use the macro in 1.7. */3163PNG_REMOVED(206, void, png_save_int_32, (png_bytep buf, png_int_32 i),3164PNG_DEPRECATED)31653166/* Place a 16-bit number into a buffer in PNG byte order.3167* The parameter is declared unsigned int, not png_uint_16,3168* just to avoid potential problems on pre-ANSI C compilers.3169*/3170#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED3171PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));3172/* No png_save_int_16 -- may be added if there's a real need for it. */3173#endif31743175#ifdef PNG_USE_READ_MACROS3176/* Inline macros to do direct reads of bytes from the input buffer.3177*/3178# define PNG_B(ptr, offset) (((png_const_bytep)(ptr))[offset])3179# define PNG_get_uint_32(buf) \3180PNG_U32(PNG_B(buf,0), PNG_B(buf,1), PNG_B(buf,2), PNG_B(buf,3))31813182/* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the3183* function) incorrectly returned a value of type png_uint_32.3184*/3185# define PNG_get_uint_16(buf) PNG_U16(PNG_B(buf,0), PNG_B(buf,1))31863187# define PNG_get_int_32(buf) \3188PNG_S32(PNG_B(buf,0), PNG_B(buf,1), PNG_B(buf,2), PNG_B(buf,3))31893190/* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h,3191* but defining a macro name prefixed with PNG_PREFIX.3192*/3193# ifndef PNG_PREFIX3194# define png_get_uint_32(buf) PNG_get_uint_32(buf)3195# define png_get_uint_16(buf) PNG_get_uint_16(buf)3196# define png_get_int_32(buf) PNG_get_int_32(buf)3197# endif3198#else3199# ifdef PNG_PREFIX3200/* No macros; revert to the (redefined) function */3201# define PNG_get_uint_32 (png_get_uint_32)3202# define PNG_get_uint_16 (png_get_uint_16)3203# define PNG_get_int_32 (png_get_int_32)3204# endif3205#endif32063207#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED3208PNG_REMOVED(242, void, png_set_check_for_invalid_index,3209(png_structrp png_ptr, int enabled_if_greater_than_0), PNG_EMPTY)3210#define png_set_check_for_invalid_index(png_ptr, value)\3211(png_setting((png_ptr), PNG_SRW_CHECK_FOR_INVALID_INDEX, 0, (value)))3212/* By default the check is enabled on both read and write when the number of3213* entries in the palette is less than the maximum required by the bit depth3214* of a palette image.3215*3216* Passing 1 to 'enabled' turns the check on in all cases.3217* Passing -1 turns it off and the PNG may have invalid palette index values.3218* Passing 0 restores the default.3219*3220* On read chunk (benign) error messages are only produced with the default3221* setting; it is assumed that when the check is turned on explicitly the3222* caller will call png_get_palette_max to check the result.3223*3224* The png_setting call returns 0.3225*/3226#endif /* CHECK_FOR_INVALID_INDEX */3227#ifdef PNG_GET_PALETTE_MAX_SUPPORTED3228PNG_EXPORT(243, int, png_get_palette_max, (png_const_structrp png_ptr,3229png_const_inforp info_ptr));3230/* The info_ptr is not used, it may be NULL in 1.7.0 (not in earlier3231* versions). If the information is not available because3232* png_set_check_for_invalid_index was not used to turn it on -1 is returned.3233* Valid results can only be obtained after the complete image has been read,3234* though it may be called at any time to get the result so far.3235*/3236#endif /* GET_PALETTE_MAX */32373238/* Memory format options; these return information about the layout of the3239* transformed row using the Simplified API PNG_FORMAT_ values (see below for3240* the #defines).3241*3242* These are only relevant if read or write transforms are supported; these3243* may cause the memory format of pixel data to differ from that used in the3244* PNG file itself. Nevertheless the APIs are supported regardless of whether3245* transforms are applied; use these to consistently and safely determine the3246* layout of the image in memory.3247*3248* Some of the same information can be obtained from png_info, however this3249* does not record whether the byte or bit formats have been changed.3250*/3251PNG_EXPORT(246, unsigned int, png_memory_format, (png_structrp png_ptr));3252/* The in-memory format as a bitmask of PNG_FORMAT_FLAG_ values. All the3253* flags listed below are used. If PNG_FORMAT_FLAG_INVALID is set the3254* following caveats apply to the interpretation of PNG_FORMAT_FLAG_LINEAR:3255*3256* The gamma may differ from the sRGB (!LINEAR) or 1.0 (LINEAR). Call3257* png_memory_gamma to find the correct value.3258*3259* The channel depth may differ from 8 (!LINEAR) or 16 (LINEAR). Call3260* png_memory_channel_depth to find the correct value.3261*3262* It is only valid to call these APIS *after* either png_read_update_info3263* or png_start_read_image on read or after the first row of an image has3264* been written on write.3265*3266* To find the number of channels in each pixel from the returned value,3267* 'fmt' use:3268*3269* PNG_FORMAT_CHANNELS(fmt)3270*/32713272PNG_EXPORT(247, unsigned int, png_memory_channel_depth, (png_structrp png_ptr));3273/* The actual depth of each channel in the image, to determine the full pixel3274* depth (in bits) use:3275*3276* png_memory_channel_depth(pp) * PNG_FORMAT_CHANNELS(fmt)3277*/32783279#ifdef PNG_GAMMA_SUPPORTED3280PNG_EXPORT(248, png_fixed_point, png_memory_gamma, (png_structrp png_ptr));3281/* The actual gamma of the image data, scaled by 100,000. This is the3282* encoding gamma, e.g. 1/2.2 for sRGB. If the gamma is unknown this will3283* return 0.3284*3285* On write this invariably returns 0; libpng does not change the gamma of3286* the data on write.3287*3288* Note that this is not always the exact inverse of the 'screen gamma'3289* passed to png_set_gamma; internal optimizations remove attempts to make3290* small changes to the gamma value. This function returns the actual3291* output value.3292*/3293#endif /* GAMMA */32943295/*******************************************************************************3296* Section 5: SIMPLIFIED API3297*******************************************************************************3298*3299* Please read the documentation in libpng-manual.txt (TODO: write said3300* documentation) if you don't understand what follows.3301*3302* The simplified API hides the details of both libpng and the PNG file format3303* itself. It allows PNG files to be read into a very limited number of3304* in-memory bitmap formats or to be written from the same formats. If these3305* formats do not accomodate your needs then you can, and should, use the more3306* sophisticated APIs above - these support a wide variety of in-memory formats3307* and a wide variety of sophisticated transformations to those formats as well3308* as a wide variety of APIs to manipulate ancillary information.3309*3310* To read a PNG file using the simplified API:3311*3312* 1) Declare a 'png_image' structure (see below) on the stack and set the3313* version field to PNG_IMAGE_VERSION.3314* 2) Call the appropriate png_image_begin_read... function.3315* 3) Set the png_image 'format' member to the required sample format.3316* 4) Allocate a buffer for the image and, if required, the color-map.3317* 5) Call png_image_finish_read to read the image and, if required, the3318* color-map into your buffers.3319*3320* There are no restrictions on the format of the PNG input itself; all valid3321* color types, bit depths, and interlace methods are acceptable, and the3322* input image is transformed as necessary to the requested in-memory format3323* during the png_image_finish_read() step. The only caveat is that if you3324* request a color-mapped image from a PNG that is full-color or makes3325* complex use of an alpha channel the transformation is extremely lossy and the3326* result may look terrible.3327*3328* To write a PNG file using the simplified API:3329*3330* 1) Declare a 'png_image' structure on the stack and memset() it to all zero.3331* 2) Initialize the members of the structure that describe the image, setting3332* the 'format' member to the format of the image samples.3333* 3) Call the appropriate png_image_write... function with a pointer to the3334* image and, if necessary, the color-map to write the PNG data.3335*3336* png_image is a structure that describes the in-memory format of an image3337* when it is being read or defines the in-memory format of an image that you3338* need to write:3339*/3340#define PNG_IMAGE_VERSION 133413342typedef struct png_control *png_controlp;3343typedef struct3344{3345png_controlp opaque; /* Initialize to NULL, free with png_image_free */3346png_uint_32 version; /* Set to PNG_IMAGE_VERSION */3347png_uint_32 width; /* Image width in pixels (columns) */3348png_uint_32 height; /* Image height in pixels (rows) */3349png_uint_32 format; /* Image format as defined below */3350png_uint_32 flags; /* A bit mask containing informational flags */3351png_uint_32 colormap_entries;3352/* Number of entries in the color-map */33533354/* In the event of an error or warning the following field will be set to a3355* non-zero value and the 'message' field will contain a '\0' terminated3356* string with the libpng error or warning message. If both warnings and3357* an error were encountered, only the error is recorded. If there3358* are multiple warnings, only the first one is recorded.3359*3360* The upper 30 bits of this value are reserved, the low two bits contain3361* a value as follows:3362*/3363# define PNG_IMAGE_WARNING 13364# define PNG_IMAGE_ERROR 23365/*3366* The result is a two-bit code such that a value more than 1 indicates3367* a failure in the API just called:3368*3369* 0 - no warning or error3370* 1 - warning3371* 2 - error3372* 3 - error preceded by warning3373*/3374# define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1)33753376png_uint_32 warning_or_error;33773378char message[64];3379} png_image, *png_imagep;33803381/* The samples of the image have one to four channels whose components have3382* original values in the range 0 to 1.0:3383*3384* 1: A single gray or luminance channel (G).3385* 2: A gray/luminance channel and an alpha channel (GA).3386* 3: Three red, green, blue color channels (RGB).3387* 4: Three color channels and an alpha channel (RGBA).3388*3389* The components are encoded in one of two ways:3390*3391* a) As a small integer, value 0..255, contained in a single byte. For the3392* alpha channel the original value is simply value/255. For the color or3393* luminance channels the value is encoded according to the sRGB specification3394* and matches the 8-bit format expected by typical display devices.3395*3396* The color/gray channels are not scaled (pre-multiplied) by the alpha3397* channel and are suitable for passing to color management software.3398*3399* b) As a value in the range 0..65535, contained in a 2-byte integer. All3400* channels can be converted to the original value by dividing by 65535; all3401* channels are linear. Color channels use the RGB encoding (RGB end-points) of3402* the sRGB specification. This encoding is identified by the3403* PNG_FORMAT_FLAG_LINEAR flag below.3404*3405* When the simplified API needs to convert between sRGB and linear colorspaces,3406* the actual sRGB transfer curve defined in the sRGB specification (see the3407* article at https://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.23408* approximation used elsewhere in libpng.3409*3410* When an alpha channel is present it is expected to denote pixel coverage3411* of the color or luminance channels and is returned as an associated alpha3412* channel: the color/gray channels are scaled (pre-multiplied) by the alpha3413* value.3414*3415* The samples are either contained directly in the image data, between 1 and 83416* bytes per pixel according to the encoding, or are held in a color-map indexed3417* by bytes in the image data. In the case of a color-map the color-map entries3418* are individual samples, encoded as above, and the image data has one byte per3419* pixel to select the relevant sample from the color-map.3420*/34213422/* PNG_FORMAT_*3423*3424* #defines to be used in png_image::format. Each #define identifies a3425* particular layout of sample data and, if present, alpha values. There are3426* separate defines for each of the two component encodings.3427*3428* A format is built up using single bit flag values. All combinations are3429* valid. Formats can be built up from the flag values or you can use one of3430* the predefined values below. When testing formats always use the FORMAT_FLAG3431* macros to test for individual features - future versions of the library may3432* add new flags.3433*3434* When reading or writing color-mapped images the format should be set to the3435* format of the entries in the color-map then png_image_{read,write}_colormap3436* called to read or write the color-map and set the format correctly for the3437* image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!3438*3439* NOTE: libpng can be built with particular features disabled, if you see3440* compiler errors because the definition of one of the following flags has been3441* compiled out it is because libpng does not have the required support. It is3442* possible, however, for the libpng configuration to enable the format on just3443* read or just write; in that case you may see an error at run time. You can3444* guard against this by checking for the definition of the appropriate3445* "_SUPPORTED" macro, one of:3446*3447* PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED3448*/3449#define PNG_FORMAT_FLAG_ALPHA 0x01U /* format with an alpha channel */3450#define PNG_FORMAT_FLAG_COLOR 0x02U /* color format: otherwise grayscale */3451#define PNG_FORMAT_FLAG_LINEAR 0x04U /* 2 byte channels else 1 byte */3452#define PNG_FORMAT_FLAG_COLORMAP 0x08U /* image data is color-mapped */3453#define PNG_FORMAT_FLAG_BGR 0x10U /* BGR colors, else order is RGB */3454#define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */3455/* other bits RESERVED */34563457/* The PNG color type value can be derived from a format which repesents a valid3458* PNG format using the following macro. Note that if any of the non-PNG3459* format elements are use, such as BGR or AFIRST, the color type value that3460* results does represent the number of channels in the format but may not3461* represent their order or encoding.3462*3463* NOTE: the format can encode illegal PNG formats, such as a colormap with3464* alpha or without color; these are legal simplified API formats which produce3465* data that cannot be represented as PNG regardless of channel order or3466* encoding.3467*3468* The macro below is the bit shift version, a multiplicative version which only3469* evaluates 'f' once is:3470*3471* ((((((((f) * 0x111) & 0x128) * 0x3) & 0x130) * 0x5) >> 6) & 0x7)3472*/3473#define PNG_COLOR_TYPE_FROM_FORMAT(f)\3474((((f) & (!((f) & PNG_FORMAT_FLAG_AFILLER))) << 2) |\3475(((f) & PNG_FORMAT_FLAG_COLOR) ) |\3476(((f) & PNG_FORMAT_FLAG_COLORMAP) >> 3))34773478/* The inverse: note that PNG_FORMAT_FLAG_LINEAR is not set by this macro and3479* that there is no handling for a 'filler' channel, consequently the macro must3480* only be used on genuine PNG color types, not the result of png_get_color_type3481* after transforms have been applied to the original PNG data.3482*/3483#define PNG_FORMAT_FROM_COLOR_TYPE(c)\3484((((c) & PNG_COLOR_MASK_ALPHA) >> 2) |\3485(((c) & PNG_COLOR_MASK_COLOR) ) |\3486(((c) & PNG_COLOR_MASK_PALETTE) << 3))34873488/* The following flags are not used by the simplified API but may be returned3489* by png_memory_format. Presence of any of these flags means that the values3490* in the image (in memory) cannot be handled 'normally'.3491*/3492#define PNG_FORMAT_FLAG_AFILLER 0x40U /* The 'alpha' channel is a filler:3493* PNG_FORMAT_FLAG_ALPHA is set however the value in the alpha channel3494* is not an alpha value and (therefore) cannot be used for alpha3495* computations, it is just a filler value. PNG_COLOR_TYPE_FROM_FORMAT3496* will return a color type *without* PNG_COLOR_MASK_ALPHA, however3497* PNG_FORMAT_CHANNELS will return the correct number, including the3498* filler channel.3499*/3500#define PNG_FORMAT_FLAG_SWAPPED 0x80U /* bytes or bits swapped:3501* When the bit depth is 16 this means that the bytes within the3502* components have been swapped, when the bit depth is less than 83503* it means the pixels within the bytes have been swapped. It should3504* not be set for 8-bit compononents (it is meaningless). */3505#define PNG_FORMAT_FLAG_RANGE 0x100U /* component range not 0..bit-depth:3506* Low-bit-depth grayscale components have been unpacked into bytes3507* without scaling, or RGB[A] pixels have been shifted back to the3508* significant-bit range from the sBIT chunk or channels (currently3509* alpha or gray) have been inverted. */3510#define PNG_FORMAT_FLAG_INVALID 0x8000U /* Invalid simplified API channel depth:3511* For single channel grayscale and palette indexed image data PNG3512* supports bit depths of 1, 2 or 4 bits per pixel (and per channel)3513* packed into bytes. The simplified API macros will not work with3514* these formats (the simplified API always uses 8 or 16-bit channels).3515* In the simplified API 'linear' images always have 16-bit channels3516* and non-linear images are always sRGB encoded. If the INVALID flag3517* is set then this may not be true; it is necessary to check the3518* memory format bit-depth and gamma separately.3519*/35203521/* Commonly used formats have predefined macros.3522*3523* First the single byte (sRGB) formats:3524*/3525#define PNG_FORMAT_GRAY 0U3526#define PNG_FORMAT_GA PNG_FORMAT_FLAG_ALPHA3527#define PNG_FORMAT_AG (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)3528#define PNG_FORMAT_RGB PNG_FORMAT_FLAG_COLOR3529#define PNG_FORMAT_BGR (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)3530#define PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)3531#define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)3532#define PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)3533#define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)35343535/* Then the linear 2-byte formats. When naming these "Y" is used to3536* indicate a luminance (gray) channel.3537*/3538#define PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR3539#define PNG_FORMAT_LINEAR_Y_ALPHA (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)3540#define PNG_FORMAT_LINEAR_RGB (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)3541#define PNG_FORMAT_LINEAR_RGB_ALPHA \3542(PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA)35433544/* With color-mapped formats the image data is one byte for each pixel, the byte3545* is an index into the color-map which is formatted as above. To obtain a3546* color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP3547* to one of the above definitions, or you can use one of the definitions below.3548*/3549#define PNG_FORMAT_RGB_COLORMAP (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP)3550#define PNG_FORMAT_BGR_COLORMAP (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP)3551#define PNG_FORMAT_RGBA_COLORMAP (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP)3552#define PNG_FORMAT_ARGB_COLORMAP (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP)3553#define PNG_FORMAT_BGRA_COLORMAP (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP)3554#define PNG_FORMAT_ABGR_COLORMAP (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP)35553556/* PNG_IMAGE macros3557*3558* These are convenience macros to derive information from a png_image3559* structure. The PNG_IMAGE_SAMPLE_ macros return values appropriate to the3560* actual image sample values - either the entries in the color-map or the3561* pixels in the image. The PNG_IMAGE_PIXEL_ macros return corresponding values3562* for the pixels and will always return 1 for color-mapped formats. The3563* remaining macros return information about the rows in the image and the3564* complete image.3565*3566* NOTE: All the macros that take a png_image::format parameter are compile time3567* constants if the format parameter is, itself, a constant. Therefore these3568* macros can be used in array declarations and case labels where required.3569* Similarly the macros are also pre-processor constants (sizeof is not used) so3570* they can be used in #if tests.3571*3572* First the information about the samples.3573*/3574#define PNG_IMAGE_SAMPLE_CHANNELS(fmt)\3575(((fmt)&(PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA))+1)3576/* Return the total number of channels in a given format: 1..4 */35773578#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\3579((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1)3580/* Return the size in bytes of a single component of a pixel or color-map3581* entry (as appropriate) in the image: 1 or 2.3582*/35833584#define PNG_IMAGE_SAMPLE_SIZE(fmt)\3585(PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt))3586/* This is the size of the sample data for one sample. If the image is3587* color-mapped it is the size of one color-map entry (and image pixels are3588* one byte in size), otherwise it is the size of one image pixel.3589*/35903591#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\3592(PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)3593/* The maximum size of the color-map required by the format expressed in a3594* count of components. This can be used to compile-time allocate a3595* color-map:3596*3597* png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];3598*3599* png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];3600*3601* Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the3602* information from one of the png_image_begin_read_ APIs and dynamically3603* allocate the required memory.3604*/36053606/* Corresponding information about the pixels */3607#define PNG_IMAGE_PIXEL_(test,fmt)\3608(((fmt)&PNG_FORMAT_FLAG_COLORMAP)?1:test(fmt))36093610#define PNG_IMAGE_PIXEL_CHANNELS(fmt)\3611PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_CHANNELS,fmt)3612/* The number of separate channels (components) in a pixel; 1 for a3613* color-mapped image.3614*/36153616#define PNG_FORMAT_CHANNELS(fmt) PNG_IMAGE_PIXEL_CHANNELS(fmt)3617/* Synonym for the above for use with the result of png_get_memory_format.3618* This exists to avoid confusion with the PNG_IMAGE_ macros which do not3619* work on all possible results of png_get_memory_format.3620*/36213622#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\3623PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt)3624/* The size, in bytes, of each component in a pixel; 1 for a color-mapped3625* image.3626*/36273628#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt)3629/* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */36303631/* Information about the whole row, or whole image */3632#define PNG_IMAGE_ROW_STRIDE(image)\3633(PNG_IMAGE_PIXEL_CHANNELS((image).format) * (png_alloc_size_t)(image).width)3634/* Return the total number of components in a single row of the image; this3635* is the minimum 'row stride', the minimum count of components between each3636* row. For a color-mapped image this is the minimum number of bytes in a3637* row.3638*3639* WARNING: libpng 1.7: this macro now returns a png_alloc_size_t, previous3640* versions returned a png_uint_32 and could overflow for images that fit in3641* memory. This macro can still overflow, but if it does the row will not3642* fit in memory. The simplified API functions detect this and refuse to3643* handle the image.3644*/36453646#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\3647(PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride))3648/* Return the size, in bytes, of an image buffer given a png_image and a row3649* stride - the number of components to leave space for in each row.3650*3651* WARNING: This is the total size of the image, for large images it will3652* overflow on a 32-bit system. In libpng 1.7 (but not before) it returns a3653* png_alloc_size_t which means that the result only overflows for3654* ridiculously large PNG files. libpng checks and will refuse to handle3655* such data (the PNG is probably invalid.)3656*3657* Take great care over the type of 'row_stride'; libpng assumes that the3658* type is png_alloc_size_t, as returned by PNG_IMAGE_ROW_STRIDE. You can3659* use any type you like but libpng only checks for overflow when the type is3660* png_alloc_size_t. In particular for png_uint_32 on a 64-bit system you3661* must do your own overflow checking. Cast row_stride as (png_alloc_size_t)3662* to avoid this (check for overflow before the cast of course!)3663*/36643665#define PNG_IMAGE_SIZE(image)\3666PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image))3667/* Return the size, in bytes, of the image in memory given just a png_image;3668* the row stride is the minimum stride required for the image.3669*/36703671#define PNG_IMAGE_COLORMAP_SIZE(image)\3672(PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries)3673/* Return the size, in bytes, of the color-map of this image. If the image3674* format is not a color-map format this will return a size sufficient for3675* 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if3676* you don't want to allocate a color-map in this case.3677*/36783679/* PNG_IMAGE_FLAG_*3680*3681* Flags containing additional information about the image are held in the3682* 'flags' field of png_image.3683*/3684#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 0x013685/* This indicates the the RGB values of the in-memory bitmap do not3686* correspond to the red, green and blue end-points defined by sRGB.3687*/36883689#define PNG_IMAGE_FLAG_FAST 0x023690/* On write emphasise speed over compression; the resultant PNG file will be3691* larger but will be produced significantly faster, particular for large3692* images. Do not use this option for images which will be distributed, only3693* used it when producing intermediate files that will be read back in3694* repeatedly. For a typical 24-bit image the option will double the read3695* speed at the cost of increasing the image size by 25%, however for many3696* more compressible images the PNG file can be 10 times larger with only a3697* slight speed gain.3698*/36993700#define PNG_IMAGE_FLAG_16BIT_sRGB 0x043701/* On read if the image is a 16-bit per component image and there is no gAMA3702* or sRGB chunk assume that the components are sRGB encoded. Notice that3703* images output by the simplified API always have gamma information; setting3704* this flag only affects the interpretation of 16-bit images from an3705* external source. It is recommended that the application expose this flag3706* to the user; the user can normally easily recognize the difference between3707* linear and sRGB encoding. This flag has no effect on write - the data3708* passed to the write APIs must have the correct encoding (as defined3709* above.)3710*3711* If the flag is not set (the default) input 16-bit per component data is3712* assumed to be linear.3713*3714* NOTE: the flag can only be set after the png_image_begin_read_ call,3715* because that call initializes the 'flags' field.3716*/37173718#ifdef PNG_SIMPLIFIED_READ_SUPPORTED3719/* READ APIs3720* ---------3721*3722* The png_image passed to the read APIs must have been initialized by setting3723* the png_controlp field 'opaque' to NULL (or, safer, memset the whole thing.)3724*/3725#ifdef PNG_STDIO_SUPPORTED3726PNG_EXPORT(234, int, png_image_begin_read_from_file, (png_imagep image,3727const char *file_name));3728/* The named file is opened for read and the image header is filled in3729* from the PNG header in the file.3730*/37313732PNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image,3733FILE* file));3734/* The PNG header is read from the stdio FILE object. */3735#endif /* STDIO */37363737PNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image,3738png_const_voidp memory, size_t size));3739/* The PNG header is read from the given memory buffer. */37403741PNG_EXPORT(237, int, png_image_finish_read, (png_imagep image,3742png_const_colorp background, void *buffer, ptrdiff_t row_stride,3743void *colormap));3744/* Finish reading the image into the supplied buffer and clean up the3745* png_image structure.3746*3747* row_stride is the step, in byte or 2-byte units as appropriate,3748* between adjacent rows. A positive stride indicates that the top-most row3749* is first in the buffer - the normal top-down arrangement. A negative3750* stride indicates that the bottom-most row is first in the buffer.3751*3752* background need only be supplied if an alpha channel must be removed from3753* a png_byte format and the removal is to be done by compositing on a solid3754* color; otherwise it may be NULL and any composition will be done directly3755* onto the buffer. The value is an sRGB color to use for the background,3756* for grayscale output the green channel is used.3757*3758* background must be supplied when an alpha channel must be removed from a3759* single byte color-mapped output format, in other words if:3760*3761* 1) The original format from png_image_begin_read_from_* had3762* PNG_FORMAT_FLAG_ALPHA set.3763* 2) The format set by the application does not.3764* 3) The format set by the application has PNG_FORMAT_FLAG_COLORMAP set and3765* PNG_FORMAT_FLAG_LINEAR *not* set.3766*3767* For linear output removing the alpha channel is always done by compositing3768* on black and background is ignored.3769*3770* colormap must be supplied when PNG_FORMAT_FLAG_COLORMAP is set. It must3771* be at least the size (in bytes) returned by PNG_IMAGE_COLORMAP_SIZE.3772* image->colormap_entries will be updated to the actual number of entries3773* written to the colormap; this may be less than the original value.3774*/37753776PNG_EXPORT(238, void, png_image_free, (png_imagep image));3777/* Free any data allocated by libpng in image->opaque, setting the pointer to3778* NULL. May be called at any time after the structure is initialized.3779*/3780#endif /* SIMPLIFIED_READ */37813782#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED3783/* WRITE APIS3784* ----------3785* For write you must initialize a png_image structure to describe the image to3786* be written. To do this use memset to set the whole structure to 0 then3787* initialize fields describing your image.3788*3789* version: must be set to PNG_IMAGE_VERSION3790* opaque: must be initialized to NULL3791* width: image width in pixels3792* height: image height in rows3793* format: the format of the data (image and color-map) you wish to write3794* flags: set to 0 unless one of the defined flags applies; set3795* PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB3796* values do not correspond to the colors in sRGB.3797* colormap_entries: set to the number of entries in the color-map (0 to 256)3798*/3799#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED3800PNG_EXPORT(239, int, png_image_write_to_file, (png_imagep image,3801const char *file, int convert_to_8bit, const void *buffer,3802ptrdiff_t row_stride, const void *colormap));3803/* Write the image to the named file. */38043805PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file,3806int convert_to_8_bit, const void *buffer, ptrdiff_t row_stride,3807const void *colormap));3808/* Write the image to the given (FILE*). */3809#endif /* SIMPLIFIED_WRITE_STDIO */38103811/* With all write APIs if image is in one of the linear formats with 16-bit3812* data then setting convert_to_8_bit will cause the output to be an 8-bit PNG3813* gamma encoded according to the sRGB specification, otherwise a 16-bit linear3814* encoded PNG file is written.3815*3816* With color-mapped data formats the colormap parameter point to a color-map3817* with at least image->colormap_entries encoded in the specified format. If3818* the format is linear the written PNG color-map will be converted to sRGB3819* regardless of the convert_to_8_bit flag.3820*3821* With all APIs row_stride is handled as in the read APIs - it is the spacing3822* from one row to the next in component sized units (1 or 2 bytes) and if3823* negative indicates a bottom-up row layout in the buffer. If row_stride is3824* zero, libpng will calculate it for you from the image width and number of3825* channels.3826*3827* Note that the write API does not support interlacing, sub-8-bit pixels or3828* most ancillary chunks. If you need to write text chunks (e.g. for copyright3829* notices) you need to use one of the other APIs.3830*/38313832PNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,3833png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8_bit,3834const void *buffer, ptrdiff_t row_stride, const void *colormap));3835/* Write the image to the given memory buffer. The function both writes the3836* whole PNG data stream to *memory and updates *memory_bytes with the count3837* of bytes written.3838*3839* 'memory' may be NULL. In this case *memory_bytes is not read however on3840* success the number of bytes which would have been written will still be3841* stored in *memory_bytes. On failure *memory_bytes will contain 0.3842*3843* If 'memory' is not NULL it must point to memory[*memory_bytes] of3844* writeable memory.3845*3846* If the function returns success memory[*memory_bytes] (if 'memory' is not3847* NULL) contains the written PNG data. *memory_bytes will always be less3848* than or equal to the original value.3849*3850* If the function returns false and *memory_bytes was not changed an error3851* occured during write. If *memory_bytes was changed, or is not 0 if3852* 'memory' was NULL, the write would have succeeded but for the memory3853* buffer being too small. *memory_bytes contains the required number of3854* bytes and will be bigger that the original value.3855*/38563857#define png_image_write_get_memory_size(image, size, convert_to_8_bit, buffer,\3858row_stride, colormap)\3859png_image_write_to_memory(&(image), 0, &(size), convert_to_8_bit, buffer,\3860row_stride, colormap)3861/* Return the amount of memory in 'size' required to compress this image.3862* The png_image structure 'image' must be filled in as in the above3863* function and must not be changed before the actual write call, the buffer3864* and all other parameters must also be identical to that in the final3865* write call. The 'size' variable need not be initialized.3866*3867* NOTE: the macro returns true/false, if false is returned 'size' will be3868* set to zero and the write failed and probably will fail if tried again.3869*/38703871/* You can pre-allocate the buffer by making sure it is of sufficient size3872* regardless of the amount of compression achieved. The buffer size will3873* always be bigger than the original image and it will never be filled. The3874* following macros are provided to assist in allocating the buffer.3875*/3876#define PNG_IMAGE_DATA_SIZE(image) (PNG_IMAGE_SIZE(image)+(image).height)3877/* The number of uncompressed bytes in the PNG byte encoding of the image;3878* uncompressing the PNG IDAT data will give this number of bytes.3879*/3880#ifndef PNG_ZLIB_MAX_SIZE3881# define PNG_ZLIB_MAX_SIZE(b) ((b)+(((b)+7U)>>3)+(((b)+63U)>>6)+11U)3882/* An upper bound on the number of compressed bytes given 'b' uncompressed3883* bytes. This is based on deflateBounds() in zlib; different3884* implementations of zlib compression may conceivably produce more data so3885* if your zlib implementation is not zlib itself redefine this macro3886* appropriately.3887*/3888#endif38893890#define PNG_IMAGE_COMPRESSED_SIZE_MAX(image)\3891PNG_ZLIB_MAX_SIZE((png_alloc_size_t)PNG_IMAGE_DATA_SIZE(image))3892/* An upper bound on the size of the data in the PNG IDAT chunks. */38933894#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\3895((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\3896(((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\389712U+3U*(image).colormap_entries/*PLTE data*/+\3898(((image).format&PNG_FORMAT_FLAG_ALPHA)?\389912U/*tRNS*/+(image).colormap_entries:0U):0U)+\390012U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))3901/* A helper for the following macro; if your compiler cannot handle the3902* following macro use this one with the result of3903* PNG_IMAGE_COMPRESSED_SIZE_MAX(image) as the second argument (most3904* compilers should handle this just fine.)3905*/39063907#define PNG_IMAGE_PNG_SIZE_MAX(image)\3908PNG_IMAGE_PNG_SIZE_MAX_(image, PNG_IMAGE_COMPRESSED_SIZE_MAX(image))3909/* An upper bound on the total length of the PNG data stream for 'image'.3910* The result is of type png_alloc_size_t, on 32-bit systems this may3911* overflow even though PNG_IMAGE_DATA_SIZE does not overflow; the write will3912* run out of buffer space but return a corrected size which should work.3913*3914* NOTE: while PNG_IMAGE_SIZE cannot overflow for an image in memory this3915* macro can because of the extra bytes used in the PNG byte encoding. You3916* need to avoid this macro if your image size approaches the limit of your3917* system memory; typically the maximum value of size_t. Use the above3918* function call instead.3919*/3920#endif /* SIMPLIFIED_WRITE */3921/*******************************************************************************3922* END OF SIMPLIFIED API3923******************************************************************************/39243925/*******************************************************************************3926* Section 6: IMPLEMENTATION OPTIONS3927*******************************************************************************3928*3929* Change of options used during read and/or write.3930*3931* A number of internal options can (but do not need to be) changed to3932* fine tune the implementation. These options control such things as the3933* precise settings for compression, the accuracy of arithmetic used internally3934* for image processing operations (gamma transformations) and, in some cases,3935* the specific implementations (hardware or software optimizations.)3936*3937* To avoid API proliferation there is a single general API (new in 1.7) to do3938* this. When a particular option is not supported by the build in libpng an3939* attempt to set it will return a failure code but will be totally ignored3940* unless the PNG_SF_ERROR flag is set (see below).3941*/3942PNG_EXPORT(249, png_int_32, png_setting, (png_structrp png_ptr,3943png_uint_32 setting, png_uint_32 parameter, png_int_32 value));3944/* Alter setting 'setting' using the values of 'parameter' and 'value'. The3945* result is either one of the following failure codes or a setting/parameter3946* specific result code.3947*3948* The failure codes match the POSIX 1003.1 <errno.h> values (section 2.5,3949* error numbers) with a preceding PNG_. (png_uint_32)result gives a number3950* in the range 0x80000001U to 0x8000000fU.3951*/3952# define PNG_EBADF (-0x7fffffff) /* read/write error */3953/* An attempt was made to apply a read setting to a write structure or3954* vice versa.3955*/3956# define PNG_EINVAL (-0x7ffffffe) /* invalid argument */3957/* 'png_ptr' was NULL or 'parameter' or 'value' is invalid for the given3958* setting.3959*/3960# define PNG_EDOM (-0x7ffffffd) /* out of range */3961/* Either 'parameter' or 'value' is out of range for the given setting3962* (only returned when paramter or value are used and are numeric; for3963* flag values PNG_EINVAL will be returned.)3964*/3965# define PNG_ENOSYS (-0x7ffffff1) /* unsupported setting/param */3966/* The setting was not recognized; typically this means that libpng was3967* built without the appropriate support.3968*/3969# define PNG_UNSUPPORTED_SETTING PNG_ENOSYS3970/* For backware compatibility with earlier libpng versions and3971* 'png_set_option' return codes.3972*/3973# define PNG_UNSET (-0x7ffffff0) /* NOT an erro code: no previous setting */3974/* The setting was not (previously) set. Returned when there is no built3975* in default for a setting. Normally this means that the default will3976* depend on other settings or the PNG itself.3977*/3978/* Results larger (more positive) than PNG_ENOSYS are success codes (even if3979* negative). The value is interpreted as follows (as defined by the3980* setting):3981*3982* 1) A signed 31-bit number in the range -0x7fffffef to +0x7fffffff3983* 2) An unsigned 31 bit number in the range 0U to 0x7fffffffU3984* 3) An unsigned 32 bit bit set/flag value in the range 0U to 0xfffffffU3985* but excluding values in the range 0x80000000U to 0x80000000FU3986* encoded as follows:3987*3988* if (v <= 0x7fffffffU)3989* v3990* else if (v > 0x8000000FU)3991* -(png_int_32)-v3992*3993* The result can be converted by to the original (png_uint_32) simply3994* by casting it as such.3995*/3996# define PNG_FAILED(result) ((result) <= PNG_ENOSYS)3997/* The setting did not take; this includes both errors making the setting3998* (e.g. parameter or value errors) and unsupported settings. Check the3999* result code itself for more information.4000*/4001# define PNG_OK(result) ((result) > PNG_ENOSYS)4002/* The setting succeeded; the result is a return code which depends on the4003* particular setting. (E.g. it might be a return code or it might be the4004* previous value.)4005*/40064007/* SETTING VALUES (generic)4008*4009* These are flag values that are added to the setting definitions below to4010* simplify processing inside libpng and self-document the setting behavior.4011* All these values have the prefix PNG_SF_4012*/4013#define PNG_SF_ERROR (0x80000000U)4014/* If this is set on the 'setting' argument to png_setting and a failure code4015* would otherwise be returned call png_error instead. This is a convenience4016* for applications that do not want to check the result code. It is never4017* set by default. The error string is cryptic.4018*/4019#define PNG_SF_GET (0x40000000U)4020/* Do not set the setting. With most settings this just allows for the4021* presence of support for the setting to be checked at run time; if the4022* setting is not support PNG_ENOSYS will be returned.4023*4024* With some settings checking of the parameter or value may be done, but4025* there is no guarantee, so always supply valid parameter and value.4026*4027* With some settings the current setting is returned. This is typically4028* only done when the default setting is configurable and not even always4029* then. If the setting does this it will document the behavior.4030*/4031#define PNG_SF_READ (0x20000000U)4032/* The setting may be applied to a read png_struct. If this is not set and4033* an attempt is made to apply the setting to a read struct4034* PNG_EBADF will be returned.4035*/4036#define PNG_SF_WRITE (0x10000000U)4037/* The setting may be applied to a write png_struct. If this is not set4038* and an attempt is made to apply the setting to a write struct4039* PNG_EBADF will be returned.4040*/40414042/*********************************** WRITE ************************************/4043/* WRITE COMPRESSION SUPPORT4044*4045* These settings are normally accessed using the macros that are defined above;4046* the function-like macros replace the API calls present in previous versions4047* of libpng.4048*4049* 'setting' is as follows, 'parameter' is a chunk name; png_IDAT for IDAT4050* compression, png_iCCP for iCCP chunk compression png_zTXt for zTZt *and* iTXt4051* text chunk compression. Other values must not be used; they will result in4052* PNG_ENOSYS at present but may alter compression of new chunks in the future.4053*4054* The value is the new compression setting. The result is is the old4055* compression setting or an error code. Compression settings are documented4056* in text above describing the function-like macros. PNG_UNSET is returned4057* when the setting was not previously set; in this case the default may vary4058* according to the actual data (e.g. length, PNG format).4059*4060* 0 is valid as a parameter if PNG_SF_GET is set, in that case the current or4061* last setting is returned.4062*/4063#define PNG_SW_COMPRESS_zlib_level (PNG_SF_WRITE + 0U)4064#define PNG_SW_COMPRESS_windowBits (PNG_SF_WRITE + 1U)4065#define PNG_SW_COMPRESS_memLevel (PNG_SF_WRITE + 2U)4066#define PNG_SW_COMPRESS_strategy (PNG_SF_WRITE + 3U)4067#define PNG_SW_COMPRESS_png_level (PNG_SF_WRITE + 4U)4068#define PNG_SW_COMPRESS_method (PNG_SF_WRITE + 5U)40694070/* WRITE IDAT size.4071*4072* The size of the IDAT chunks that are written (the last may be smaller).4073*/4074#define PNG_SW_IDAT_size (PNG_SF_WRITE + 6U)40754076/* WRITE FILTER CONTROL4077*4078* These settings are used by png_set_filter and png_set_row_buffers to control4079* the filters used during compression. The 'filters' setting has two arguments4080* however the first is the filter method (or type) and must be 0 for PNG.4081* Standards based on PNG may define additional values, as with other base file4082* characteristics such as the compression type, however the result would not be4083* a PNG.4084*/4085#define PNG_SW_COMPRESS_filters (PNG_SF_WRITE + 7U)4086#define PNG_SW_COMPRESS_row_buffers (PNG_SF_WRITE + 8U)40874088/* WRITE ROW FLUSH CONTROL4089*4090* This sets the number of rows between flush calls. '0' was used to indicate4091* no flushing (before the end). The maximum number of rows in a PNG is4092* actually greater than the maximum of a 31-bit integer for interlaced images,4093* however this doesn't matter much; the number of rows was always declared as4094* 'int', so it is still passed in the 'value' argument.4095*/4096#define PNG_SW_FLUSH (PNG_SF_WRITE + 9U)40974098/*********************************** READ *************************************/4099/* The size of the buffer used while reading IDAT chunks and, potentially, other4100* compressed chunks.4101*/4102#define PNG_SR_COMPRESS_buffer_size (PNG_SF_READ + 1U)4103/* Read compressed data buffer size, in 'parameter'. The result is 0. */41044105#define PNG_SR_GAMMA_threshold (PNG_SF_READ + 2U)4106#define png_set_gamma_threshold(png_ptr, threshold)\4107(png_setting((png_ptr), PNG_SR_GAMMA_threshold, (threshold), 0))4108/* SETTING: threshold below which gamma correction is not done, the default4109* (set when the library is built) is PNG_GAMMA_THRESHOLD_FIXED, the4110* 'parameter' is a png_fixed_point number, the difference from PNG_FP_14111* above which gamma correction will be performed.4112*4113* The value '153' is sufficient to maintain 1% accuracy in 16-bit linear4114* calculations over a 655:1 range; over the maximum range possible with the4115* 16-bit linear representation. Reasonable values are:4116*4117* 0: always do gamma correction, even if the gamma values are4118* identical. The only point to this is to avoid a bug in the4119* optimized (no gamma correction) code path, or for testing.4120* 2: always do gamma correction if there is any significant4121* difference. Notice that '1' will result in gamma correction in4122* many cases when the screen gamma is the inverse of the encoding4123* gamma because of inaccuracies in the representation of gamma.4124* 153: do gamma correction if it is needed to maintain the accuracy of4125* 16-bit linear calculations at 1% or below.4126* 216: maintain 1% accuracy over a 100:1 dynamic range in 16-bit linear4127* calculations. This matches the widely accepted numbers for human4128* perception of differences within an image, however that doesn't4129* mean that such high accuracy is required to avoid artefacts; such4130* accuracy (such a low number) is only required if versions of the4131* same image with and without gamma correction are to be compared4132* visually.4133* 5000: this is the default from libpng 1.6 and earlier. Using this4134* produces changes in image contrast that are visible when suitable4135* images are compared side-by-side however they are not obvious and4136* it is inconceivable that a user would notice the change unless4137* the user was very familiar with the image and the viewing4138* environment.4139*4140* Values between 216 and 5000 produce varying very small changes in image4141* contrast. Values above 10,000 (10%) produce noticeable increase or4142* decrease in contrast which will probably change how the image is4143* perceived. There is an internal limit on the maximum value which is4144* currently 65%; PNG_EDOM will be returned for higher values.4145*4146* The result is the value that was set.4147*/4148#if 0 /*NYI*/4149#define PNG_SR_GAMMA_accuracy /*NYI*/4150/* SETTING: controls the accuracy of the gamma calculations when the results4151* are cached. The default is PNG_DEFAULT_GAMMA_ACCURACY. The number is 1004152* times the number of bits, 'b', used in the internal tables when the input4153* is linear, permitted values are 0..1600 however '0' causes the caching to4154* be skipped entirely (so gives maximum accuracy with no caching!)4155*4156* The accuracy in the linear domain for a value 'a' is:4157*4158* +/-(.5/2^a)4159*4160* so for the default-default of 665 this means the accuracy is +/-0.5% and4161* this ensures that almost-equal input values do not differ by more than 1%4162* in the output, meeting the accepted requirement for human vision.4163*4164* The default value has no effect on input narrower than 16 bits. For n-bit4165* input the total table size is ((n-v)+1)*(2^v), where 'v' is a/gamma and4166* 'gamma' is the gamma encoding of the input:4167*4168* n a gamma 'v' table size4169* 8 6.65 .45455 14.6 2564170* 16 6.65 .45455 14.6 655364171* 16 6.65 1.0 6.65 12804172* 16 6 1.0 6 7044173* 16 5 1.0 5 3844174*/4175#endif /*NYI*/41764177#define PNG_SR_CRC_ACTION (PNG_SF_READ + 4U)4178/* 'parameter' is what to do with critical chunks, 'value' is what to do with4179* ancillary ones when the CRC does not match on read. 0 is returned. See4180* png_set_crc_action for more information.4181*/41824183/*********************************** OPTIONS **********************************/4184/* png_set_option is implemented via png_setting to provide API compatibility4185* with releases prior to 1.7.04186*/4187/* HARDWARE OPTIMIZATIONS4188*4189* Normally hardware capabilites, such as the Intel SSE instructions, are4190* detected at run time, however sometimes it may be impossible to do this in4191* user mode, in which case it is necessary to discover the capabilities in an4192* OS specific way. Such capabilities are listed here when libpng has support4193* for them and must be turned ON by the application if present. Check4194* pnglibconf.h for options appropriate to your hardware.4195*4196* In general 'PNG_EXTENSIONS' controls hardware optimizations; these are not4197* supported parts of libpng and, if there are problems with them, bugs should4198* be ported to the implementers. Depending on the configuration it may not be4199* possible to disable extensions at run time.4200*/4201#define PNG_SRW_OPTION (PNG_SF_READ+PNG_SF_WRITE + 0U)4202#ifdef PNG_SET_OPTION_SUPPORTED4203PNG_REMOVED(244, int, png_set_option, (png_structrp png_ptr, int option,4204int onoff), PNG_EMPTY)42054206#define png_set_option(p, opt, onoff)\4207(png_setting((p), PNG_SRW_OPTION, (opt), (onoff)))4208/* Pre 1.7 API; in 1.7 the result values have changed numerically but not by4209* name. For backward API compatibility this setting only returns one error4210* code, PNG_ENOSYS and that only for option numbers out of range, otherwise4211* if the option isn't supported PNG_OPTION_UNSET (PNG_UNSET) is returned.4212*/4213#endif /* SET_OPTION */4214#define PNG_OPTION_UNSET PNG_UNSET /* Unset - defaults to off */4215#define PNG_OPTION_INVALID PNG_ENOSYS /* Option number out of range */4216#define PNG_OPTION_OFF 04217#define PNG_OPTION_ON 142184219/* Specific options: */4220#define PNG_EXTENSIONS 0 /* HARDWARE: switch extensions on or off */4221#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */4222#define PNG_SKIP_sRGB_CHECK_PROFILE 4 /* SOFTWARE: Check ICC profile for sRGB */4223#define PNG_OPTION_NEXT 6 /* Next option - numbers are even */42244225#define PNG_SRW_CHECK_FOR_INVALID_INDEX (PNG_SF_READ+PNG_SF_WRITE + 1U)4226/* Turn the palette index check on or off; see4227* png_set_check_for_invalid_index above.4228*/42294230#define PNG_SRW_ERROR_HANDLING (PNG_SF_READ+PNG_SF_WRITE + 2U)4231/* Change the action on issues that can be handled. */42324233/*******************************************************************************4234* END OF HARDWARE OPTIONS4235******************************************************************************/42364237/* The last ordinal number (this is the *last* one already used; the next4238* one to use is one more than this.) Maintainer, remember to add an entry to4239* scripts/symbols.def as well.4240*/4241#ifdef PNG_EXPORT_LAST_ORDINAL4242PNG_EXPORT_LAST_ORDINAL(249);4243#endif42444245#ifdef __cplusplus4246}4247#endif42484249#endif /* PNG_VERSION_INFO_ONLY */4250/* Do not put anything past this line */4251#endif /* PNG_H */425242534254