Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1246 lines
47 KiB

  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.2 [March 31, 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. /* This is required for the definition of abort(), used as a last ditch
  25. * error handler when all else fails.
  26. */
  27. #include <stdlib.h>
  28. #define PNGLIB_BUILD
  29. #ifdef PNG_USER_CONFIG
  30. # include "pngusr.h"
  31. /* These should have been defined in pngusr.h */
  32. # ifndef PNG_USER_PRIVATEBUILD
  33. # define PNG_USER_PRIVATEBUILD "Custom libpng build"
  34. # endif
  35. # ifndef PNG_USER_DLLFNAME_POSTFIX
  36. # define PNG_USER_DLLFNAME_POSTFIX "Cb"
  37. # endif
  38. #endif
  39. #include "png.h"
  40. #include "pnginfo.h"
  41. #include "pngstruct.h"
  42. /* This is used for 16 bit gamma tables - only the top level pointers are const,
  43. * this could be changed:
  44. */
  45. typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
  46. /* Added at libpng-1.2.9 */
  47. /* Moved to pngpriv.h at libpng-1.5.0 */
  48. /* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure"
  49. * script. We may need it here to get the correct configuration on things
  50. * like limits.
  51. */
  52. #ifdef PNG_CONFIGURE_LIBPNG
  53. # ifdef HAVE_CONFIG_H
  54. # include "config.h"
  55. # endif
  56. #endif
  57. /* Moved to pngpriv.h at libpng-1.5.0 */
  58. /* NOTE: some of these may have been used in external applications as
  59. * these definitions were exposed in pngconf.h prior to 1.5.
  60. */
  61. /* If you are running on a machine where you cannot allocate more
  62. * than 64K of memory at once, uncomment this. While libpng will not
  63. * normally need that much memory in a chunk (unless you load up a very
  64. * large file), zlib needs to know how big of a chunk it can use, and
  65. * libpng thus makes sure to check any memory allocation to verify it
  66. * will fit into memory.
  67. *
  68. * zlib provides 'MAXSEG_64K' which, if defined, indicates the
  69. * same limit and pngconf.h (already included) sets the limit
  70. * if certain operating systems are detected.
  71. */
  72. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  73. # define PNG_MAX_MALLOC_64K
  74. #endif
  75. #ifndef PNG_UNUSED
  76. /* Unused formal parameter warnings are silenced using the following macro
  77. * which is expected to have no bad effects on performance (optimizing
  78. * compilers will probably remove it entirely). Note that if you replace
  79. * it with something other than whitespace, you must include the terminating
  80. * semicolon.
  81. */
  82. # define PNG_UNUSED(param) (void)param;
  83. #endif
  84. /* Just a little check that someone hasn't tried to define something
  85. * contradictory.
  86. */
  87. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  88. # undef PNG_ZBUF_SIZE
  89. # define PNG_ZBUF_SIZE 65536L
  90. #endif
  91. /* If warnings or errors are turned off the code is disabled
  92. * or redirected here.
  93. */
  94. #ifndef PNG_WARNINGS_SUPPORTED
  95. # define png_warning(s1,s2) ((void)0)
  96. # define png_chunk_warning(s1,s2) ((void)0)
  97. #endif
  98. #ifndef PNG_ERROR_TEXT_SUPPORTED
  99. # define png_error(s1,s2) png_err(s1)
  100. # define png_chunk_error(s1,s2) png_err(s1)
  101. # define png_fixed_error(s1,s2) png_err(s1)
  102. #endif
  103. #ifndef PNG_EXTERN
  104. /* The functions exported by PNG_EXTERN are internal functions, which
  105. * aren't usually used outside the library (as far as I know), so it is
  106. * debatable if they should be exported at all. In the future, when it
  107. * is possible to have run-time registry of chunk-handling functions,
  108. * some of these might be made available again.
  109. # define PNG_EXTERN extern
  110. */
  111. # define PNG_EXTERN
  112. #endif
  113. /* Some fixed point APIs are still required even if not exported because
  114. * they get used by the corresponding floating point APIs. This magic
  115. * deals with this:
  116. */
  117. #ifdef PNG_FIXED_POINT_SUPPORTED
  118. # define PNGFAPI PNGAPI
  119. #else
  120. # define PNGFAPI /* PRIVATE */
  121. #endif
  122. /* Other defines specific to compilers can go here. Try to keep
  123. * them inside an appropriate ifdef/endif pair for portability.
  124. */
  125. #if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
  126. defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
  127. /* png.c requires the following ANSI-C constants if the conversion of
  128. * floating point to ASCII is implemented therein:
  129. *
  130. * DBL_DIG Maximum number of decimal digits (can be set to any constant)
  131. * DBL_MIN Smallest normalized fp number (can be set to an arbitrary value)
  132. * DBL_MAX Maximum floating point number (can be set to an arbitrary value)
  133. */
  134. # include <float.h>
  135. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  136. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  137. /* We need to check that <math.h> hasn't already been included earlier
  138. * as it seems it doesn't agree with <fp.h>, yet we should really use
  139. * <fp.h> if possible.
  140. */
  141. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  142. # include <fp.h>
  143. # endif
  144. # else
  145. # include <math.h>
  146. # endif
  147. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  148. /* Amiga SAS/C: We must include builtin FPU functions when compiling using
  149. * MATH=68881
  150. */
  151. # include <m68881.h>
  152. # endif
  153. #endif
  154. /* This provides the non-ANSI (far) memory allocation routines. */
  155. #if defined(__TURBOC__) && defined(__MSDOS__)
  156. # include <mem.h>
  157. # include <alloc.h>
  158. #endif
  159. #if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \
  160. defined(_WIN32) || defined(__WIN32__)
  161. # include <windows.h> /* defines _WINDOWS_ macro */
  162. #endif
  163. /* Moved here around 1.5.0beta36 from pngconf.h */
  164. /* Users may want to use these so they are not private. Any library
  165. * functions that are passed far data must be model-independent.
  166. */
  167. /* Memory model/platform independent fns */
  168. #ifndef PNG_ABORT
  169. # ifdef _WINDOWS_
  170. # define PNG_ABORT() ExitProcess(0)
  171. # else
  172. # define PNG_ABORT() abort()
  173. # endif
  174. #endif
  175. #ifdef USE_FAR_KEYWORD
  176. /* Use this to make far-to-near assignments */
  177. # define CHECK 1
  178. # define NOCHECK 0
  179. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  180. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  181. # define png_strcpy _fstrcpy
  182. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  183. # define png_strlen _fstrlen
  184. # define png_memcmp _fmemcmp /* SJT: added */
  185. # define png_memcpy _fmemcpy
  186. # define png_memset _fmemset
  187. # define png_sprintf sprintf
  188. #else
  189. # ifdef _WINDOWS_ /* Favor Windows over C runtime fns */
  190. # define CVT_PTR(ptr) (ptr)
  191. # define CVT_PTR_NOCHECK(ptr) (ptr)
  192. # define png_strcpy lstrcpyA
  193. # define png_strncpy lstrcpynA
  194. # define png_strlen lstrlenA
  195. # define png_memcmp memcmp
  196. # define png_memcpy CopyMemory
  197. # define png_memset memset
  198. # define png_sprintf wsprintfA
  199. # else
  200. # define CVT_PTR(ptr) (ptr)
  201. # define CVT_PTR_NOCHECK(ptr) (ptr)
  202. # define png_strcpy strcpy
  203. # define png_strncpy strncpy /* Added to v 1.2.6 */
  204. # define png_strlen strlen
  205. # define png_memcmp memcmp /* SJT: added */
  206. # define png_memcpy memcpy
  207. # define png_memset memset
  208. # define png_sprintf sprintf
  209. # endif
  210. #endif
  211. /* End of memory model/platform independent support */
  212. #ifndef PNG_NO_SNPRINTF
  213. # ifdef _MSC_VER
  214. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  215. # define png_snprintf2 _snprintf
  216. # define png_snprintf6 _snprintf
  217. # else
  218. # define png_snprintf snprintf /* Added to v 1.2.19 */
  219. # define png_snprintf2 snprintf
  220. # define png_snprintf6 snprintf
  221. # endif
  222. #else
  223. /* You don't have or don't want to use snprintf(). Caution: Using
  224. * sprintf instead of snprintf exposes your application to accidental
  225. * or malevolent buffer overflows. If you don't have snprintf()
  226. * as a general rule you should provide one (you can get one from
  227. * Portable OpenSSH).
  228. */
  229. # define png_snprintf(s1,n,fmt,x1) png_sprintf(s1,fmt,x1)
  230. # define png_snprintf2(s1,n,fmt,x1,x2) png_sprintf(s1,fmt,x1,x2)
  231. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  232. png_sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  233. #endif
  234. /* End of 1.5.0beta36 move from pngconf.h */
  235. /* CONSTANTS and UTILITY MACROS
  236. * These are used internally by libpng and not exposed in the API
  237. */
  238. /* Various modes of operation. Note that after an init, mode is set to
  239. * zero automatically when the structure is created.
  240. */
  241. #define PNG_HAVE_IHDR 0x01
  242. #define PNG_HAVE_PLTE 0x02
  243. #define PNG_HAVE_IDAT 0x04
  244. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  245. #define PNG_HAVE_IEND 0x10
  246. #define PNG_HAVE_gAMA 0x20
  247. #define PNG_HAVE_cHRM 0x40
  248. #define PNG_HAVE_sRGB 0x80
  249. #define PNG_HAVE_CHUNK_HEADER 0x100
  250. #define PNG_WROTE_tIME 0x200
  251. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  252. #define PNG_BACKGROUND_IS_GRAY 0x800
  253. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  254. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  255. /* Flags for the transformations the PNG library does on the image data */
  256. #define PNG_BGR 0x0001
  257. #define PNG_INTERLACE 0x0002
  258. #define PNG_PACK 0x0004
  259. #define PNG_SHIFT 0x0008
  260. #define PNG_SWAP_BYTES 0x0010
  261. #define PNG_INVERT_MONO 0x0020
  262. #define PNG_QUANTIZE 0x0040
  263. #define PNG_BACKGROUND 0x0080
  264. #define PNG_BACKGROUND_EXPAND 0x0100
  265. #define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */
  266. #define PNG_16_TO_8 0x0400
  267. #define PNG_RGBA 0x0800
  268. #define PNG_EXPAND 0x1000
  269. #define PNG_GAMMA 0x2000
  270. #define PNG_GRAY_TO_RGB 0x4000
  271. #define PNG_FILLER 0x8000L
  272. #define PNG_PACKSWAP 0x10000L
  273. #define PNG_SWAP_ALPHA 0x20000L
  274. #define PNG_STRIP_ALPHA 0x40000L
  275. #define PNG_INVERT_ALPHA 0x80000L
  276. #define PNG_USER_TRANSFORM 0x100000L
  277. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  278. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  279. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  280. /* 0x800000L Unused */
  281. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  282. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  283. /* 0x4000000L unused */
  284. /* 0x8000000L unused */
  285. /* 0x10000000L unused */
  286. /* 0x20000000L unused */
  287. /* 0x40000000L unused */
  288. /* Flags for png_create_struct */
  289. #define PNG_STRUCT_PNG 0x0001
  290. #define PNG_STRUCT_INFO 0x0002
  291. /* Scaling factor for filter heuristic weighting calculations */
  292. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  293. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  294. /* Flags for the png_ptr->flags rather than declaring a byte for each one */
  295. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  296. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  297. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  298. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  299. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  300. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  301. #define PNG_FLAG_ROW_INIT 0x0040
  302. #define PNG_FLAG_FILLER_AFTER 0x0080
  303. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  304. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  305. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  306. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  307. /* 0x1000 unused */
  308. /* 0x2000 unused */
  309. /* 0x4000 unused */
  310. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  311. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  312. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  313. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  314. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  315. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  316. /* 0x200000L unused */
  317. /* 0x400000L unused */
  318. #define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000L /* Added to libpng-1.4.0 */
  319. /* 0x1000000L unused */
  320. /* 0x2000000L unused */
  321. /* 0x4000000L unused */
  322. /* 0x8000000L unused */
  323. /* 0x10000000L unused */
  324. /* 0x20000000L unused */
  325. /* 0x40000000L unused */
  326. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  327. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  328. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  329. PNG_FLAG_CRC_CRITICAL_IGNORE)
  330. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  331. PNG_FLAG_CRC_CRITICAL_MASK)
  332. /* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
  333. * can handle at once. This type need be no larger than 16 bits (so maximum of
  334. * 65535), this define allows us to discover how big it is, but limited by the
  335. * maximuum for png_size_t. The value can be overriden in a library build
  336. * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
  337. * lower value (e.g. 255 works). A lower value may help memory usage (slightly)
  338. * and may even improve performance on some systems (and degrade it on others.)
  339. */
  340. #ifndef ZLIB_IO_MAX
  341. # define ZLIB_IO_MAX ((uInt)-1)
  342. #endif
  343. /* Save typing and make code easier to understand */
  344. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  345. abs((int)((c1).green) - (int)((c2).green)) + \
  346. abs((int)((c1).blue) - (int)((c2).blue)))
  347. /* Added to libpng-1.2.6 JB */
  348. #define PNG_ROWBYTES(pixel_bits, width) \
  349. ((pixel_bits) >= 8 ? \
  350. ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
  351. (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )
  352. /* PNG_OUT_OF_RANGE returns true if value is outside the range
  353. * ideal-delta..ideal+delta. Each argument is evaluated twice.
  354. * "ideal" and "delta" should be constants, normally simple
  355. * integers, "value" a variable. Added to libpng-1.2.6 JB
  356. */
  357. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  358. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  359. /* Conversions between fixed and floating point, only defined if
  360. * required (to make sure the code doesn't accidentally use float
  361. * when it is supposedly disabled.)
  362. */
  363. #ifdef PNG_FLOATING_POINT_SUPPORTED
  364. /* The floating point conversion can't overflow, though it can and
  365. * does lose accuracy relative to the original fixed point value.
  366. * In practice this doesn't matter because png_fixed_point only
  367. * stores numbers with very low precision. The png_ptr and s
  368. * arguments are unused by default but are there in case error
  369. * checking becomes a requirement.
  370. */
  371. #define png_float(png_ptr, fixed, s) (.00001 * (fixed))
  372. /* The fixed point conversion performs range checking and evaluates
  373. * its argument multiple times, so must be used with care. The
  374. * range checking uses the PNG specification values for a signed
  375. * 32 bit fixed point value except that the values are deliberately
  376. * rounded-to-zero to an integral value - 21474 (21474.83 is roughly
  377. * (2^31-1) * 100000). 's' is a string that describes the value being
  378. * converted.
  379. *
  380. * NOTE: this macro will raise a png_error if the range check fails,
  381. * therefore it is normally only appropriate to use this on values
  382. * that come from API calls or other sources where an out of range
  383. * error indicates a programming error, not a data error!
  384. *
  385. * NOTE: by default this is off - the macro is not used - because the
  386. * function call saves a lot of code.
  387. */
  388. #ifdef PNG_FIXED_POINT_MACRO_SUPPORTED
  389. #define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
  390. ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))
  391. #else
  392. PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp,
  393. png_const_charp text));
  394. #endif
  395. #endif
  396. /* Constant strings for known chunk types. If you need to add a chunk,
  397. * define the name here, and add an invocation of the macro wherever it's
  398. * needed.
  399. */
  400. #define PNG_IHDR PNG_CONST png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  401. #define PNG_IDAT PNG_CONST png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  402. #define PNG_IEND PNG_CONST png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  403. #define PNG_PLTE PNG_CONST png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  404. #define PNG_bKGD PNG_CONST png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  405. #define PNG_cHRM PNG_CONST png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  406. #define PNG_gAMA PNG_CONST png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  407. #define PNG_hIST PNG_CONST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  408. #define PNG_iCCP PNG_CONST png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  409. #define PNG_iTXt PNG_CONST png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  410. #define PNG_oFFs PNG_CONST png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  411. #define PNG_pCAL PNG_CONST png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  412. #define PNG_sCAL PNG_CONST png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  413. #define PNG_pHYs PNG_CONST png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  414. #define PNG_sBIT PNG_CONST png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  415. #define PNG_sPLT PNG_CONST png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  416. #define PNG_sRGB PNG_CONST png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  417. #define PNG_sTER PNG_CONST png_byte png_sTER[5] = {115, 84, 69, 82, '\0'}
  418. #define PNG_tEXt PNG_CONST png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  419. #define PNG_tIME PNG_CONST png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  420. #define PNG_tRNS PNG_CONST png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  421. #define PNG_zTXt PNG_CONST png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  422. /* Inhibit C++ name-mangling for libpng functions but not for system calls. */
  423. #ifdef __cplusplus
  424. extern "C" {
  425. #endif /* __cplusplus */
  426. /* These functions are used internally in the code. They generally
  427. * shouldn't be used unless you are writing code to add or replace some
  428. * functionality in libpng. More information about most functions can
  429. * be found in the files where the functions are located.
  430. */
  431. /* Allocate memory for an internal libpng struct */
  432. PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)),
  433. PNG_ALLOCATED);
  434. /* Free memory from internal libpng struct */
  435. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  436. PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2,
  437. PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)),
  438. PNG_ALLOCATED);
  439. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  440. png_free_ptr free_fn, png_voidp mem_ptr));
  441. /* Free any memory that info_ptr points to and reset struct. */
  442. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  443. png_infop info_ptr));
  444. /* Function to allocate memory for zlib. PNGAPI is disallowed. */
  445. PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items,
  446. uInt size)),PNG_ALLOCATED);
  447. /* Function to free memory for zlib. PNGAPI is disallowed. */
  448. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  449. /* Next four functions are used internally as callbacks. PNGCBAPI is required
  450. * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to
  451. * PNGCBAPI at 1.5.0
  452. */
  453. PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr,
  454. png_bytep data, png_size_t length));
  455. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  456. PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  457. png_bytep buffer, png_size_t length));
  458. #endif
  459. PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr,
  460. png_bytep data, png_size_t length));
  461. #ifdef PNG_WRITE_FLUSH_SUPPORTED
  462. # ifdef PNG_STDIO_SUPPORTED
  463. PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr));
  464. # endif
  465. #endif
  466. /* Reset the CRC variable */
  467. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  468. /* Write the "data" buffer to whatever output you are using */
  469. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr,
  470. png_const_bytep data, png_size_t length));
  471. /* Read and check the PNG file signature */
  472. PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr));
  473. /* Read the chunk header (length + type name) */
  474. PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr));
  475. /* Read data from whatever input you are using into the "data" buffer */
  476. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  477. png_size_t length));
  478. /* Read bytes into buf, and update png_ptr->crc */
  479. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  480. png_size_t length));
  481. /* Decompress data in a chunk that uses compression */
  482. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  483. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  484. PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr,
  485. int comp_type, png_size_t chunklength, png_size_t prefix_length,
  486. png_size_t *data_length));
  487. #endif
  488. /* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
  489. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  490. /* Read the CRC from the file and compare it to the libpng calculated CRC */
  491. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  492. /* Calculate the CRC over a section of data. Note that we are only
  493. * passing a maximum of 64K on systems that have this as a memory limit,
  494. * since this is the maximum buffer size we can specify.
  495. */
  496. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr,
  497. png_const_bytep ptr, png_size_t length));
  498. #ifdef PNG_WRITE_FLUSH_SUPPORTED
  499. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  500. #endif
  501. /* Write various chunks */
  502. /* Write the IHDR chunk, and update the png_struct with the necessary
  503. * information.
  504. */
  505. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  506. png_uint_32 height,
  507. int bit_depth, int color_type, int compression_method, int filter_method,
  508. int interlace_method));
  509. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr,
  510. png_const_colorp palette, png_uint_32 num_pal));
  511. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  512. png_size_t length));
  513. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  514. #ifdef PNG_WRITE_gAMA_SUPPORTED
  515. # ifdef PNG_FLOATING_POINT_SUPPORTED
  516. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  517. # endif
  518. # ifdef PNG_FIXED_POINT_SUPPORTED
  519. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr,
  520. png_fixed_point file_gamma));
  521. # endif
  522. #endif
  523. #ifdef PNG_WRITE_sBIT_SUPPORTED
  524. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr,
  525. png_const_color_8p sbit, int color_type));
  526. #endif
  527. #ifdef PNG_WRITE_cHRM_SUPPORTED
  528. # ifdef PNG_FLOATING_POINT_SUPPORTED
  529. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  530. double white_x, double white_y,
  531. double red_x, double red_y, double green_x, double green_y,
  532. double blue_x, double blue_y));
  533. # endif
  534. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  535. png_fixed_point int_white_x, png_fixed_point int_white_y,
  536. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  537. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  538. png_fixed_point int_blue_y));
  539. #endif
  540. #ifdef PNG_WRITE_sRGB_SUPPORTED
  541. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  542. int intent));
  543. #endif
  544. #ifdef PNG_WRITE_iCCP_SUPPORTED
  545. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  546. png_const_charp name, int compression_type,
  547. png_const_charp profile, int proflen));
  548. /* Note to maintainer: profile should be png_bytep */
  549. #endif
  550. #ifdef PNG_WRITE_sPLT_SUPPORTED
  551. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  552. png_const_sPLT_tp palette));
  553. #endif
  554. #ifdef PNG_WRITE_tRNS_SUPPORTED
  555. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr,
  556. png_const_bytep trans, png_const_color_16p values, int number,
  557. int color_type));
  558. #endif
  559. #ifdef PNG_WRITE_bKGD_SUPPORTED
  560. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  561. png_const_color_16p values, int color_type));
  562. #endif
  563. #ifdef PNG_WRITE_hIST_SUPPORTED
  564. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr,
  565. png_const_uint_16p hist, int num_hist));
  566. #endif
  567. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  568. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  569. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  570. png_const_charp key, png_charpp new_key));
  571. #endif
  572. #ifdef PNG_WRITE_tEXt_SUPPORTED
  573. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key,
  574. png_const_charp text, png_size_t text_len));
  575. #endif
  576. #ifdef PNG_WRITE_zTXt_SUPPORTED
  577. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key,
  578. png_const_charp text, png_size_t text_len, int compression));
  579. #endif
  580. #ifdef PNG_WRITE_iTXt_SUPPORTED
  581. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  582. int compression, png_const_charp key, png_const_charp lang,
  583. png_const_charp lang_key, png_const_charp text));
  584. #endif
  585. #ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */
  586. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  587. png_infop info_ptr, png_const_textp text_ptr, int num_text));
  588. #endif
  589. #ifdef PNG_WRITE_oFFs_SUPPORTED
  590. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  591. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  592. #endif
  593. #ifdef PNG_WRITE_pCAL_SUPPORTED
  594. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  595. png_int_32 X0, png_int_32 X1, int type, int nparams,
  596. png_const_charp units, png_charpp params));
  597. #endif
  598. #ifdef PNG_WRITE_pHYs_SUPPORTED
  599. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  600. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  601. int unit_type));
  602. #endif
  603. #ifdef PNG_WRITE_tIME_SUPPORTED
  604. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  605. png_const_timep mod_time));
  606. #endif
  607. #ifdef PNG_WRITE_sCAL_SUPPORTED
  608. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  609. int unit, png_const_charp width, png_const_charp height));
  610. #endif
  611. /* Called when finished processing a row of data */
  612. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  613. /* Internal use only. Called before first row of data */
  614. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  615. /* Combine a row of data, dealing with alpha, etc. if requested */
  616. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  617. int mask));
  618. #ifdef PNG_READ_INTERLACING_SUPPORTED
  619. /* Expand an interlaced row */
  620. /* OLD pre-1.0.9 interface:
  621. PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
  622. png_bytep row, int pass, png_uint_32 transformations));
  623. */
  624. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  625. #endif
  626. /* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */
  627. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  628. /* Grab pixels out of a row for an interlaced pass */
  629. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  630. png_bytep row, int pass));
  631. #endif
  632. /* Unfilter a row */
  633. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  634. png_row_infop row_info, png_bytep row, png_const_bytep prev_row,
  635. int filter));
  636. /* Choose the best filter to use and filter the row data */
  637. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  638. png_row_infop row_info));
  639. /* Write out the filtered row. */
  640. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  641. png_bytep filtered_row));
  642. /* Finish a row while reading, dealing with interlacing passes, etc. */
  643. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  644. /* Initialize the row buffers, etc. */
  645. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  646. /* Optional call to update the users info structure */
  647. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  648. png_infop info_ptr));
  649. /* These are the functions that do the transformations */
  650. #ifdef PNG_READ_FILLER_SUPPORTED
  651. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  652. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  653. #endif
  654. #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
  655. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  656. png_bytep row));
  657. #endif
  658. #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
  659. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  660. png_bytep row));
  661. #endif
  662. #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
  663. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  664. png_bytep row));
  665. #endif
  666. #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
  667. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  668. png_bytep row));
  669. #endif
  670. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  671. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  672. PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info,
  673. png_bytep row, int at_start));
  674. #endif
  675. #ifdef PNG_16BIT_SUPPORTED
  676. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  677. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info,
  678. png_bytep row));
  679. #endif
  680. #endif
  681. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
  682. defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  683. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info,
  684. png_bytep row));
  685. #endif
  686. #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
  687. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr,
  688. png_row_infop row_info, png_bytep row));
  689. #endif
  690. #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
  691. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  692. png_bytep row));
  693. #endif
  694. #ifdef PNG_READ_PACK_SUPPORTED
  695. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info,
  696. png_bytep row));
  697. #endif
  698. #ifdef PNG_READ_SHIFT_SUPPORTED
  699. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info,
  700. png_bytep row, png_const_color_8p sig_bits));
  701. #endif
  702. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  703. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info,
  704. png_bytep row));
  705. #endif
  706. #ifdef PNG_READ_16_TO_8_SUPPORTED
  707. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info,
  708. png_bytep row));
  709. #endif
  710. #ifdef PNG_READ_QUANTIZE_SUPPORTED
  711. PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info,
  712. png_bytep row, png_const_bytep palette_lookup,
  713. png_const_bytep quantize_lookup));
  714. # ifdef PNG_CORRECT_PALETTE_SUPPORTED
  715. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  716. png_colorp palette, int num_palette));
  717. # endif
  718. #endif
  719. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  720. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info,
  721. png_bytep row));
  722. #endif
  723. #ifdef PNG_WRITE_PACK_SUPPORTED
  724. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  725. png_bytep row, png_uint_32 bit_depth));
  726. #endif
  727. #ifdef PNG_WRITE_SHIFT_SUPPORTED
  728. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info,
  729. png_bytep row, png_const_color_8p bit_depth));
  730. #endif
  731. #ifdef PNG_READ_BACKGROUND_SUPPORTED
  732. # ifdef PNG_READ_GAMMA_SUPPORTED
  733. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info,
  734. png_bytep row, png_const_color_16p trans_color,
  735. png_const_color_16p background, png_const_color_16p background_1,
  736. png_const_bytep gamma_table, png_const_bytep gamma_from_1,
  737. png_const_bytep gamma_to_1, png_const_uint_16pp gamma_16,
  738. png_const_uint_16pp gamma_16_from_1, png_const_uint_16pp gamma_16_to_1,
  739. int gamma_shift));
  740. # else
  741. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info,
  742. png_bytep row, png_const_color_16p trans_color,
  743. png_const_color_16p background));
  744. # endif
  745. #endif
  746. #ifdef PNG_READ_GAMMA_SUPPORTED
  747. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info,
  748. png_bytep row, png_const_bytep gamma_table,
  749. png_const_uint_16pp gamma_16_table, int gamma_shift));
  750. #endif
  751. #ifdef PNG_READ_EXPAND_SUPPORTED
  752. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  753. png_bytep row, png_const_colorp palette, png_const_bytep trans,
  754. int num_trans));
  755. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  756. png_bytep row, png_const_color_16p trans_color));
  757. #endif
  758. #ifdef PNG_READ_EXPAND_16_SUPPORTED
  759. PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info,
  760. png_bytep row));
  761. #endif
  762. /* The following decodes the appropriate chunks, and does error correction,
  763. * then calls the appropriate callback for the chunk if it is valid.
  764. */
  765. /* Decode the IHDR chunk */
  766. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  767. png_uint_32 length));
  768. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  769. png_uint_32 length));
  770. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  771. png_uint_32 length));
  772. #ifdef PNG_READ_bKGD_SUPPORTED
  773. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  774. png_uint_32 length));
  775. #endif
  776. #ifdef PNG_READ_cHRM_SUPPORTED
  777. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  778. png_uint_32 length));
  779. #endif
  780. #ifdef PNG_READ_gAMA_SUPPORTED
  781. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  782. png_uint_32 length));
  783. #endif
  784. #ifdef PNG_READ_hIST_SUPPORTED
  785. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  786. png_uint_32 length));
  787. #endif
  788. #ifdef PNG_READ_iCCP_SUPPORTED
  789. PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  790. png_uint_32 length));
  791. #endif /* PNG_READ_iCCP_SUPPORTED */
  792. #ifdef PNG_READ_iTXt_SUPPORTED
  793. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  794. png_uint_32 length));
  795. #endif
  796. #ifdef PNG_READ_oFFs_SUPPORTED
  797. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  798. png_uint_32 length));
  799. #endif
  800. #ifdef PNG_READ_pCAL_SUPPORTED
  801. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  802. png_uint_32 length));
  803. #endif
  804. #ifdef PNG_READ_pHYs_SUPPORTED
  805. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  806. png_uint_32 length));
  807. #endif
  808. #ifdef PNG_READ_sBIT_SUPPORTED
  809. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  810. png_uint_32 length));
  811. #endif
  812. #ifdef PNG_READ_sCAL_SUPPORTED
  813. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  814. png_uint_32 length));
  815. #endif
  816. #ifdef PNG_READ_sPLT_SUPPORTED
  817. PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  818. png_uint_32 length));
  819. #endif /* PNG_READ_sPLT_SUPPORTED */
  820. #ifdef PNG_READ_sRGB_SUPPORTED
  821. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  822. png_uint_32 length));
  823. #endif
  824. #ifdef PNG_READ_tEXt_SUPPORTED
  825. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  826. png_uint_32 length));
  827. #endif
  828. #ifdef PNG_READ_tIME_SUPPORTED
  829. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  830. png_uint_32 length));
  831. #endif
  832. #ifdef PNG_READ_tRNS_SUPPORTED
  833. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  834. png_uint_32 length));
  835. #endif
  836. #ifdef PNG_READ_zTXt_SUPPORTED
  837. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  838. png_uint_32 length));
  839. #endif
  840. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  841. png_infop info_ptr, png_uint_32 length));
  842. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  843. png_const_bytep chunk_name));
  844. /* Handle the transformations for reading and writing */
  845. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  846. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  847. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  848. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  849. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  850. png_infop info_ptr));
  851. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  852. png_infop info_ptr));
  853. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  854. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  855. png_uint_32 length));
  856. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  857. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  858. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  859. png_bytep buffer, png_size_t buffer_length));
  860. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  861. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  862. png_bytep buffer, png_size_t buffer_length));
  863. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  864. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  865. png_infop info_ptr, png_uint_32 length));
  866. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  867. png_infop info_ptr));
  868. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  869. png_infop info_ptr));
  870. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  871. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  872. png_infop info_ptr));
  873. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  874. png_infop info_ptr));
  875. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  876. # ifdef PNG_READ_tEXt_SUPPORTED
  877. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  878. png_infop info_ptr, png_uint_32 length));
  879. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  880. png_infop info_ptr));
  881. # endif
  882. # ifdef PNG_READ_zTXt_SUPPORTED
  883. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  884. png_infop info_ptr, png_uint_32 length));
  885. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  886. png_infop info_ptr));
  887. # endif
  888. # ifdef PNG_READ_iTXt_SUPPORTED
  889. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  890. png_infop info_ptr, png_uint_32 length));
  891. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  892. png_infop info_ptr));
  893. # endif
  894. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  895. #ifdef PNG_MNG_FEATURES_SUPPORTED
  896. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  897. png_bytep row));
  898. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  899. png_bytep row));
  900. #endif
  901. /* Added at libpng version 1.4.0 */
  902. #ifdef PNG_CHECK_cHRM_SUPPORTED
  903. PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr,
  904. png_fixed_point int_white_x, png_fixed_point int_white_y,
  905. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  906. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  907. png_fixed_point int_blue_y));
  908. #endif
  909. #ifdef PNG_CHECK_cHRM_SUPPORTED
  910. /* Added at libpng version 1.2.34 and 1.4.0 */
  911. /* Currently only used by png_check_cHRM_fixed */
  912. PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2,
  913. unsigned long *hi_product, unsigned long *lo_product));
  914. #endif
  915. /* Added at libpng version 1.4.0 */
  916. PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr,
  917. png_uint_32 width, png_uint_32 height, int bit_depth,
  918. int color_type, int interlace_type, int compression_type,
  919. int filter_type));
  920. /* Free all memory used by the read (old method - NOT DLL EXPORTED) */
  921. PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr,
  922. png_infop info_ptr, png_infop end_info_ptr));
  923. /* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
  924. PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr));
  925. #ifdef USE_FAR_KEYWORD /* memory model conversion function */
  926. PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr,
  927. int check));
  928. #endif /* USE_FAR_KEYWORD */
  929. #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
  930. PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr,
  931. png_const_charp name),PNG_NORETURN);
  932. #endif
  933. /* ASCII to FP interfaces, currently only implemented if sCAL
  934. * support is required.
  935. */
  936. #if defined(PNG_READ_sCAL_SUPPORTED)
  937. /* MAX_DIGITS is actually the maximum number of characters in an sCAL
  938. * width or height, derived from the precision (number of significant
  939. * digits - a build time settable option) and assumpitions about the
  940. * maximum ridiculous exponent.
  941. */
  942. #define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)
  943. #ifdef PNG_FLOATING_POINT_SUPPORTED
  944. PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii,
  945. png_size_t size, double fp, unsigned int precision));
  946. #endif /* FLOATING_POINT */
  947. #ifdef PNG_FIXED_POINT_SUPPORTED
  948. PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr,
  949. png_charp ascii, png_size_t size, png_fixed_point fp));
  950. #endif /* FIXED_POINT */
  951. #endif /* READ_sCAL */
  952. #if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
  953. /* An internal API to validate the format of a floating point number.
  954. * The result is the index of the next character. If the number is
  955. * not valid it will be the index of a character in the supposed number.
  956. *
  957. * The format of a number is defined in the PNG extensions specification
  958. * and this API is strictly conformant to that spec, not anyone elses!
  959. *
  960. * The format as a regular expression is:
  961. *
  962. * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
  963. *
  964. * or:
  965. *
  966. * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
  967. *
  968. * The complexity is that either integer or fraction must be present and the
  969. * fraction is permitted to have no digits only if the integer is present.
  970. *
  971. * NOTE: The dangling E problem.
  972. * There is a PNG valid floating point number in the following:
  973. *
  974. * PNG floating point numb1.ers are not greedy.
  975. *
  976. * Working this out requires *TWO* character lookahead (because of the
  977. * sign), the parser does not do this - it will fail at the 'r' - this
  978. * doesn't matter for PNG sCAL chunk values, but it requires more care
  979. * if the value were ever to be embedded in something more complex. Use
  980. * ANSI-C strtod if you need the lookahead.
  981. */
  982. /* State table for the parser. */
  983. #define PNG_FP_INTEGER 0 /* before or in integer */
  984. #define PNG_FP_FRACTION 1 /* before or in fraction */
  985. #define PNG_FP_EXPONENT 2 /* before or in exponent */
  986. #define PNG_FP_STATE 3 /* mask for the above */
  987. #define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */
  988. #define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */
  989. #define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */
  990. #define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */
  991. #define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */
  992. #define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */
  993. #define PNG_FP_INVALID 128 /* Available for callers as a distinct value */
  994. /* Result codes for the parser (boolean - true meants ok, false means
  995. * not ok yet.)
  996. */
  997. #define PNG_FP_MAYBE 0 /* The number may be valid in the future */
  998. #define PNG_FP_OK 1 /* The number is valid */
  999. /* The actual parser. This can be called repeatedly, it updates
  1000. * the index into the string and the state variable (which must
  1001. * be initialzed to 0). It returns a result code, as above. There
  1002. * is no point calling the parser any more if it fails to advance to
  1003. * the end of the string - it is stuck on an invalid character (or
  1004. * terminated by '\0').
  1005. *
  1006. * Note that the pointer will consume an E or even an E+ then leave
  1007. * a 'maybe' state even though a preceding integer.fraction is valid.
  1008. * The PNG_FP_WAS_VALID flag indicates that a preceding substring was
  1009. * a valid number. It's possible to recover from this by calling
  1010. * the parser again (from the start, with state 0) but with a string
  1011. * that omits the last character (i.e. set the size to the index of
  1012. * the problem character.) This has not been tested within libpng.
  1013. */
  1014. PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string,
  1015. png_size_t size, int *statep, png_size_tp whereami));
  1016. /* This is the same but it checks a complete string and returns true
  1017. * only if it just contains a floating point number.
  1018. */
  1019. PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string,
  1020. png_size_t size));
  1021. #endif /* pCAL || sCAL */
  1022. #if defined(PNG_READ_GAMMA_SUPPORTED) ||\
  1023. defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
  1024. /* Added at libpng version 1.5.0 */
  1025. /* This is a utility to provide a*times/div (rounded) and indicate
  1026. * if there is an overflow. The result is a boolean - false (0)
  1027. * for overflow, true (1) if no overflow, in which case *res
  1028. * holds the result.
  1029. */
  1030. PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a,
  1031. png_int_32 multiplied_by, png_int_32 divided_by));
  1032. #endif
  1033. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
  1034. /* Same deal, but issue a warning on overflow and return 0. */
  1035. PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr,
  1036. png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by));
  1037. #endif
  1038. #ifdef PNG_READ_GAMMA_SUPPORTED
  1039. /* Calculate a reciprocal - used for gamma values. This returns
  1040. * 0 if the argument is 0 in order to maintain an undefined value,
  1041. * there are no warnings.
  1042. */
  1043. PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a));
  1044. /* The same but gives a reciprocal of the product of two fixed point
  1045. * values. Accuracy is suitable for gamma calculations but this is
  1046. * not exact - use png_muldiv for that.
  1047. */
  1048. PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a,
  1049. png_fixed_point b));
  1050. #endif
  1051. #ifdef PNG_READ_GAMMA_SUPPORTED
  1052. /* Internal fixed point gamma correction. These APIs are called as
  1053. * required to convert single values - they don't need to be fast,
  1054. * they are not used when processing image pixel values.
  1055. *
  1056. * While the input is an 'unsigned' value it must actually be the
  1057. * correct bit value - 0..255 or 0..65535 as required.
  1058. */
  1059. PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr,
  1060. unsigned int value, png_fixed_point gamma_value));
  1061. PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value));
  1062. PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value,
  1063. png_fixed_point gamma_value));
  1064. PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value,
  1065. png_fixed_point gamma_value));
  1066. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
  1067. int bit_depth));
  1068. #endif
  1069. /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
  1070. #include "pngdebug.h"
  1071. #ifdef __cplusplus
  1072. }
  1073. #endif
  1074. #endif /* PNGPRIV_H */