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