• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*====================================================================*
2  -  Copyright (C) 2001 Leptonica.  All rights reserved.
3  -  This software is distributed in the hope that it will be
4  -  useful, but with NO WARRANTY OF ANY KIND.
5  -  No author or distributor accepts responsibility to anyone for the
6  -  consequences of using this software, or for whether it serves any
7  -  particular purpose or works at all, unless he or she says so in
8  -  writing.  Everyone is granted permission to copy, modify and
9  -  redistribute this source code, for commercial or non-commercial
10  -  purposes, with the following restrictions: (1) the origin of this
11  -  source code must not be misrepresented; (2) modified versions must
12  -  be plainly marked as such; and (3) this notice may not be removed
13  -  or altered from any source or modified source distribution.
14  *====================================================================*/
15 
16 #ifndef  LEPTONICA_ENVIRON_H
17 #define  LEPTONICA_ENVIRON_H
18 
19 #if defined(WIN32) || defined(WIN64)
20 /* WINDOWS_SPECIFICS */
21 /* Provide intptr_t from the non-existent stdint.h. */
22 #if defined(WIN32)
23 typedef int intptr_t;
24 typedef unsigned int uintptr_t;
25 #else
26 typedef long int intptr_t;
27 typedef unsigned long int uintptr_t;
28 #endif
29 
30 /* VC++6 doesn't seem to have powf, expf. */
31 #if (_MSC_VER <= 1400)
32 #define powf(x, y) (float)pow((double)(x), (double)(y))
33 #define expf(x) (float)exp((double)(x))
34 #endif
35 
36 /* DLL EXPORT/IMPORT */
37 #ifdef LEPTONLIB_EXPORTS
38 #define LEPT_DLL __declspec(dllexport)
39 #elif defined(LEPTONLIB_IMPORTS)
40 #define LEPT_DLL __declspec(dllimport)
41 #else
42 #define LEPT_DLL
43 #endif
44 #else  /* non-WINDOWS-SPECIFICS */
45 #include <stdint.h>
46 #define LEPT_DLL
47 #endif
48 
49 typedef intptr_t l_intptr_t;
50 typedef uintptr_t l_uintptr_t;
51 
52 
53 /*--------------------------------------------------------------------*
54  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
55  *                          USER CONFIGURABLE                         *
56  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
57  *                 Environ variables with I/O libraries               *
58  *               Manual Configuration Only: NOT AUTO_CONF             *
59  *--------------------------------------------------------------------*/
60 /*
61  *  Leptonica provides interfaces to link to four external image I/O
62  *  libraries, plus zlib.  Setting any of these to 0 causes
63  *  non-functioning stubs to be linked.
64  */
65 #ifndef HAVE_CONFIG_H
66 #define  HAVE_LIBJPEG     1
67 #define  HAVE_LIBTIFF     0
68 #define  HAVE_LIBPNG      0
69 #define  HAVE_LIBZ        0
70 #define  HAVE_LIBGIF      0
71 #define  HAVE_LIBUNGIF    0
72 #endif  /* ~HAVE_CONFIG_H */
73 
74 /*
75  * On linux systems, you can do I/O between Pix and memory.  Specifically,
76  * you can compress (write compressed data to memory from a Pix) and
77  * uncompress (read from compressed data in memory to a Pix).
78  * For all but TIFF and PS, these use the non-posix GNU functions
79  * fmemopen() and open_memstream().  These functions are not
80  * available on other systems.  To use these functions in linux,
81  * you must define HAVE_FMEMOPEN to be 1 here.
82  */
83 #ifndef HAVE_CONFIG_H
84 #define  HAVE_FMEMOPEN    1
85 #endif  /* ~HAVE_CONFIG_H */
86 
87 
88 /*--------------------------------------------------------------------*
89  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
90  *                          USER CONFIGURABLE                         *
91  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*
92  *       Environ variables for uncompressed formatted image I/O       *
93  *--------------------------------------------------------------------*/
94 /*
95  *  Leptonica supplies image I/O for pnm, bmp and ps.
96  *  Setting any of these to 0 causes non-functioning stubs to be linked.
97  */
98 #define  USE_BMPIO        1
99 #define  USE_PNMIO        1
100 #define  USE_PSIO         1
101 
102 
103 /*--------------------------------------------------------------------*
104  *                          Built-in types                            *
105  *--------------------------------------------------------------------*/
106 typedef signed char             l_int8;
107 typedef unsigned char           l_uint8;
108 typedef short                   l_int16;
109 typedef unsigned short          l_uint16;
110 typedef int                     l_int32;
111 typedef unsigned int            l_uint32;
112 typedef float                   l_float32;
113 typedef double                  l_float64;
114 
115 
116 /*------------------------------------------------------------------------*
117  *                            Standard macros                             *
118  *------------------------------------------------------------------------*/
119 #ifndef L_MIN
120 #define L_MIN(x,y)   (((x) < (y)) ? (x) : (y))
121 #endif
122 
123 #ifndef L_MAX
124 #define L_MAX(x,y)   (((x) > (y)) ? (x) : (y))
125 #endif
126 
127 #ifndef L_ABS
128 #define L_ABS(x)     (((x) < 0) ? (-1 * (x)) : (x))
129 #endif
130 
131 #ifndef L_SIGN
132 #define L_SIGN(x)    (((x) < 0) ? -1 : 1)
133 #endif
134 
135 #ifndef UNDEF
136 #define UNDEF        -1
137 #endif
138 
139 #ifndef NULL
140 #define NULL          0
141 #endif
142 
143 #ifndef TRUE
144 #define TRUE          1
145 #endif
146 
147 #ifndef FALSE
148 #define FALSE         0
149 #endif
150 
151 
152 /*--------------------------------------------------------------------*
153  *         Environ variables used within compiler invocation          *
154  *--------------------------------------------------------------------*/
155 /*
156  *  To control conditional compilation, one of two variables
157  *
158  *       L_LITTLE_ENDIAN  (e.g., for Intel X86)
159  *       L_BIG_ENDIAN     (e.g., for Sun SPARC, Mac Power PC)
160  *
161  *  is defined when the GCC compiler is invoked.
162  *  All code should compile properly for both hardware architectures.
163  */
164 
165 
166 /*------------------------------------------------------------------------*
167  *                   Simple search state variables                        *
168  *------------------------------------------------------------------------*/
169 enum {
170     L_NOT_FOUND = 0,
171     L_FOUND = 1
172 };
173 
174 
175 /*------------------------------------------------------------------------*
176  *                      Standard memory allocation                        *
177  *
178  *  These specify the memory management functions that are used
179  *  on all heap data except for Pix.  Memory management for Pix
180  *  also defaults to malloc and free.  See pix1.c for details.
181  *------------------------------------------------------------------------*/
182 #define MALLOC(blocksize)           malloc(blocksize)
183 #define CALLOC(numelem, elemsize)   calloc(numelem, elemsize)
184 #define REALLOC(ptr, blocksize)     realloc(ptr, blocksize)
185 #define FREE(ptr)                   free(ptr)
186 
187 
188 /*------------------------------------------------------------------------*
189  *         Control printing of error, warning, and info messages         *
190  *                                                                        *
191  *      (Use -DNO_CONSOLE_IO on compiler line to prevent text output)     *
192  *------------------------------------------------------------------------*/
193 #ifdef  NO_CONSOLE_IO
194 
195 #define PROCNAME(name)
196 #define ERROR_PTR(a,b,c)            ((void *)(c))
197 #define ERROR_INT(a,b,c)            ((l_int32)(c))
198 #define ERROR_FLOAT(a,b,c)          ((l_float32)(c))
199 #define ERROR_VOID(a,b)
200 #define L_ERROR(a,b)
201 #define L_ERROR_STRING(a,b,c)
202 #define L_ERROR_INT(a,b,c)
203 #define L_ERROR_FLOAT(a,b,c)
204 #define L_WARNING(a,b)
205 #define L_WARNING_STRING(a,b,c)
206 #define L_WARNING_INT(a,b,c)
207 #define L_WARNING_FLOAT(a,b,c)
208 #define L_INFO(a,b)
209 #define L_INFO_STRING(a,b,c)
210 #define L_INFO_INT(a,b,c)
211 #define L_INFO_INT2(a,b,c,d)
212 #define L_INFO_FLOAT(a,b,c)
213 #define L_INFO_FLOAT2(a,b,c,d)
214 
215 #else
216 
217 #define PROCNAME(name)              static const char procName[] = name
218 #define ERROR_PTR(a,b,c)            returnErrorPtr((a),(b),(c))
219 #define ERROR_INT(a,b,c)            returnErrorInt((a),(b),(c))
220 #define ERROR_FLOAT(a,b,c)          returnErrorFloat((a),(b),(c))
221 #define ERROR_VOID(a,b)             returnErrorVoid((a),(b))
222 #define L_ERROR(a,b)                l_error((a),(b))
223 #define L_ERROR_STRING(a,b,c)       l_errorString((a),(b),(c))
224 #define L_ERROR_INT(a,b,c)          l_errorInt((a),(b),(c))
225 #define L_ERROR_FLOAT(a,b,c)        l_errorFloat((a),(b),(c))
226 #define L_WARNING(a,b)              l_warning((a),(b))
227 #define L_WARNING_STRING(a,b,c)     l_warningString((a),(b),(c))
228 #define L_WARNING_INT(a,b,c)        l_warningInt((a),(b),(c))
229 #define L_WARNING_FLOAT(a,b,c)      l_warningFloat((a),(b),(c))
230 #define L_INFO(a,b)                 l_info((a),(b))
231 #define L_INFO_STRING(a,b,c)        l_infoString((a),(b),(c))
232 #define L_INFO_INT(a,b,c)           l_infoInt((a),(b),(c))
233 #define L_INFO_INT2(a,b,c,d)        l_infoInt2((a),(b),(c),(d))
234 #define L_INFO_FLOAT(a,b,c)         l_infoFloat((a),(b),(c))
235 #define L_INFO_FLOAT2(a,b,c,d)      l_infoFloat2((a),(b),(c),(d))
236 
237 #endif  /* NO_CONSOLE_IO */
238 
239 
240 /*------------------------------------------------------------------------*
241  *                        snprintf() renamed in MSVC                      *
242  *------------------------------------------------------------------------*/
243 #if defined(__MINGW32__) || defined(WIN32)
244 #define snprintf _snprintf
245 #endif
246 
247 
248 #endif /* LEPTONICA_ENVIRON_H */
249 
250