Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/Libpng/pngpriv.h

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

Archive Download this file

Revision: 2154