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 /* FILE was undefined somewhere */ 50 #include <stdio.h> 51 52 typedef intptr_t l_intptr_t; 53 typedef uintptr_t l_uintptr_t; 54 55 56 /*--------------------------------------------------------------------* 57 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!* 58 * USER CONFIGURABLE * 59 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!* 60 * Environ variables with I/O libraries * 61 * Manual Configuration Only: NOT AUTO_CONF * 62 *--------------------------------------------------------------------*/ 63 /* 64 * Leptonica provides interfaces to link to four external image I/O 65 * libraries, plus zlib. Setting any of these to 0 causes 66 * non-functioning stubs to be linked. 67 */ 68 #ifndef HAVE_CONFIG_H 69 #define HAVE_LIBJPEG 1 70 #define HAVE_LIBTIFF 1 71 #define HAVE_LIBPNG 1 72 #define HAVE_LIBZ 1 73 #define HAVE_LIBGIF 0 74 #define HAVE_LIBUNGIF 0 75 #endif /* ~HAVE_CONFIG_H */ 76 77 /* 78 * On linux systems, you can do I/O between Pix and memory. Specifically, 79 * you can compress (write compressed data to memory from a Pix) and 80 * uncompress (read from compressed data in memory to a Pix). 81 * For all but TIFF and PS, these use the non-posix GNU functions 82 * fmemopen() and open_memstream(). These functions are not 83 * available on other systems. To use these functions in linux, 84 * you must define HAVE_FMEMOPEN to be 1 here. 85 */ 86 #ifndef HAVE_CONFIG_H 87 #define HAVE_FMEMOPEN 0 88 #endif /* ~HAVE_CONFIG_H */ 89 90 91 /*--------------------------------------------------------------------* 92 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!* 93 * USER CONFIGURABLE * 94 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!* 95 * Environ variables for uncompressed formatted image I/O * 96 *--------------------------------------------------------------------*/ 97 /* 98 * Leptonica supplies image I/O for pnm, bmp and ps. 99 * Setting any of these to 0 causes non-functioning stubs to be linked. 100 */ 101 #define USE_BMPIO 1 102 #define USE_PNMIO 1 103 #define USE_PSIO 1 104 105 106 /*--------------------------------------------------------------------* 107 * Built-in types * 108 *--------------------------------------------------------------------*/ 109 typedef signed char l_int8; 110 typedef unsigned char l_uint8; 111 typedef short l_int16; 112 typedef unsigned short l_uint16; 113 typedef int l_int32; 114 typedef unsigned int l_uint32; 115 typedef float l_float32; 116 typedef double l_float64; 117 118 119 /*------------------------------------------------------------------------* 120 * Standard macros * 121 *------------------------------------------------------------------------*/ 122 #ifndef L_MIN 123 #define L_MIN(x,y) (((x) < (y)) ? (x) : (y)) 124 #endif 125 126 #ifndef L_MAX 127 #define L_MAX(x,y) (((x) > (y)) ? (x) : (y)) 128 #endif 129 130 #ifndef L_ABS 131 #define L_ABS(x) (((x) < 0) ? (-1 * (x)) : (x)) 132 #endif 133 134 #ifndef L_SIGN 135 #define L_SIGN(x) (((x) < 0) ? -1 : 1) 136 #endif 137 138 #ifndef UNDEF 139 #define UNDEF -1 140 #endif 141 142 #ifndef NULL 143 #define NULL 0 144 #endif 145 146 #ifndef TRUE 147 #define TRUE 1 148 #endif 149 150 #ifndef FALSE 151 #define FALSE 0 152 #endif 153 154 155 /*--------------------------------------------------------------------* 156 * Environ variables used within compiler invocation * 157 *--------------------------------------------------------------------*/ 158 /* 159 * To control conditional compilation, one of two variables 160 * 161 * L_LITTLE_ENDIAN (e.g., for Intel X86) 162 * L_BIG_ENDIAN (e.g., for Sun SPARC, Mac Power PC) 163 * 164 * is defined when the GCC compiler is invoked. 165 * All code should compile properly for both hardware architectures. 166 */ 167 168 169 /*------------------------------------------------------------------------* 170 * Simple search state variables * 171 *------------------------------------------------------------------------*/ 172 enum { 173 L_NOT_FOUND = 0, 174 L_FOUND = 1 175 }; 176 177 178 /*------------------------------------------------------------------------* 179 * Standard memory allocation * 180 * 181 * These specify the memory management functions that are used 182 * on all heap data except for Pix. Memory management for Pix 183 * also defaults to malloc and free. See pix1.c for details. 184 *------------------------------------------------------------------------*/ 185 #define MALLOC(blocksize) malloc(blocksize) 186 #define CALLOC(numelem, elemsize) calloc(numelem, elemsize) 187 #define REALLOC(ptr, blocksize) realloc(ptr, blocksize) 188 #define FREE(ptr) free(ptr) 189 190 191 /*------------------------------------------------------------------------* 192 * Control printing of error, warning, and info messages * 193 * * 194 * (Use -DNO_CONSOLE_IO on compiler line to prevent text output) * 195 *------------------------------------------------------------------------*/ 196 #ifdef NO_CONSOLE_IO 197 198 #define PROCNAME(name) 199 #define ERROR_PTR(a,b,c) ((void *)(c)) 200 #define ERROR_INT(a,b,c) ((l_int32)(c)) 201 #define ERROR_FLOAT(a,b,c) ((l_float32)(c)) 202 #define ERROR_VOID(a,b) 203 #define L_ERROR(a,b) 204 #define L_ERROR_STRING(a,b,c) 205 #define L_ERROR_INT(a,b,c) 206 #define L_ERROR_FLOAT(a,b,c) 207 #define L_WARNING(a,b) 208 #define L_WARNING_STRING(a,b,c) 209 #define L_WARNING_INT(a,b,c) 210 #define L_WARNING_FLOAT(a,b,c) 211 #define L_INFO(a,b) 212 #define L_INFO_STRING(a,b,c) 213 #define L_INFO_INT(a,b,c) 214 #define L_INFO_INT2(a,b,c,d) 215 #define L_INFO_FLOAT(a,b,c) 216 #define L_INFO_FLOAT2(a,b,c,d) 217 218 #else 219 220 #define PROCNAME(name) static const char procName[] = name 221 #define ERROR_PTR(a,b,c) returnErrorPtr((a),(b),(c)) 222 #define ERROR_INT(a,b,c) returnErrorInt((a),(b),(c)) 223 #define ERROR_FLOAT(a,b,c) returnErrorFloat((a),(b),(c)) 224 #define ERROR_VOID(a,b) returnErrorVoid((a),(b)) 225 #define L_ERROR(a,b) l_error((a),(b)) 226 #define L_ERROR_STRING(a,b,c) l_errorString((a),(b),(c)) 227 #define L_ERROR_INT(a,b,c) l_errorInt((a),(b),(c)) 228 #define L_ERROR_FLOAT(a,b,c) l_errorFloat((a),(b),(c)) 229 #define L_WARNING(a,b) l_warning((a),(b)) 230 #define L_WARNING_STRING(a,b,c) l_warningString((a),(b),(c)) 231 #define L_WARNING_INT(a,b,c) l_warningInt((a),(b),(c)) 232 #define L_WARNING_FLOAT(a,b,c) l_warningFloat((a),(b),(c)) 233 #define L_INFO(a,b) l_info((a),(b)) 234 #define L_INFO_STRING(a,b,c) l_infoString((a),(b),(c)) 235 #define L_INFO_INT(a,b,c) l_infoInt((a),(b),(c)) 236 #define L_INFO_INT2(a,b,c,d) l_infoInt2((a),(b),(c),(d)) 237 #define L_INFO_FLOAT(a,b,c) l_infoFloat((a),(b),(c)) 238 #define L_INFO_FLOAT2(a,b,c,d) l_infoFloat2((a),(b),(c),(d)) 239 240 #endif /* NO_CONSOLE_IO */ 241 242 243 /*------------------------------------------------------------------------* 244 * snprintf() renamed in MSVC * 245 *------------------------------------------------------------------------*/ 246 #if defined(__MINGW32__) || defined(WIN32) 247 #define snprintf _snprintf 248 #endif 249 250 251 #endif /* LEPTONICA_ENVIRON_H */ 252 253