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