1/* pngconf.h - machine-configurable file for libpng
2 *
3 * libpng version 1.6.52
4 *
5 * Copyright (c) 2018-2025 Cosmin Truta
6 * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
7 * Copyright (c) 1996-1997 Andreas Dilger
8 * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
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 * Any machine specific code is near the front of this file, so if you
15 * are configuring libpng for a machine, you may want to read the section
16 * starting here down to where it starts to typedef png_color, png_text,
17 * and png_info.
18 */
19
20#ifndef PNGCONF_H
21#define PNGCONF_H
22
23#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */
24
25/* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C
26 * compiler for correct compilation. The following header files are required by
27 * the standard. If your compiler doesn't provide these header files, or they
28 * do not match the standard, you will need to provide/improve them.
29 */
30#include <limits.h>
31#include <stddef.h>
32
33/* Library header files. These header files are all defined by ISOC90; libpng
34 * expects conformant implementations, however, an ISOC90 conformant system need
35 * not provide these header files if the functionality cannot be implemented.
36 * In this case it will be necessary to disable the relevant parts of libpng in
37 * the build of pnglibconf.h.
38 *
39 * Prior to 1.6.0 string.h was included here; the API changes in 1.6.0 to not
40 * include this unnecessary header file.
41 */
42
43#ifdef PNG_STDIO_SUPPORTED
44 /* Required for the definition of FILE: */
45# include <stdio.h>
46#endif
47
48#ifdef PNG_SETJMP_SUPPORTED
49 /* Required for the definition of jmp_buf and the declaration of longjmp: */
50# include <setjmp.h>
51#endif
52
53#ifdef PNG_CONVERT_tIME_SUPPORTED
54 /* Required for struct tm: */
55# include <time.h>
56#endif
57
58#endif /* PNG_BUILDING_SYMBOL_TABLE */
59
60/* Prior to 1.6.0, it was possible to turn off 'const' in declarations,
61 * using PNG_NO_CONST. This is no longer supported.
62 */
63#define PNG_CONST const /* backward compatibility only */
64
65/* This controls optimization of the reading of 16-bit and 32-bit
66 * values from PNG files. It can be set on a per-app-file basis: it
67 * just changes whether a macro is used when the function is called.
68 * The library builder sets the default; if read functions are not
69 * built into the library the macro implementation is forced on.
70 */
71#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED
72# define PNG_USE_READ_MACROS
73#endif
74#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS)
75# if PNG_DEFAULT_READ_MACROS
76# define PNG_USE_READ_MACROS
77# endif
78#endif
79
80/* COMPILER SPECIFIC OPTIONS.
81 *
82 * These options are provided so that a variety of difficult compilers
83 * can be used. Some are fixed at build time (e.g. PNG_API_RULE
84 * below) but still have compiler specific implementations, others
85 * may be changed on a per-file basis when compiling against libpng.
86 */
87
88/* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect
89 * against legacy (pre ISOC90) compilers that did not understand function
90 * prototypes. [Deprecated.]
91 */
92#ifndef PNGARG
93# define PNGARG(arglist) arglist
94#endif
95
96/* Function calling conventions.
97 * =============================
98 * Normally it is not necessary to specify to the compiler how to call
99 * a function - it just does it - however on x86 systems derived from
100 * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems
101 * and some others) there are multiple ways to call a function and the
102 * default can be changed on the compiler command line. For this reason
103 * libpng specifies the calling convention of every exported function and
104 * every function called via a user supplied function pointer. This is
105 * done in this file by defining the following macros:
106 *
107 * PNGAPI Calling convention for exported functions.
108 * PNGCBAPI Calling convention for user provided (callback) functions.
109 * PNGCAPI Calling convention used by the ANSI-C library (required
110 * for longjmp callbacks and sometimes used internally to
111 * specify the calling convention for zlib).
112 *
113 * These macros should never be overridden. If it is necessary to
114 * change calling convention in a private build this can be done
115 * by setting PNG_API_RULE (which defaults to 0) to one of the values
116 * below to select the correct 'API' variants.
117 *
118 * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout.
119 * This is correct in every known environment.
120 * PNG_API_RULE=1 Use the operating system convention for PNGAPI and
121 * the 'C' calling convention (from PNGCAPI) for
122 * callbacks (PNGCBAPI). This is no longer required
123 * in any known environment - if it has to be used
124 * please post an explanation of the problem to the
125 * libpng mailing list.
126 *
127 * These cases only differ if the operating system does not use the C
128 * calling convention, at present this just means the above cases
129 * (x86 DOS/Windows systems) and, even then, this does not apply to
130 * Cygwin running on those systems.
131 *
132 * Note that the value must be defined in pnglibconf.h so that what
133 * the application uses to call the library matches the conventions
134 * set when building the library.
135 */
136
137/* Symbol export
138 * =============
139 * When building a shared library it is almost always necessary to tell
140 * the compiler which symbols to export. The png.h macro 'PNG_EXPORT'
141 * is used to mark the symbols. On some systems these symbols can be
142 * extracted at link time and need no special processing by the compiler,
143 * on other systems the symbols are flagged by the compiler and just
144 * the declaration requires a special tag applied (unfortunately) in a
145 * compiler dependent way. Some systems can do either.
146 *
147 * A small number of older systems also require a symbol from a DLL to
148 * be flagged to the program that calls it. This is a problem because
149 * we do not know in the header file included by application code that
150 * the symbol will come from a shared library, as opposed to a statically
151 * linked one. For this reason the application must tell us by setting
152 * the magic flag PNG_USE_DLL to turn on the special processing before
153 * it includes png.h.
154 *
155 * Four additional macros are used to make this happen:
156 *
157 * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from
158 * the build or imported if PNG_USE_DLL is set - compiler
159 * and system specific.
160 *
161 * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to
162 * 'type', compiler specific.
163 *
164 * PNG_DLL_EXPORT Set to the magic to use during a libpng build to
165 * make a symbol exported from the DLL. Not used in the
166 * public header files; see pngpriv.h for how it is used
167 * in the libpng build.
168 *
169 * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come
170 * from a DLL - used to define PNG_IMPEXP when
171 * PNG_USE_DLL is set.
172 */
173
174/* System specific discovery.
175 * ==========================
176 * This code is used at build time to find PNG_IMPEXP, the API settings
177 * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL
178 * import processing is possible. On Windows systems it also sets
179 * compiler-specific macros to the values required to change the calling
180 * conventions of the various functions.
181 */
182#if defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || \
183 defined(__CYGWIN__)
184 /* Windows system (DOS doesn't support DLLs). Includes builds under Cygwin or
185 * MinGW on any architecture currently supported by Windows. Also includes
186 * Watcom builds but these need special treatment because they are not
187 * compatible with GCC or Visual C because of different calling conventions.
188 */
189# if PNG_API_RULE == 2
190 /* If this line results in an error, either because __watcall is not
191 * understood or because of a redefine just below you cannot use *this*
192 * build of the library with the compiler you are using. *This* build was
193 * build using Watcom and applications must also be built using Watcom!
194 */
195# define PNGCAPI __watcall
196# endif
197
198# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
199# define PNGCAPI __cdecl
200# if PNG_API_RULE == 1
201 /* If this line results in an error __stdcall is not understood and
202 * PNG_API_RULE should not have been set to '1'.
203 */
204# define PNGAPI __stdcall
205# endif
206# else
207 /* An older compiler, or one not detected (erroneously) above,
208 * if necessary override on the command line to get the correct
209 * variants for the compiler.
210 */
211# ifndef PNGCAPI
212# define PNGCAPI _cdecl
213# endif
214# if PNG_API_RULE == 1 && !defined(PNGAPI)
215# define PNGAPI _stdcall
216# endif
217# endif /* compiler/api */
218
219 /* NOTE: PNGCBAPI always defaults to PNGCAPI. */
220
221# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD)
222# error PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed
223# endif
224
225# define PNG_DLL_EXPORT __declspec(dllexport)
226# ifndef PNG_DLL_IMPORT
227# define PNG_DLL_IMPORT __declspec(dllimport)
228# endif
229
230#else /* !Windows */
231# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
232# define PNGAPI _System
233# else /* !Windows/x86 && !OS/2 */
234 /* Use the defaults, or define PNG*API on the command line (but
235 * this will have to be done for every compile!)
236 */
237# endif /* other system, !OS/2 */
238#endif /* !Windows/x86 */
239
240/* Now do all the defaulting . */
241#ifndef PNGCAPI
242# define PNGCAPI
243#endif
244#ifndef PNGCBAPI
245# define PNGCBAPI PNGCAPI
246#endif
247#ifndef PNGAPI
248# define PNGAPI PNGCAPI
249#endif
250
251/* PNG_IMPEXP may be set on the compilation system command line or (if not set)
252 * then in an internal header file when building the library, otherwise (when
253 * using the library) it is set here.
254 */
255#ifndef PNG_IMPEXP
256# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
257 /* This forces use of a DLL, disallowing static linking */
258# define PNG_IMPEXP PNG_DLL_IMPORT
259# endif
260
261# ifndef PNG_IMPEXP
262# define PNG_IMPEXP
263# endif
264#endif
265
266/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat
267 * 'attributes' as a storage class - the attributes go at the start of the
268 * function definition, and attributes are always appended regardless of the
269 * compiler. This considerably simplifies these macros but may cause problems
270 * if any compilers both need function attributes and fail to handle them as
271 * a storage class (this is unlikely.)
272 */
273#ifndef PNG_FUNCTION
274# define PNG_FUNCTION(type, name, args, attributes) attributes type name args
275#endif
276
277#ifndef PNG_EXPORT_TYPE
278# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type
279#endif
280
281 /* The ordinal value is only relevant when preprocessing png.h for symbol
282 * table entries, so we discard it here. See the .dfn files in the
283 * scripts directory.
284 */
285
286#ifndef PNG_EXPORTA
287# define PNG_EXPORTA(ordinal, type, name, args, attributes) \
288 PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), args, \
289 PNG_LINKAGE_API attributes)
290#endif
291
292/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
293 * so make something non-empty to satisfy the requirement:
294 */
295#define PNG_EMPTY /*empty list*/
296
297#define PNG_EXPORT(ordinal, type, name, args) \
298 PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
299
300/* Use PNG_REMOVED to comment out a removed interface. */
301#ifndef PNG_REMOVED
302# define PNG_REMOVED(ordinal, type, name, args, attributes)
303#endif
304
305#ifndef PNG_CALLBACK
306# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) args
307#endif
308
309/* Support for compiler specific function attributes. These are used
310 * so that where compiler support is available incorrect use of API
311 * functions in png.h will generate compiler warnings.
312 *
313 * Added at libpng-1.2.41.
314 */
315
316#ifndef PNG_NO_PEDANTIC_WARNINGS
317# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED
318# define PNG_PEDANTIC_WARNINGS_SUPPORTED
319# endif
320#endif
321
322#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED
323 /* Support for compiler specific function attributes. These are used
324 * so that where compiler support is available, incorrect use of API
325 * functions in png.h will generate compiler warnings. Added at libpng
326 * version 1.2.41. Disabling these removes the warnings but may also produce
327 * less efficient code.
328 */
329# if defined(__clang__) && defined(__has_attribute)
330 /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
331# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
332# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
333# endif
334# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__)
335# define PNG_NORETURN __attribute__((__noreturn__))
336# endif
337# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__)
338# define PNG_ALLOCATED __attribute__((__malloc__))
339# endif
340# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__)
341# define PNG_DEPRECATED __attribute__((__deprecated__))
342# endif
343# if !defined(PNG_PRIVATE)
344# ifdef __has_extension
345# if __has_extension(attribute_unavailable_with_message)
346# define PNG_PRIVATE __attribute__((__unavailable__(\
347 "This function is not exported by libpng.")))
348# endif
349# endif
350# endif
351# ifndef PNG_RESTRICT
352# define PNG_RESTRICT __restrict
353# endif
354
355# elif defined(__GNUC__)
356# ifndef PNG_USE_RESULT
357# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
358# endif
359# ifndef PNG_NORETURN
360# define PNG_NORETURN __attribute__((__noreturn__))
361# endif
362# if __GNUC__ >= 3
363# ifndef PNG_ALLOCATED
364# define PNG_ALLOCATED __attribute__((__malloc__))
365# endif
366# ifndef PNG_DEPRECATED
367# define PNG_DEPRECATED __attribute__((__deprecated__))
368# endif
369# ifndef PNG_PRIVATE
370# if 0 /* Doesn't work so we use deprecated instead*/
371# define PNG_PRIVATE \
372 __attribute__((warning("This function is not exported by libpng.")))
373# else
374# define PNG_PRIVATE \
375 __attribute__((__deprecated__))
376# endif
377# endif
378# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
379# ifndef PNG_RESTRICT
380# define PNG_RESTRICT __restrict
381# endif
382# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */
383# endif /* __GNUC__ >= 3 */
384
385# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
386# ifndef PNG_USE_RESULT
387# define PNG_USE_RESULT /* not supported */
388# endif
389# ifndef PNG_NORETURN
390# define PNG_NORETURN __declspec(noreturn)
391# endif
392# ifndef PNG_ALLOCATED
393# if (_MSC_VER >= 1400)
394# define PNG_ALLOCATED __declspec(restrict)
395# endif
396# endif
397# ifndef PNG_DEPRECATED
398# define PNG_DEPRECATED __declspec(deprecated)
399# endif
400# ifndef PNG_PRIVATE
401# define PNG_PRIVATE __declspec(deprecated)
402# endif
403# ifndef PNG_RESTRICT
404# if (_MSC_VER >= 1400)
405# define PNG_RESTRICT __restrict
406# endif
407# endif
408
409# elif defined(__WATCOMC__)
410# ifndef PNG_RESTRICT
411# define PNG_RESTRICT __restrict
412# endif
413# endif
414#endif /* PNG_PEDANTIC_WARNINGS */
415
416#ifndef PNG_DEPRECATED
417# define PNG_DEPRECATED /* Use of this function is deprecated */
418#endif
419#ifndef PNG_USE_RESULT
420# define PNG_USE_RESULT /* The result of this function must be checked */
421#endif
422#ifndef PNG_NORETURN
423# define PNG_NORETURN /* This function does not return */
424#endif
425#ifndef PNG_ALLOCATED
426# define PNG_ALLOCATED /* The result of the function is new memory */
427#endif
428#ifndef PNG_PRIVATE
429# define PNG_PRIVATE /* This is a private libpng function */
430#endif
431#ifndef PNG_RESTRICT
432# define PNG_RESTRICT /* The C99 "restrict" feature */
433#endif
434
435#ifndef PNG_FP_EXPORT /* A floating point API. */
436# ifdef PNG_FLOATING_POINT_SUPPORTED
437# define PNG_FP_EXPORT(ordinal, type, name, args)\
438 PNG_EXPORT(ordinal, type, name, args);
439# else /* No floating point APIs */
440# define PNG_FP_EXPORT(ordinal, type, name, args)
441# endif
442#endif
443#ifndef PNG_FIXED_EXPORT /* A fixed point API. */
444# ifdef PNG_FIXED_POINT_SUPPORTED
445# define PNG_FIXED_EXPORT(ordinal, type, name, args)\
446 PNG_EXPORT(ordinal, type, name, args);
447# else /* No fixed point APIs */
448# define PNG_FIXED_EXPORT(ordinal, type, name, args)
449# endif
450#endif
451
452#ifndef PNG_BUILDING_SYMBOL_TABLE
453/* Some typedefs to get us started. These should be safe on most of the common
454 * platforms.
455 *
456 * png_uint_32 and png_int_32 may, currently, be larger than required to hold a
457 * 32-bit value however this is not normally advisable.
458 *
459 * png_uint_16 and png_int_16 should always be two bytes in size - this is
460 * verified at library build time.
461 *
462 * png_byte must always be one byte in size.
463 *
464 * The checks below use constants from limits.h, as defined by the ISOC90
465 * standard.
466 */
467#if CHAR_BIT == 8 && UCHAR_MAX == 255
468 typedef unsigned char png_byte;
469#else
470# error libpng requires 8-bit bytes
471#endif
472
473#if INT_MIN == -32768 && INT_MAX == 32767
474 typedef int png_int_16;
475#elif SHRT_MIN == -32768 && SHRT_MAX == 32767
476 typedef short png_int_16;
477#else
478# error libpng requires a signed 16-bit integer type
479#endif
480
481#if UINT_MAX == 65535
482 typedef unsigned int png_uint_16;
483#elif USHRT_MAX == 65535
484 typedef unsigned short png_uint_16;
485#else
486# error libpng requires an unsigned 16-bit integer type
487#endif
488
489#if INT_MIN < -2147483646 && INT_MAX > 2147483646
490 typedef int png_int_32;
491#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646
492 typedef long int png_int_32;
493#else
494# error libpng requires a signed 32-bit (or longer) integer type
495#endif
496
497#if UINT_MAX > 4294967294U
498 typedef unsigned int png_uint_32;
499#elif ULONG_MAX > 4294967294U
500 typedef unsigned long int png_uint_32;
501#else
502# error libpng requires an unsigned 32-bit (or longer) integer type
503#endif
504
505/* Prior to 1.6.0, it was possible to disable the use of size_t and ptrdiff_t.
506 * From 1.6.0 onwards, an ISO C90 compiler, as well as a standard-compliant
507 * behavior of sizeof and ptrdiff_t are required.
508 * The legacy typedefs are provided here for backwards compatibility.
509 */
510typedef size_t png_size_t;
511typedef ptrdiff_t png_ptrdiff_t;
512
513/* libpng needs to know the maximum value of 'size_t' and this controls the
514 * definition of png_alloc_size_t, below. This maximum value of size_t limits
515 * but does not control the maximum allocations the library makes - there is
516 * direct application control of this through png_set_user_limits().
517 */
518#ifndef PNG_SMALL_SIZE_T
519 /* Compiler specific tests for systems where size_t is known to be less than
520 * 32 bits (some of these systems may no longer work because of the lack of
521 * 'far' support; see above.)
522 */
523# if (defined(__TURBOC__) && !defined(__FLAT__)) ||\
524 (defined(_MSC_VER) && defined(MAXSEG_64K))
525# define PNG_SMALL_SIZE_T
526# endif
527#endif
528
529/* png_alloc_size_t is guaranteed to be no smaller than size_t, and no smaller
530 * than png_uint_32. Casts from size_t or png_uint_32 to png_alloc_size_t are
531 * not necessary; in fact, it is recommended not to use them at all, so that
532 * the compiler can complain when something turns out to be problematic.
533 *
534 * Casts in the other direction (from png_alloc_size_t to size_t or
535 * png_uint_32) should be explicitly applied; however, we do not expect to
536 * encounter practical situations that require such conversions.
537 *
538 * PNG_SMALL_SIZE_T must be defined if the maximum value of size_t is less than
539 * 4294967295 - i.e. less than the maximum value of png_uint_32.
540 */
541#ifdef PNG_SMALL_SIZE_T
542 typedef png_uint_32 png_alloc_size_t;
543#else
544 typedef size_t png_alloc_size_t;
545#endif
546
547/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler
548 * implementations of Intel CPU specific support of user-mode segmented address
549 * spaces, where 16-bit pointers address more than 65536 bytes of memory using
550 * separate 'segment' registers. The implementation requires two different
551 * types of pointer (only one of which includes the segment value.)
552 *
553 * If required this support is available in version 1.2 of libpng and may be
554 * available in versions through 1.5, although the correctness of the code has
555 * not been verified recently.
556 */
557
558/* Typedef for floating-point numbers that are converted to fixed-point with a
559 * multiple of 100,000, e.g., gamma
560 */
561typedef png_int_32 png_fixed_point;
562
563/* Add typedefs for pointers */
564typedef void * png_voidp;
565typedef const void * png_const_voidp;
566typedef png_byte * png_bytep;
567typedef const png_byte * png_const_bytep;
568typedef png_uint_32 * png_uint_32p;
569typedef const png_uint_32 * png_const_uint_32p;
570typedef png_int_32 * png_int_32p;
571typedef const png_int_32 * png_const_int_32p;
572typedef png_uint_16 * png_uint_16p;
573typedef const png_uint_16 * png_const_uint_16p;
574typedef png_int_16 * png_int_16p;
575typedef const png_int_16 * png_const_int_16p;
576typedef char * png_charp;
577typedef const char * png_const_charp;
578typedef png_fixed_point * png_fixed_point_p;
579typedef const png_fixed_point * png_const_fixed_point_p;
580typedef size_t * png_size_tp;
581typedef const size_t * png_const_size_tp;
582
583#ifdef PNG_FLOATING_POINT_SUPPORTED
584typedef double * png_doublep;
585typedef const double * png_const_doublep;
586#endif
587
588/* Pointers to pointers; i.e. arrays */
589typedef png_byte * * png_bytepp;
590typedef png_uint_32 * * png_uint_32pp;
591typedef png_int_32 * * png_int_32pp;
592typedef png_uint_16 * * png_uint_16pp;
593typedef png_int_16 * * png_int_16pp;
594typedef const char * * png_const_charpp;
595typedef char * * png_charpp;
596typedef png_fixed_point * * png_fixed_point_pp;
597#ifdef PNG_FLOATING_POINT_SUPPORTED
598typedef double * * png_doublepp;
599#endif
600
601/* Pointers to pointers to pointers; i.e., pointer to array */
602typedef char * * * png_charppp;
603
604#ifdef PNG_STDIO_SUPPORTED
605/* With PNG_STDIO_SUPPORTED it was possible to use I/O streams that were
606 * not necessarily stdio FILE streams, to allow building Windows applications
607 * before Win32 and Windows CE applications before WinCE 3.0, but that kind
608 * of support has long been discontinued.
609 */
610typedef FILE * png_FILE_p; /* [Deprecated] */
611#endif
612
613#endif /* PNG_BUILDING_SYMBOL_TABLE */
614
615#endif /* PNGCONF_H */
616