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