xref: /aosp_15_r20/external/libpng/pngdebug.h (revision a67afe4df73cf47866eedc69947994b8ff839aba)
1*a67afe4dSAndroid Build Coastguard Worker 
2*a67afe4dSAndroid Build Coastguard Worker /* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
3*a67afe4dSAndroid Build Coastguard Worker  *
4*a67afe4dSAndroid Build Coastguard Worker  * Copyright (c) 2018 Cosmin Truta
5*a67afe4dSAndroid Build Coastguard Worker  * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson
6*a67afe4dSAndroid Build Coastguard Worker  * Copyright (c) 1996-1997 Andreas Dilger
7*a67afe4dSAndroid Build Coastguard Worker  * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
8*a67afe4dSAndroid Build Coastguard Worker  *
9*a67afe4dSAndroid Build Coastguard Worker  * This code is released under the libpng license.
10*a67afe4dSAndroid Build Coastguard Worker  * For conditions of distribution and use, see the disclaimer
11*a67afe4dSAndroid Build Coastguard Worker  * and license in png.h
12*a67afe4dSAndroid Build Coastguard Worker  */
13*a67afe4dSAndroid Build Coastguard Worker 
14*a67afe4dSAndroid Build Coastguard Worker /* Define PNG_DEBUG at compile time for debugging information.  Higher
15*a67afe4dSAndroid Build Coastguard Worker  * numbers for PNG_DEBUG mean more debugging information.  This has
16*a67afe4dSAndroid Build Coastguard Worker  * only been added since version 0.95 so it is not implemented throughout
17*a67afe4dSAndroid Build Coastguard Worker  * libpng yet, but more support will be added as needed.
18*a67afe4dSAndroid Build Coastguard Worker  *
19*a67afe4dSAndroid Build Coastguard Worker  * png_debug[1-2]?(level, message ,arg{0-2})
20*a67afe4dSAndroid Build Coastguard Worker  *   Expands to a statement (either a simple expression or a compound
21*a67afe4dSAndroid Build Coastguard Worker  *   do..while(0) statement) that outputs a message with parameter
22*a67afe4dSAndroid Build Coastguard Worker  *   substitution if PNG_DEBUG is defined to 2 or more.  If PNG_DEBUG
23*a67afe4dSAndroid Build Coastguard Worker  *   is undefined, 0 or 1 every png_debug expands to a simple expression
24*a67afe4dSAndroid Build Coastguard Worker  *   (actually ((void)0)).
25*a67afe4dSAndroid Build Coastguard Worker  *
26*a67afe4dSAndroid Build Coastguard Worker  *   level: level of detail of message, starting at 0.  A level 'n'
27*a67afe4dSAndroid Build Coastguard Worker  *          message is preceded by 'n' 3-space indentations (not implemented
28*a67afe4dSAndroid Build Coastguard Worker  *          on Microsoft compilers unless PNG_DEBUG_FILE is also
29*a67afe4dSAndroid Build Coastguard Worker  *          defined, to allow debug DLL compilation with no standard IO).
30*a67afe4dSAndroid Build Coastguard Worker  *   message: a printf(3) style text string.  A trailing '\n' is added
31*a67afe4dSAndroid Build Coastguard Worker  *            to the message.
32*a67afe4dSAndroid Build Coastguard Worker  *   arg: 0 to 2 arguments for printf(3) style substitution in message.
33*a67afe4dSAndroid Build Coastguard Worker  */
34*a67afe4dSAndroid Build Coastguard Worker #ifndef PNGDEBUG_H
35*a67afe4dSAndroid Build Coastguard Worker #define PNGDEBUG_H
36*a67afe4dSAndroid Build Coastguard Worker /* These settings control the formatting of messages in png.c and pngerror.c */
37*a67afe4dSAndroid Build Coastguard Worker /* Moved to pngdebug.h at 1.5.0 */
38*a67afe4dSAndroid Build Coastguard Worker #  ifndef PNG_LITERAL_SHARP
39*a67afe4dSAndroid Build Coastguard Worker #    define PNG_LITERAL_SHARP 0x23
40*a67afe4dSAndroid Build Coastguard Worker #  endif
41*a67afe4dSAndroid Build Coastguard Worker #  ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
42*a67afe4dSAndroid Build Coastguard Worker #    define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
43*a67afe4dSAndroid Build Coastguard Worker #  endif
44*a67afe4dSAndroid Build Coastguard Worker #  ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET
45*a67afe4dSAndroid Build Coastguard Worker #    define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
46*a67afe4dSAndroid Build Coastguard Worker #  endif
47*a67afe4dSAndroid Build Coastguard Worker #  ifndef PNG_STRING_NEWLINE
48*a67afe4dSAndroid Build Coastguard Worker #    define PNG_STRING_NEWLINE "\n"
49*a67afe4dSAndroid Build Coastguard Worker #  endif
50*a67afe4dSAndroid Build Coastguard Worker 
51*a67afe4dSAndroid Build Coastguard Worker #ifdef PNG_DEBUG
52*a67afe4dSAndroid Build Coastguard Worker #  if (PNG_DEBUG > 0)
53*a67afe4dSAndroid Build Coastguard Worker #    if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
54*a67afe4dSAndroid Build Coastguard Worker #      include <crtdbg.h>
55*a67afe4dSAndroid Build Coastguard Worker #      if (PNG_DEBUG > 1)
56*a67afe4dSAndroid Build Coastguard Worker #        ifndef _DEBUG
57*a67afe4dSAndroid Build Coastguard Worker #          define _DEBUG
58*a67afe4dSAndroid Build Coastguard Worker #        endif
59*a67afe4dSAndroid Build Coastguard Worker #        ifndef png_debug
60*a67afe4dSAndroid Build Coastguard Worker #          define png_debug(l,m)  _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE)
61*a67afe4dSAndroid Build Coastguard Worker #        endif
62*a67afe4dSAndroid Build Coastguard Worker #        ifndef png_debug1
63*a67afe4dSAndroid Build Coastguard Worker #          define png_debug1(l,m,p1)  _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1)
64*a67afe4dSAndroid Build Coastguard Worker #        endif
65*a67afe4dSAndroid Build Coastguard Worker #        ifndef png_debug2
66*a67afe4dSAndroid Build Coastguard Worker #          define png_debug2(l,m,p1,p2) \
67*a67afe4dSAndroid Build Coastguard Worker              _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2)
68*a67afe4dSAndroid Build Coastguard Worker #        endif
69*a67afe4dSAndroid Build Coastguard Worker #      endif
70*a67afe4dSAndroid Build Coastguard Worker #    else /* PNG_DEBUG_FILE || !_MSC_VER */
71*a67afe4dSAndroid Build Coastguard Worker #      ifndef PNG_STDIO_SUPPORTED
72*a67afe4dSAndroid Build Coastguard Worker #        include <stdio.h> /* not included yet */
73*a67afe4dSAndroid Build Coastguard Worker #      endif
74*a67afe4dSAndroid Build Coastguard Worker #      ifndef PNG_DEBUG_FILE
75*a67afe4dSAndroid Build Coastguard Worker #        define PNG_DEBUG_FILE stderr
76*a67afe4dSAndroid Build Coastguard Worker #      endif /* PNG_DEBUG_FILE */
77*a67afe4dSAndroid Build Coastguard Worker 
78*a67afe4dSAndroid Build Coastguard Worker #      if (PNG_DEBUG > 1)
79*a67afe4dSAndroid Build Coastguard Worker #        ifdef __STDC__
80*a67afe4dSAndroid Build Coastguard Worker #          ifndef png_debug
81*a67afe4dSAndroid Build Coastguard Worker #            define png_debug(l,m) \
82*a67afe4dSAndroid Build Coastguard Worker        do { \
83*a67afe4dSAndroid Build Coastguard Worker        int num_tabs=l; \
84*a67afe4dSAndroid Build Coastguard Worker        fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? "   " : \
85*a67afe4dSAndroid Build Coastguard Worker          (num_tabs==2 ? "      " : (num_tabs>2 ? "         " : "")))); \
86*a67afe4dSAndroid Build Coastguard Worker        } while (0)
87*a67afe4dSAndroid Build Coastguard Worker #          endif
88*a67afe4dSAndroid Build Coastguard Worker #          ifndef png_debug1
89*a67afe4dSAndroid Build Coastguard Worker #            define png_debug1(l,m,p1) \
90*a67afe4dSAndroid Build Coastguard Worker        do { \
91*a67afe4dSAndroid Build Coastguard Worker        int num_tabs=l; \
92*a67afe4dSAndroid Build Coastguard Worker        fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? "   " : \
93*a67afe4dSAndroid Build Coastguard Worker          (num_tabs==2 ? "      " : (num_tabs>2 ? "         " : ""))),p1); \
94*a67afe4dSAndroid Build Coastguard Worker        } while (0)
95*a67afe4dSAndroid Build Coastguard Worker #          endif
96*a67afe4dSAndroid Build Coastguard Worker #          ifndef png_debug2
97*a67afe4dSAndroid Build Coastguard Worker #            define png_debug2(l,m,p1,p2) \
98*a67afe4dSAndroid Build Coastguard Worker        do { \
99*a67afe4dSAndroid Build Coastguard Worker        int num_tabs=l; \
100*a67afe4dSAndroid Build Coastguard Worker        fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? "   " : \
101*a67afe4dSAndroid Build Coastguard Worker          (num_tabs==2 ? "      " : (num_tabs>2 ? "         " : ""))),p1,p2);\
102*a67afe4dSAndroid Build Coastguard Worker        } while (0)
103*a67afe4dSAndroid Build Coastguard Worker #          endif
104*a67afe4dSAndroid Build Coastguard Worker #        else /* __STDC __ */
105*a67afe4dSAndroid Build Coastguard Worker #          ifndef png_debug
106*a67afe4dSAndroid Build Coastguard Worker #            define png_debug(l,m) \
107*a67afe4dSAndroid Build Coastguard Worker        do { \
108*a67afe4dSAndroid Build Coastguard Worker        int num_tabs=l; \
109*a67afe4dSAndroid Build Coastguard Worker        char format[256]; \
110*a67afe4dSAndroid Build Coastguard Worker        snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
111*a67afe4dSAndroid Build Coastguard Worker          (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
112*a67afe4dSAndroid Build Coastguard Worker          m,PNG_STRING_NEWLINE); \
113*a67afe4dSAndroid Build Coastguard Worker        fprintf(PNG_DEBUG_FILE,format); \
114*a67afe4dSAndroid Build Coastguard Worker        } while (0)
115*a67afe4dSAndroid Build Coastguard Worker #          endif
116*a67afe4dSAndroid Build Coastguard Worker #          ifndef png_debug1
117*a67afe4dSAndroid Build Coastguard Worker #            define png_debug1(l,m,p1) \
118*a67afe4dSAndroid Build Coastguard Worker        do { \
119*a67afe4dSAndroid Build Coastguard Worker        int num_tabs=l; \
120*a67afe4dSAndroid Build Coastguard Worker        char format[256]; \
121*a67afe4dSAndroid Build Coastguard Worker        snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
122*a67afe4dSAndroid Build Coastguard Worker          (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
123*a67afe4dSAndroid Build Coastguard Worker          m,PNG_STRING_NEWLINE); \
124*a67afe4dSAndroid Build Coastguard Worker        fprintf(PNG_DEBUG_FILE,format,p1); \
125*a67afe4dSAndroid Build Coastguard Worker        } while (0)
126*a67afe4dSAndroid Build Coastguard Worker #          endif
127*a67afe4dSAndroid Build Coastguard Worker #          ifndef png_debug2
128*a67afe4dSAndroid Build Coastguard Worker #            define png_debug2(l,m,p1,p2) \
129*a67afe4dSAndroid Build Coastguard Worker        do { \
130*a67afe4dSAndroid Build Coastguard Worker        int num_tabs=l; \
131*a67afe4dSAndroid Build Coastguard Worker        char format[256]; \
132*a67afe4dSAndroid Build Coastguard Worker        snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
133*a67afe4dSAndroid Build Coastguard Worker          (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
134*a67afe4dSAndroid Build Coastguard Worker          m,PNG_STRING_NEWLINE); \
135*a67afe4dSAndroid Build Coastguard Worker        fprintf(PNG_DEBUG_FILE,format,p1,p2); \
136*a67afe4dSAndroid Build Coastguard Worker        } while (0)
137*a67afe4dSAndroid Build Coastguard Worker #          endif
138*a67afe4dSAndroid Build Coastguard Worker #        endif /* __STDC __ */
139*a67afe4dSAndroid Build Coastguard Worker #      endif /* (PNG_DEBUG > 1) */
140*a67afe4dSAndroid Build Coastguard Worker 
141*a67afe4dSAndroid Build Coastguard Worker #    endif /* _MSC_VER */
142*a67afe4dSAndroid Build Coastguard Worker #  endif /* (PNG_DEBUG > 0) */
143*a67afe4dSAndroid Build Coastguard Worker #endif /* PNG_DEBUG */
144*a67afe4dSAndroid Build Coastguard Worker #ifndef png_debug
145*a67afe4dSAndroid Build Coastguard Worker #  define png_debug(l, m) ((void)0)
146*a67afe4dSAndroid Build Coastguard Worker #endif
147*a67afe4dSAndroid Build Coastguard Worker #ifndef png_debug1
148*a67afe4dSAndroid Build Coastguard Worker #  define png_debug1(l, m, p1) ((void)0)
149*a67afe4dSAndroid Build Coastguard Worker #endif
150*a67afe4dSAndroid Build Coastguard Worker #ifndef png_debug2
151*a67afe4dSAndroid Build Coastguard Worker #  define png_debug2(l, m, p1, p2) ((void)0)
152*a67afe4dSAndroid Build Coastguard Worker #endif
153*a67afe4dSAndroid Build Coastguard Worker #endif /* PNGDEBUG_H */
154