2
0

pngpriv.h 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. /* pngpriv.h - private declarations for use inside libpng
  2. *
  3. * Last changed in libpng 1.5.26 [December 17, 2015]
  4. * Copyright (c) 1998-2002,2004,2006-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. /* Flags for the png_ptr->flags rather than declaring a byte for each one */
  476. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  477. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  478. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  479. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  480. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  481. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  482. #define PNG_FLAG_ROW_INIT 0x0040
  483. #define PNG_FLAG_FILLER_AFTER 0x0080
  484. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  485. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  486. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  487. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  488. #define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */
  489. #define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */
  490. #define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */
  491. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000
  492. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000
  493. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000
  494. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000
  495. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000
  496. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000
  497. #define PNG_FLAG_ZSTREAM_PROGRESSIVE 0x200000
  498. /* 0x400000 unused */
  499. #define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000 /* Added to libpng-1.4.0 */
  500. #define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000 /* 5 lines added */
  501. #define PNG_FLAG_ZTXT_CUSTOM_LEVEL 0x2000000 /* to libpng-1.5.4 */
  502. #define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL 0x4000000
  503. #define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000
  504. #define PNG_FLAG_ZTXT_CUSTOM_METHOD 0x10000000
  505. /* 0x20000000 unused */
  506. /* 0x40000000 unused */
  507. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  508. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  509. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  510. PNG_FLAG_CRC_CRITICAL_IGNORE)
  511. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  512. PNG_FLAG_CRC_CRITICAL_MASK)
  513. /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
  514. * can handle at once. This type need be no larger than 16 bits (so maximum of
  515. * 65535), this define allows us to discover how big it is, but limited by the
  516. * maximuum for png_size_t. The value can be overriden in a library build
  517. * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
  518. * lower value (e.g. 255 works). A lower value may help memory usage (slightly)
  519. * and may even improve performance on some systems (and degrade it on others.)
  520. */
  521. #ifndef ZLIB_IO_MAX
  522. # define ZLIB_IO_MAX ((uInt)-1)
  523. #endif
  524. /* Save typing and make code easier to understand */
  525. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  526. abs((int)((c1).green) - (int)((c2).green)) + \
  527. abs((int)((c1).blue) - (int)((c2).blue)))
  528. /* Added to libpng-1.2.6 JB */
  529. #define PNG_ROWBYTES(pixel_bits, width) \
  530. ((pixel_bits) >= 8 ? \
  531. ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
  532. (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )
  533. /* PNG_OUT_OF_RANGE returns true if value is outside the range
  534. * ideal-delta..ideal+delta. Each argument is evaluated twice.
  535. * "ideal" and "delta" should be constants, normally simple
  536. * integers, "value" a variable. Added to libpng-1.2.6 JB
  537. */
  538. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  539. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  540. /* Conversions between fixed and floating point, only defined if
  541. * required (to make sure the code doesn't accidentally use float
  542. * when it is supposedly disabled.)
  543. */
  544. #ifdef PNG_FLOATING_POINT_SUPPORTED
  545. /* The floating point conversion can't overflow, though it can and
  546. * does lose accuracy relative to the original fixed point value.
  547. * In practice this doesn't matter because png_fixed_point only
  548. * stores numbers with very low precision. The png_ptr and s
  549. * arguments are unused by default but are there in case error
  550. * checking becomes a requirement.
  551. */
  552. #define png_float(png_ptr, fixed, s) (.00001 * (fixed))
  553. /* The fixed point conversion performs range checking and evaluates
  554. * its argument multiple times, so must be used with care. The
  555. * range checking uses the PNG specification values for a signed
  556. * 32 bit fixed point value except that the values are deliberately
  557. * rounded-to-zero to an integral value - 21474 (21474.83 is roughly
  558. * (2^31-1) * 100000). 's' is a string that describes the value being
  559. * converted.
  560. *
  561. * NOTE: this macro will raise a png_error if the range check fails,
  562. * therefore it is normally only appropriate to use this on values
  563. * that come from API calls or other sources where an out of range
  564. * error indicates a programming error, not a data error!
  565. *
  566. * NOTE: by default this is off - the macro is not used - because the
  567. * function call saves a lot of code.
  568. */
  569. #ifdef PNG_FIXED_POINT_MACRO_SUPPORTED
  570. #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
  571. ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))
  572. #else
  573. #ifndef PNG_VERSION_INFO_ONLY
  574. PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp,
  575. png_const_charp text));
  576. #endif /* !PNG_VERSION_INFO_ONLY */
  577. #endif
  578. #endif
  579. /* Constants for known chunk types. If you need to add a chunk, define the name
  580. * here. For historical reasons these constants have the form png_<name>; i.e.
  581. * the prefix is lower case. Please use decimal values as the parameters to
  582. * match the ISO PNG specification and to avoid relying on the C locale
  583. * interpretation of character values.
  584. *
  585. * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values
  586. * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string
  587. * to be generated if required.
  588. *
  589. * PNG_32b correctly produces a value shifted by up to 24 bits, even on
  590. * architectures where (int) is only 16 bits.
  591. */
  592. #define PNG_32b(b,s) ((png_uint_32)(b) << (s))
  593. #define PNG_CHUNK(b1,b2,b3,b4) \
  594. (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
  595. #define png_IHDR PNG_CHUNK( 73, 72, 68, 82)
  596. #define png_IDAT PNG_CHUNK( 73, 68, 65, 84)
  597. #define png_IEND PNG_CHUNK( 73, 69, 78, 68)
  598. #define png_PLTE PNG_CHUNK( 80, 76, 84, 69)
  599. #define png_bKGD PNG_CHUNK( 98, 75, 71, 68)
  600. #define png_cHRM PNG_CHUNK( 99, 72, 82, 77)
  601. #define png_gAMA PNG_CHUNK(103, 65, 77, 65)
  602. #define png_hIST PNG_CHUNK(104, 73, 83, 84)
  603. #define png_iCCP PNG_CHUNK(105, 67, 67, 80)
  604. #define png_iTXt PNG_CHUNK(105, 84, 88, 116)
  605. #define png_oFFs PNG_CHUNK(111, 70, 70, 115)
  606. #define png_pCAL PNG_CHUNK(112, 67, 65, 76)
  607. #define png_sCAL PNG_CHUNK(115, 67, 65, 76)
  608. #define png_pHYs PNG_CHUNK(112, 72, 89, 115)
  609. #define png_sBIT PNG_CHUNK(115, 66, 73, 84)
  610. #define png_sPLT PNG_CHUNK(115, 80, 76, 84)
  611. #define png_sRGB PNG_CHUNK(115, 82, 71, 66)
  612. #define png_sTER PNG_CHUNK(115, 84, 69, 82)
  613. #define png_tEXt PNG_CHUNK(116, 69, 88, 116)
  614. #define png_tIME PNG_CHUNK(116, 73, 77, 69)
  615. #define png_tRNS PNG_CHUNK(116, 82, 78, 83)
  616. #define png_zTXt PNG_CHUNK(122, 84, 88, 116)
  617. /* The following will work on (signed char*) strings, whereas the get_uint_32
  618. * macro will fail on top-bit-set values because of the sign extension.
  619. */
  620. #define PNG_CHUNK_FROM_STRING(s)\
  621. PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3])
  622. /* This uses (char), not (png_byte) to avoid warnings on systems where (char) is
  623. * signed and the argument is a (char[]) This macro will fail miserably on
  624. * systems where (char) is more than 8 bits.
  625. */
  626. #define PNG_STRING_FROM_CHUNK(s,c)\
  627. (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\
  628. ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c)))
  629. /* Do the same but terminate with a null character. */
  630. #define PNG_CSTRING_FROM_CHUNK(s,c)\
  631. (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
  632. /* Test on flag values as defined in the spec (section 5.4): */
  633. #define PNG_CHUNK_ANCILLIARY(c) (1 & ((c) >> 29))
  634. #define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLIARY(c))
  635. #define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
  636. #define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
  637. #define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
  638. /* Gamma values (new at libpng-1.5.4): */
  639. #define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */
  640. #define PNG_GAMMA_MAC_INVERSE 65909
  641. #define PNG_GAMMA_sRGB_INVERSE 45455
  642. /* Almost everything below is C specific; the #defines above can be used in
  643. * non-C code (so long as it is C-preprocessed) the rest of this stuff cannot.
  644. */
  645. #ifndef PNG_VERSION_INFO_ONLY
  646. #include "pngstruct.h"
  647. #include "pnginfo.h"
  648. /* This is used for 16 bit gamma tables -- only the top level pointers are
  649. * const; this could be changed:
  650. */
  651. typedef const png_uint_16p * png_const_uint_16pp;
  652. /* Inhibit C++ name-mangling for libpng functions but not for system calls. */
  653. #ifdef __cplusplus
  654. extern "C" {
  655. #endif /* __cplusplus */
  656. /* These functions are used internally in the code. They generally
  657. * shouldn't be used unless you are writing code to add or replace some
  658. * functionality in libpng. More information about most functions can
  659. * be found in the files where the functions are located.
  660. */
  661. /* Check the user version string for compatibility, returns false if the version
  662. * numbers aren't compatible.
  663. */
  664. PNG_EXTERN int png_user_version_check(png_structp png_ptr,
  665. png_const_charp user_png_ver);
  666. /* Allocate memory for an internal libpng struct */
  667. PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)),
  668. PNG_ALLOCATED);
  669. /* Free memory from internal libpng struct */
  670. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  671. PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2,
  672. PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)),
  673. PNG_ALLOCATED);
  674. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  675. png_free_ptr free_fn, png_voidp mem_ptr));
  676. /* Free any memory that info_ptr points to and reset struct. */
  677. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  678. png_infop info_ptr));
  679. /* Function to allocate memory for zlib. PNGAPI is disallowed. */
  680. PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items,
  681. uInt size)),PNG_ALLOCATED);
  682. /* Function to free memory for zlib. PNGAPI is disallowed. */
  683. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  684. /* Next four functions are used internally as callbacks. PNGCBAPI is required
  685. * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to
  686. * PNGCBAPI at 1.5.0
  687. */
  688. PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr,
  689. png_bytep data, png_size_t length));
  690. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  691. PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  692. png_bytep buffer, png_size_t length));
  693. #endif
  694. PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr,
  695. png_bytep data, png_size_t length));
  696. #ifdef PNG_WRITE_FLUSH_SUPPORTED
  697. # ifdef PNG_STDIO_SUPPORTED
  698. PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr));
  699. # endif
  700. #endif
  701. /* Reset the CRC variable */
  702. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  703. /* Write the "data" buffer to whatever output you are using */
  704. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr,
  705. png_const_bytep data, png_size_t length));
  706. /* Read and check the PNG file signature */
  707. PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr));
  708. /* Read the chunk header (length + type name) */
  709. PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr));
  710. /* Read data from whatever input you are using into the "data" buffer */
  711. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  712. png_size_t length));
  713. /* Read bytes into buf, and update png_ptr->crc */
  714. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  715. png_size_t length));
  716. /* Decompress data in a chunk that uses compression */
  717. #if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED)
  718. PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr,
  719. int comp_type, png_size_t chunklength, png_size_t prefix_length,
  720. png_size_t *data_length));
  721. #endif
  722. /* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
  723. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  724. /* Read the CRC from the file and compare it to the libpng calculated CRC */
  725. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  726. /* Calculate the CRC over a section of data. Note that we are only
  727. * passing a maximum of 64K on systems that have this as a memory limit,
  728. * since this is the maximum buffer size we can specify.
  729. */
  730. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr,
  731. png_const_bytep ptr, png_size_t length));
  732. #ifdef PNG_WRITE_FLUSH_SUPPORTED
  733. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  734. #endif
  735. /* Write various chunks */
  736. /* Write the IHDR chunk, and update the png_struct with the necessary
  737. * information.
  738. */
  739. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  740. png_uint_32 height,
  741. int bit_depth, int color_type, int compression_method, int filter_method,
  742. int interlace_method));
  743. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr,
  744. png_const_colorp palette, png_uint_32 num_pal));
  745. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  746. png_size_t length));
  747. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  748. #ifdef PNG_WRITE_gAMA_SUPPORTED
  749. # ifdef PNG_FLOATING_POINT_SUPPORTED
  750. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  751. # endif
  752. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr,
  753. png_fixed_point file_gamma));
  754. #endif
  755. #ifdef PNG_WRITE_sBIT_SUPPORTED
  756. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr,
  757. png_const_color_8p sbit, int color_type));
  758. #endif
  759. #ifdef PNG_WRITE_cHRM_SUPPORTED
  760. # ifdef PNG_FLOATING_POINT_SUPPORTED
  761. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  762. double white_x, double white_y,
  763. double red_x, double red_y, double green_x, double green_y,
  764. double blue_x, double blue_y));
  765. # endif
  766. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  767. png_fixed_point int_white_x, png_fixed_point int_white_y,
  768. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  769. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  770. png_fixed_point int_blue_y));
  771. #endif
  772. #ifdef PNG_WRITE_sRGB_SUPPORTED
  773. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  774. int intent));
  775. #endif
  776. #ifdef PNG_WRITE_iCCP_SUPPORTED
  777. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  778. png_const_charp name, int compression_type,
  779. png_const_charp profile, int proflen));
  780. /* Note to maintainer: profile should be png_bytep */
  781. #endif
  782. #ifdef PNG_WRITE_sPLT_SUPPORTED
  783. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  784. png_const_sPLT_tp palette));
  785. #endif
  786. #ifdef PNG_WRITE_tRNS_SUPPORTED
  787. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr,
  788. png_const_bytep trans, png_const_color_16p values, int number,
  789. int color_type));
  790. #endif
  791. #ifdef PNG_WRITE_bKGD_SUPPORTED
  792. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  793. png_const_color_16p values, int color_type));
  794. #endif
  795. #ifdef PNG_WRITE_hIST_SUPPORTED
  796. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr,
  797. png_const_uint_16p hist, int num_hist));
  798. #endif
  799. #ifdef PNG_WRITE_tEXt_SUPPORTED
  800. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key,
  801. png_const_charp text, png_size_t text_len));
  802. #endif
  803. #ifdef PNG_WRITE_zTXt_SUPPORTED
  804. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key,
  805. png_const_charp text, png_size_t text_len, int compression));
  806. #endif
  807. #ifdef PNG_WRITE_iTXt_SUPPORTED
  808. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  809. int compression, png_const_charp key, png_const_charp lang,
  810. png_const_charp lang_key, png_const_charp text));
  811. #endif
  812. #ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */
  813. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  814. png_infop info_ptr, png_const_textp text_ptr, int num_text));
  815. #endif
  816. #ifdef PNG_WRITE_oFFs_SUPPORTED
  817. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  818. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  819. #endif
  820. #ifdef PNG_WRITE_pCAL_SUPPORTED
  821. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  822. png_int_32 X0, png_int_32 X1, int type, int nparams,
  823. png_const_charp units, png_charpp params));
  824. #endif
  825. #ifdef PNG_WRITE_pHYs_SUPPORTED
  826. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  827. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  828. int unit_type));
  829. #endif
  830. #ifdef PNG_WRITE_tIME_SUPPORTED
  831. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  832. png_const_timep mod_time));
  833. #endif
  834. #ifdef PNG_WRITE_sCAL_SUPPORTED
  835. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  836. int unit, png_const_charp width, png_const_charp height));
  837. #endif
  838. /* Called when finished processing a row of data */
  839. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  840. /* Internal use only. Called before first row of data */
  841. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  842. /* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an
  843. * array of png_ptr->width pixels. If the image is not interlaced or this
  844. * is the final pass this just does a png_memcpy, otherwise the "display" flag
  845. * is used to determine whether to copy pixels that are not in the current pass.
  846. *
  847. * Because 'png_do_read_interlace' (below) replicates pixels this allows this
  848. * function to achieve the documented 'blocky' appearance during interlaced read
  849. * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row'
  850. * are not changed if they are not in the current pass, when display is 0.
  851. *
  852. * 'display' must be 0 or 1, otherwise the memcpy will be done regardless.
  853. *
  854. * The API always reads from the png_struct row buffer and always assumes that
  855. * it is full width (png_do_read_interlace has already been called.)
  856. *
  857. * This function is only ever used to write to row buffers provided by the
  858. * caller of the relevant libpng API and the row must have already been
  859. * transformed by the read transformations.
  860. *
  861. * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed
  862. * bitmasks for use within the code, otherwise runtime generated masks are used.
  863. * The default is compile time masks.
  864. */
  865. #ifndef PNG_USE_COMPILE_TIME_MASKS
  866. # define PNG_USE_COMPILE_TIME_MASKS 1
  867. #endif
  868. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  869. int display));
  870. #ifdef PNG_READ_INTERLACING_SUPPORTED
  871. /* Expand an interlaced row: the 'row_info' describes the pass data that has
  872. * been read in and must correspond to the pixels in 'row', the pixels are
  873. * expanded (moved apart) in 'row' to match the final layout, when doing this
  874. * the pixels are *replicated* to the intervening space. This is essential for
  875. * the correct operation of png_combine_row, above.
  876. */
  877. PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
  878. png_bytep row, int pass, png_uint_32 transformations));
  879. #endif
  880. /* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */
  881. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  882. /* Grab pixels out of a row for an interlaced pass */
  883. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  884. png_bytep row, int pass));
  885. #endif
  886. /* Unfilter a row: check the filter value before calling this, there is no point
  887. * calling it for PNG_FILTER_VALUE_NONE.
  888. */
  889. PNG_EXTERN void png_read_filter_row PNGARG((png_structp pp, png_row_infop
  890. row_info, png_bytep row, png_const_bytep prev_row, int filter));
  891. PNG_EXTERN void png_read_filter_row_up_neon PNGARG((png_row_infop row_info,
  892. png_bytep row, png_const_bytep prev_row));
  893. PNG_EXTERN void png_read_filter_row_sub3_neon PNGARG((png_row_infop row_info,
  894. png_bytep row, png_const_bytep prev_row));
  895. PNG_EXTERN void png_read_filter_row_sub4_neon PNGARG((png_row_infop row_info,
  896. png_bytep row, png_const_bytep prev_row));
  897. PNG_EXTERN void png_read_filter_row_avg3_neon PNGARG((png_row_infop row_info,
  898. png_bytep row, png_const_bytep prev_row));
  899. PNG_EXTERN void png_read_filter_row_avg4_neon PNGARG((png_row_infop row_info,
  900. png_bytep row, png_const_bytep prev_row));
  901. PNG_EXTERN void png_read_filter_row_paeth3_neon PNGARG((png_row_infop row_info,
  902. png_bytep row, png_const_bytep prev_row));
  903. PNG_EXTERN void png_read_filter_row_paeth4_neon PNGARG((png_row_infop row_info,
  904. png_bytep row, png_const_bytep prev_row));
  905. /* Choose the best filter to use and filter the row data */
  906. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  907. png_row_infop row_info));
  908. /* Finish a row while reading, dealing with interlacing passes, etc. */
  909. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  910. /* Initialize the row buffers, etc. */
  911. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  912. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  913. /* Optional call to update the users info structure */
  914. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  915. png_infop info_ptr));
  916. #endif
  917. /* These are the functions that do the transformations */
  918. #ifdef PNG_READ_FILLER_SUPPORTED
  919. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  920. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  921. #endif
  922. #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
  923. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  924. png_bytep row));
  925. #endif
  926. #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
  927. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  928. png_bytep row));
  929. #endif
  930. #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
  931. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  932. png_bytep row));
  933. #endif
  934. #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
  935. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  936. png_bytep row));
  937. #endif
  938. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  939. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  940. PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info,
  941. png_bytep row, int at_start));
  942. #endif
  943. #ifdef PNG_16BIT_SUPPORTED
  944. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  945. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info,
  946. png_bytep row));
  947. #endif
  948. #endif
  949. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
  950. defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  951. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info,
  952. png_bytep row));
  953. #endif
  954. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  955. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr,
  956. png_row_infop row_info, png_bytep row));
  957. #endif
  958. #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
  959. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  960. png_bytep row));
  961. #endif
  962. #ifdef PNG_READ_PACK_SUPPORTED
  963. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info,
  964. png_bytep row));
  965. #endif
  966. #ifdef PNG_READ_SHIFT_SUPPORTED
  967. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info,
  968. png_bytep row, png_const_color_8p sig_bits));
  969. #endif
  970. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  971. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info,
  972. png_bytep row));
  973. #endif
  974. #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
  975. PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info,
  976. png_bytep row));
  977. #endif
  978. #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
  979. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info,
  980. png_bytep row));
  981. #endif
  982. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  983. PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info,
  984. png_bytep row, png_const_bytep palette_lookup,
  985. png_const_bytep quantize_lookup));
  986. # ifdef PNG_CORRECT_PALETTE_SUPPORTED
  987. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  988. png_colorp palette, int num_palette));
  989. # endif
  990. #endif
  991. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  992. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info,
  993. png_bytep row));
  994. #endif
  995. #ifdef PNG_WRITE_PACK_SUPPORTED
  996. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  997. png_bytep row, png_uint_32 bit_depth));
  998. #endif
  999. #ifdef PNG_WRITE_SHIFT_SUPPORTED
  1000. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info,
  1001. png_bytep row, png_const_color_8p bit_depth));
  1002. #endif
  1003. #if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
  1004. defined(PNG_READ_ALPHA_MODE_SUPPORTED)
  1005. PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info,
  1006. png_bytep row, png_structp png_ptr));
  1007. #endif
  1008. #ifdef PNG_READ_GAMMA_SUPPORTED
  1009. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info,
  1010. png_bytep row, png_structp png_ptr));
  1011. #endif
  1012. #ifdef PNG_READ_ALPHA_MODE_SUPPORTED
  1013. PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info,
  1014. png_bytep row, png_structp png_ptr));
  1015. #endif
  1016. #ifdef PNG_READ_EXPAND_SUPPORTED
  1017. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  1018. png_bytep row, png_const_colorp palette, png_const_bytep trans,
  1019. int num_trans));
  1020. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  1021. png_bytep row, png_const_color_16p trans_color));
  1022. #endif
  1023. #ifdef PNG_READ_EXPAND_16_SUPPORTED
  1024. PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info,
  1025. png_bytep row));
  1026. #endif
  1027. /* The following decodes the appropriate chunks, and does error correction,
  1028. * then calls the appropriate callback for the chunk if it is valid.
  1029. */
  1030. /* Decode the IHDR chunk */
  1031. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  1032. png_uint_32 length));
  1033. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  1034. png_uint_32 length));
  1035. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  1036. png_uint_32 length));
  1037. #ifdef PNG_READ_bKGD_SUPPORTED
  1038. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  1039. png_uint_32 length));
  1040. #endif
  1041. #ifdef PNG_READ_cHRM_SUPPORTED
  1042. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  1043. png_uint_32 length));
  1044. #endif
  1045. #ifdef PNG_READ_gAMA_SUPPORTED
  1046. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  1047. png_uint_32 length));
  1048. #endif
  1049. #ifdef PNG_READ_hIST_SUPPORTED
  1050. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  1051. png_uint_32 length));
  1052. #endif
  1053. #ifdef PNG_READ_iCCP_SUPPORTED
  1054. PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  1055. png_uint_32 length));
  1056. #endif /* PNG_READ_iCCP_SUPPORTED */
  1057. #ifdef PNG_READ_iTXt_SUPPORTED
  1058. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  1059. png_uint_32 length));
  1060. #endif
  1061. #ifdef PNG_READ_oFFs_SUPPORTED
  1062. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  1063. png_uint_32 length));
  1064. #endif
  1065. #ifdef PNG_READ_pCAL_SUPPORTED
  1066. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  1067. png_uint_32 length));
  1068. #endif
  1069. #ifdef PNG_READ_pHYs_SUPPORTED
  1070. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  1071. png_uint_32 length));
  1072. #endif
  1073. #ifdef PNG_READ_sBIT_SUPPORTED
  1074. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  1075. png_uint_32 length));
  1076. #endif
  1077. #ifdef PNG_READ_sCAL_SUPPORTED
  1078. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  1079. png_uint_32 length));
  1080. #endif
  1081. #ifdef PNG_READ_sPLT_SUPPORTED
  1082. PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  1083. png_uint_32 length));
  1084. #endif /* PNG_READ_sPLT_SUPPORTED */
  1085. #ifdef PNG_READ_sRGB_SUPPORTED
  1086. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  1087. png_uint_32 length));
  1088. #endif
  1089. #ifdef PNG_READ_tEXt_SUPPORTED
  1090. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  1091. png_uint_32 length));
  1092. #endif
  1093. #ifdef PNG_READ_tIME_SUPPORTED
  1094. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  1095. png_uint_32 length));
  1096. #endif
  1097. #ifdef PNG_READ_tRNS_SUPPORTED
  1098. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  1099. png_uint_32 length));
  1100. #endif
  1101. #ifdef PNG_READ_zTXt_SUPPORTED
  1102. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  1103. png_uint_32 length));
  1104. #endif
  1105. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  1106. png_infop info_ptr, png_uint_32 length));
  1107. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  1108. png_uint_32 chunk_name));
  1109. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  1110. /* Exactly as png_handle_as_unknown() except that the argument is a 32-bit chunk
  1111. * name, not a string.
  1112. */
  1113. PNG_EXTERN int png_chunk_unknown_handling PNGARG((png_structp png_ptr,
  1114. png_uint_32 chunk_name));
  1115. #endif
  1116. /* Handle the transformations for reading and writing */
  1117. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  1118. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr,
  1119. png_row_infop row_info));
  1120. #endif
  1121. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  1122. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr,
  1123. png_row_infop row_info));
  1124. #endif
  1125. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  1126. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  1127. #endif
  1128. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  1129. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  1130. png_infop info_ptr));
  1131. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  1132. png_infop info_ptr));
  1133. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  1134. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  1135. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  1136. png_bytep buffer, png_size_t buffer_length));
  1137. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  1138. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  1139. png_bytep buffer, png_size_t buffer_length));
  1140. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  1141. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  1142. png_infop info_ptr, png_uint_32 length));
  1143. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  1144. png_infop info_ptr));
  1145. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  1146. png_infop info_ptr));
  1147. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  1148. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  1149. png_infop info_ptr));
  1150. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  1151. png_infop info_ptr));
  1152. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  1153. # ifdef PNG_READ_tEXt_SUPPORTED
  1154. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  1155. png_infop info_ptr, png_uint_32 length));
  1156. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  1157. png_infop info_ptr));
  1158. # endif
  1159. # ifdef PNG_READ_zTXt_SUPPORTED
  1160. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  1161. png_infop info_ptr, png_uint_32 length));
  1162. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  1163. png_infop info_ptr));
  1164. # endif
  1165. # ifdef PNG_READ_iTXt_SUPPORTED
  1166. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  1167. png_infop info_ptr, png_uint_32 length));
  1168. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  1169. png_infop info_ptr));
  1170. # endif
  1171. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  1172. #ifdef PNG_MNG_FEATURES_SUPPORTED
  1173. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  1174. png_bytep row));
  1175. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  1176. png_bytep row));
  1177. #endif
  1178. /* Added at libpng version 1.4.0 */
  1179. #ifdef PNG_CHECK_cHRM_SUPPORTED
  1180. PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr,
  1181. png_fixed_point int_white_x, png_fixed_point int_white_y,
  1182. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  1183. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  1184. png_fixed_point int_blue_y));
  1185. #endif
  1186. #ifdef PNG_CHECK_cHRM_SUPPORTED
  1187. /* Added at libpng version 1.2.34 and 1.4.0 */
  1188. /* Currently only used by png_check_cHRM_fixed */
  1189. PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2,
  1190. unsigned long *hi_product, unsigned long *lo_product));
  1191. #endif
  1192. #ifdef PNG_cHRM_SUPPORTED
  1193. /* Added at libpng version 1.5.5 */
  1194. typedef struct png_xy
  1195. {
  1196. png_fixed_point redx, redy;
  1197. png_fixed_point greenx, greeny;
  1198. png_fixed_point bluex, bluey;
  1199. png_fixed_point whitex, whitey;
  1200. } png_xy;
  1201. typedef struct png_XYZ
  1202. {
  1203. png_fixed_point redX, redY, redZ;
  1204. png_fixed_point greenX, greenY, greenZ;
  1205. png_fixed_point blueX, blueY, blueZ;
  1206. } png_XYZ;
  1207. /* The conversion APIs return 0 on success, non-zero on a parameter error. They
  1208. * allow conversion between the above representations of a color encoding. When
  1209. * converting from XYZ end points to chromaticities the absolute magnitude of
  1210. * the end points is lost, when converting back the sum of the Y values of the
  1211. * three end points will be 1.0
  1212. */
  1213. PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ));
  1214. PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy));
  1215. PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_structp png_ptr,
  1216. png_XYZ *XYZ, png_xy xy));
  1217. #endif
  1218. /* Added at libpng version 1.4.0 */
  1219. PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr,
  1220. png_uint_32 width, png_uint_32 height, int bit_depth,
  1221. int color_type, int interlace_type, int compression_type,
  1222. int filter_type));
  1223. /* Added at libpng version 1.5.10 */
  1224. #if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
  1225. defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
  1226. PNG_EXTERN void png_do_check_palette_indexes PNGARG((png_structp png_ptr,
  1227. png_row_infop row_info));
  1228. #endif
  1229. /* Free all memory used by the read (old method - NOT DLL EXPORTED) */
  1230. PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr,
  1231. png_infop info_ptr, png_infop end_info_ptr));
  1232. /* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
  1233. PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr));
  1234. #ifdef USE_FAR_KEYWORD /* memory model conversion function */
  1235. PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr,
  1236. int check));
  1237. #endif /* USE_FAR_KEYWORD */
  1238. #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
  1239. PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr,
  1240. png_const_charp name),PNG_NORETURN);
  1241. #endif
  1242. /* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite
  1243. * the end. Always leaves the buffer nul terminated. Never errors out (and
  1244. * there is no error code.)
  1245. */
  1246. PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos,
  1247. png_const_charp string);
  1248. /* Various internal functions to handle formatted warning messages, currently
  1249. * only implemented for warnings.
  1250. */
  1251. #if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
  1252. /* Utility to dump an unsigned value into a buffer, given a start pointer and
  1253. * and end pointer (which should point just *beyond* the end of the buffer!)
  1254. * Returns the pointer to the start of the formatted string. This utility only
  1255. * does unsigned values.
  1256. */
  1257. PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end,
  1258. int format, png_alloc_size_t number);
  1259. /* Convenience macro that takes an array: */
  1260. #define PNG_FORMAT_NUMBER(buffer,format,number) \
  1261. png_format_number(buffer, buffer + (sizeof buffer), format, number)
  1262. /* Suggested size for a number buffer (enough for 64 bits and a sign!) */
  1263. #define PNG_NUMBER_BUFFER_SIZE 24
  1264. /* These are the integer formats currently supported, the name is formed from
  1265. * the standard printf(3) format string.
  1266. */
  1267. #define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */
  1268. #define PNG_NUMBER_FORMAT_02u 2
  1269. #define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */
  1270. #define PNG_NUMBER_FORMAT_02d 2
  1271. #define PNG_NUMBER_FORMAT_x 3
  1272. #define PNG_NUMBER_FORMAT_02x 4
  1273. #define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */
  1274. #endif
  1275. #ifdef PNG_WARNINGS_SUPPORTED
  1276. /* New defines and members adding in libpng-1.5.4 */
  1277. # define PNG_WARNING_PARAMETER_SIZE 32
  1278. # define PNG_WARNING_PARAMETER_COUNT 8
  1279. /* An l-value of this type has to be passed to the APIs below to cache the
  1280. * values of the parameters to a formatted warning message.
  1281. */
  1282. typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][
  1283. PNG_WARNING_PARAMETER_SIZE];
  1284. PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number,
  1285. png_const_charp string);
  1286. /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters,
  1287. * including the trailing '\0'.
  1288. */
  1289. PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p,
  1290. int number, int format, png_alloc_size_t value);
  1291. /* Use png_alloc_size_t because it is an unsigned type as big as any we
  1292. * need to output. Use the following for a signed value.
  1293. */
  1294. PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p,
  1295. int number, int format, png_int_32 value);
  1296. PNG_EXTERN void png_formatted_warning(png_structp png_ptr,
  1297. png_warning_parameters p, png_const_charp message);
  1298. /* 'message' follows the X/Open approach of using @1, @2 to insert
  1299. * parameters previously supplied using the above functions. Errors in
  1300. * specifying the paramters will simple result in garbage substitutions.
  1301. */
  1302. #endif
  1303. /* ASCII to FP interfaces, currently only implemented if sCAL
  1304. * support is required.
  1305. */
  1306. #ifdef PNG_sCAL_SUPPORTED
  1307. /* MAX_DIGITS is actually the maximum number of characters in an sCAL
  1308. * width or height, derived from the precision (number of significant
  1309. * digits - a build time settable option) and assumpitions about the
  1310. * maximum ridiculous exponent.
  1311. */
  1312. #define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)
  1313. #endif
  1314. #ifdef PNG_sCAL_SUPPORTED
  1315. #ifdef PNG_FLOATING_POINT_SUPPORTED
  1316. PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii,
  1317. png_size_t size, double fp, unsigned int precision));
  1318. #endif /* FLOATING_POINT */
  1319. #ifdef PNG_FIXED_POINT_SUPPORTED
  1320. PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr,
  1321. png_charp ascii, png_size_t size, png_fixed_point fp));
  1322. #endif /* FIXED_POINT */
  1323. #endif /* READ_sCAL */
  1324. #if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
  1325. /* An internal API to validate the format of a floating point number.
  1326. * The result is the index of the next character. If the number is
  1327. * not valid it will be the index of a character in the supposed number.
  1328. *
  1329. * The format of a number is defined in the PNG extensions specification
  1330. * and this API is strictly conformant to that spec, not anyone elses!
  1331. *
  1332. * The format as a regular expression is:
  1333. *
  1334. * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
  1335. *
  1336. * or:
  1337. *
  1338. * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
  1339. *
  1340. * The complexity is that either integer or fraction must be present and the
  1341. * fraction is permitted to have no digits only if the integer is present.
  1342. *
  1343. * NOTE: The dangling E problem.
  1344. * There is a PNG valid floating point number in the following:
  1345. *
  1346. * PNG floating point numb1.ers are not greedy.
  1347. *
  1348. * Working this out requires *TWO* character lookahead (because of the
  1349. * sign), the parser does not do this - it will fail at the 'r' - this
  1350. * doesn't matter for PNG sCAL chunk values, but it requires more care
  1351. * if the value were ever to be embedded in something more complex. Use
  1352. * ANSI-C strtod if you need the lookahead.
  1353. */
  1354. /* State table for the parser. */
  1355. #define PNG_FP_INTEGER 0 /* before or in integer */
  1356. #define PNG_FP_FRACTION 1 /* before or in fraction */
  1357. #define PNG_FP_EXPONENT 2 /* before or in exponent */
  1358. #define PNG_FP_STATE 3 /* mask for the above */
  1359. #define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */
  1360. #define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */
  1361. #define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */
  1362. #define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */
  1363. #define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */
  1364. /* These three values don't affect the parser. They are set but not used.
  1365. */
  1366. #define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */
  1367. #define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */
  1368. #define PNG_FP_NONZERO 256 /* A non-zero value */
  1369. #define PNG_FP_STICKY 448 /* The above three flags */
  1370. /* This is available for the caller to store in 'state' if required. Do not
  1371. * call the parser after setting it (the parser sometimes clears it.)
  1372. */
  1373. #define PNG_FP_INVALID 512 /* Available for callers as a distinct value */
  1374. /* Result codes for the parser (boolean - true meants ok, false means
  1375. * not ok yet.)
  1376. */
  1377. #define PNG_FP_MAYBE 0 /* The number may be valid in the future */
  1378. #define PNG_FP_OK 1 /* The number is valid */
  1379. /* Tests on the sticky non-zero and negative flags. To pass these checks
  1380. * the state must also indicate that the whole number is valid - this is
  1381. * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this
  1382. * is equivalent to PNG_FP_OK above.)
  1383. */
  1384. #define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO)
  1385. /* NZ_MASK: the string is valid and a non-zero negative value */
  1386. #define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO)
  1387. /* Z MASK: the string is valid and a non-zero value. */
  1388. /* PNG_FP_SAW_DIGIT: the string is valid. */
  1389. #define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT)
  1390. #define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)
  1391. #define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)
  1392. /* The actual parser. This can be called repeatedly. It updates
  1393. * the index into the string and the state variable (which must
  1394. * be initialized to 0). It returns a result code, as above. There
  1395. * is no point calling the parser any more if it fails to advance to
  1396. * the end of the string - it is stuck on an invalid character (or
  1397. * terminated by '\0').
  1398. *
  1399. * Note that the pointer will consume an E or even an E+ and then leave
  1400. * a 'maybe' state even though a preceding integer.fraction is valid.
  1401. * The PNG_FP_WAS_VALID flag indicates that a preceding substring was
  1402. * a valid number. It's possible to recover from this by calling
  1403. * the parser again (from the start, with state 0) but with a string
  1404. * that omits the last character (i.e. set the size to the index of
  1405. * the problem character.) This has not been tested within libpng.
  1406. */
  1407. PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string,
  1408. png_size_t size, int *statep, png_size_tp whereami));
  1409. /* This is the same but it checks a complete string and returns true
  1410. * only if it just contains a floating point number. As of 1.5.4 this
  1411. * function also returns the state at the end of parsing the number if
  1412. * it was valid (otherwise it returns 0.) This can be used for testing
  1413. * for negative or zero values using the sticky flag.
  1414. */
  1415. PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string,
  1416. png_size_t size));
  1417. #endif /* pCAL || sCAL */
  1418. #if defined(PNG_READ_GAMMA_SUPPORTED) ||\
  1419. defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
  1420. /* Added at libpng version 1.5.0 */
  1421. /* This is a utility to provide a*times/div (rounded) and indicate
  1422. * if there is an overflow. The result is a boolean - false (0)
  1423. * for overflow, true (1) if no overflow, in which case *res
  1424. * holds the result.
  1425. */
  1426. PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a,
  1427. png_int_32 multiplied_by, png_int_32 divided_by));
  1428. #endif
  1429. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
  1430. /* Same deal, but issue a warning on overflow and return 0. */
  1431. PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr,
  1432. png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by));
  1433. #endif
  1434. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED)
  1435. /* Calculate a reciprocal - used for gamma values. This returns
  1436. * 0 if the argument is 0 in order to maintain an undefined value,
  1437. * there are no warnings.
  1438. */
  1439. PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a));
  1440. /* The same but gives a reciprocal of the product of two fixed point
  1441. * values. Accuracy is suitable for gamma calculations but this is
  1442. * not exact - use png_muldiv for that.
  1443. */
  1444. PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a,
  1445. png_fixed_point b));
  1446. #endif
  1447. #ifdef PNG_READ_GAMMA_SUPPORTED
  1448. /* Internal fixed point gamma correction. These APIs are called as
  1449. * required to convert single values - they don't need to be fast,
  1450. * they are not used when processing image pixel values.
  1451. *
  1452. * While the input is an 'unsigned' value it must actually be the
  1453. * correct bit value - 0..255 or 0..65535 as required.
  1454. */
  1455. PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr,
  1456. unsigned int value, png_fixed_point gamma_value));
  1457. PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value));
  1458. PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value,
  1459. png_fixed_point gamma_value));
  1460. PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value,
  1461. png_fixed_point gamma_value));
  1462. PNG_EXTERN void png_destroy_gamma_table(png_structp png_ptr);
  1463. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
  1464. int bit_depth));
  1465. #endif
  1466. /* Missing declarations if FIXED_POINT is *not* supported - fixed properly
  1467. * in libpng 1.6
  1468. */
  1469. #ifndef PNG_FIXED_POINT_SUPPORTED
  1470. #ifdef PNG_cHRM_SUPPORTED
  1471. PNG_EXTERN png_uint_32 png_get_cHRM_XYZ_fixed PNGARG(
  1472. (png_structp png_ptr, png_const_infop info_ptr,
  1473. png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
  1474. png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
  1475. png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
  1476. png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
  1477. png_fixed_point *int_blue_Z));
  1478. PNG_EXTERN void png_set_cHRM_XYZ_fixed PNGARG((png_structp png_ptr,
  1479. png_infop info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y,
  1480. png_fixed_point int_red_Z, png_fixed_point int_green_X,
  1481. png_fixed_point int_green_Y, png_fixed_point int_green_Z,
  1482. png_fixed_point int_blue_X, png_fixed_point int_blue_Y,
  1483. png_fixed_point int_blue_Z));
  1484. PNG_EXTERN void png_set_cHRM_fixed PNGARG((png_structp png_ptr,
  1485. png_infop info_ptr, png_fixed_point int_white_x,
  1486. png_fixed_point int_white_y, png_fixed_point int_red_x,
  1487. png_fixed_point int_red_y, png_fixed_point int_green_x,
  1488. png_fixed_point int_green_y, png_fixed_point int_blue_x,
  1489. png_fixed_point int_blue_y));
  1490. #endif
  1491. #ifdef PNG_gAMA_SUPPORTED
  1492. PNG_EXTERN png_uint_32 png_get_gAMA_fixed PNGARG(
  1493. (png_const_structp png_ptr, png_const_infop info_ptr,
  1494. png_fixed_point *int_file_gamma));
  1495. PNG_EXTERN void png_set_gAMA_fixed PNGARG((png_structp png_ptr,
  1496. png_infop info_ptr, png_fixed_point int_file_gamma));
  1497. #endif
  1498. #ifdef PNG_READ_BACKGROUND_SUPPORTED
  1499. PNG_EXTERN void png_set_background_fixed PNGARG((png_structp png_ptr,
  1500. png_const_color_16p background_color, int background_gamma_code,
  1501. int need_expand, png_fixed_point background_gamma));
  1502. #endif
  1503. #ifdef PNG_READ_ALPHA_MODE_SUPPORTED
  1504. PNG_EXTERN void png_set_alpha_mode_fixed PNGARG((png_structp png_ptr,
  1505. int mode, png_fixed_point output_gamma));
  1506. #endif
  1507. #ifdef PNG_READ_GAMMA_SUPPORTED
  1508. PNG_EXTERN void png_set_gamma_fixed PNGARG((png_structp png_ptr,
  1509. png_fixed_point screen_gamma, png_fixed_point override_file_gamma));
  1510. #endif
  1511. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  1512. PNG_EXTERN void png_set_rgb_to_gray_fixed PNGARG((png_structp png_ptr,
  1513. int error_action, png_fixed_point red, png_fixed_point green));
  1514. #endif
  1515. #endif /* FIX MISSING !FIXED_POINT DECLARATIONS */
  1516. /* These are initialization functions for hardware specific PNG filter
  1517. * optimizations; list these here then select the appropriate one at compile
  1518. * time using the macro PNG_FILTER_OPTIMIZATIONS. If the macro is not defined
  1519. * the generic code is used.
  1520. */
  1521. #ifdef PNG_FILTER_OPTIMIZATIONS
  1522. PNG_EXTERN void PNG_FILTER_OPTIMIZATIONS(png_structp png_ptr, unsigned int bpp);
  1523. /* Just declare the optimization that will be used */
  1524. #else
  1525. /* List *all* the possible optimizations here - this branch is required if
  1526. * the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in
  1527. * CFLAGS in place of CPPFLAGS *and* uses symbol prefixing.
  1528. */
  1529. PNG_EXTERN void png_init_filter_functions_neon(png_structp png_ptr,
  1530. unsigned int bpp);
  1531. #endif
  1532. /* Maintainer: Put new private prototypes here ^ */
  1533. #include "pngdebug.h"
  1534. #ifdef __cplusplus
  1535. }
  1536. #endif
  1537. #endif /* PNG_VERSION_INFO_ONLY */
  1538. #endif /* PNGPRIV_H */