pngpriv.h 69 KB

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