pngpriv.h 61 KB

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