tesseract  4.00.00dev
host.h
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: host.h
3  ** Purpose: This is the system independent typedefs and defines
4  ** Author: MN, JG, MD
5  **
6  ** (c) Copyright Hewlett-Packard Company, 1988-1996.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  */
17 
18 #ifndef TESSERACT_CCUTIL_HOST_H_
19 #define TESSERACT_CCUTIL_HOST_H_
20 
21 #include <limits>
22 #include "platform.h"
23 /* _WIN32 */
24 #ifdef _WIN32
25 #include <windows.h>
26 #undef min
27 #undef max
28 #endif
29 
30 #include <cinttypes> // PRId32, ...
31 #include <cstdint> // int32_t, ...
32 
33 // definitions of portable data types (numbers and characters)
34 typedef int8_t inT8;
35 typedef uint8_t uinT8;
36 typedef int16_t inT16;
37 typedef uint16_t uinT16;
38 typedef int32_t inT32;
39 typedef uint32_t uinT32;
40 typedef int64_t inT64;
41 typedef uint64_t uinT64;
42 typedef float FLOAT32;
43 typedef double FLOAT64;
44 typedef unsigned char BOOL8;
45 
46 #if defined(_WIN32)
47 
48 /* MinGW defines the standard PRI... macros, but MSVS doesn't. */
49 
50 #if !defined(PRId32)
51 # define PRId32 "d"
52 #endif
53 
54 #if !defined(PRId64)
55 # define PRId64 "I64d"
56 #endif
57 
58 #endif /* _WIN32 */
59 
60 #define MAX_INT8 0x7f
61 #define MAX_INT16 0x7fff
62 #define MAX_INT32 0x7fffffff
63 #define MAX_UINT8 0xff
64 #define MAX_UINT16 0xffff
65 #define MAX_UINT32 0xffffffff
66 #define MAX_FLOAT32 std::numeric_limits<float>::max()
67 
68 #define MIN_INT8 static_cast<inT8>(0x80)
69 #define MIN_INT16 static_cast<inT16>(0x8000)
70 #define MIN_INT32 static_cast<inT32>(0x80000000)
71 #define MIN_UINT8 0x00
72 #define MIN_UINT16 0x0000
73 #define MIN_UINT32 0x00000000
74 // Minimum positive value ie 1e-37ish.
75 #define MIN_FLOAT32 std::numeric_limits<float>::min()
76 
77 // Defines
78 #ifndef TRUE
79 #define TRUE 1
80 #endif
81 
82 #ifndef FALSE
83 #define FALSE 0
84 #endif
85 
86 // Return true if x is within tolerance of y
87 template<class T> bool NearlyEqual(T x, T y, T tolerance) {
88  T diff = x - y;
89  return diff <= tolerance && -diff <= tolerance;
90 }
91 
92 #endif // TESSERACT_CCUTIL_HOST_H_
int64_t inT64
Definition: host.h:40
int32_t inT32
Definition: host.h:38
uint64_t uinT64
Definition: host.h:41
bool NearlyEqual(T x, T y, T tolerance)
Definition: host.h:87
int16_t inT16
Definition: host.h:36
uint32_t uinT32
Definition: host.h:39
unsigned char BOOL8
Definition: host.h:44
float FLOAT32
Definition: host.h:42
int8_t inT8
Definition: host.h:34
uint8_t uinT8
Definition: host.h:35
uint16_t uinT16
Definition: host.h:37
double FLOAT64
Definition: host.h:43