HIntDef.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*****************************************************************************
  2. * HIntDef.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/libhalcon
  6. * Description: Definition of HALCON data types
  7. * These definitions can be controlled by the compiler
  8. * The size of the data type is always in byte _not_ in bits
  9. *
  10. * (c) 1996-2020 by MVTec Software GmbH
  11. * www.mvtec.com
  12. *
  13. *****************************************************************************/
  14. #ifndef HINTDEF_H
  15. #define HINTDEF_H
  16. #ifndef __midl
  17. # include <float.h> /* FLT_MAX, DBL_MAX, ... */
  18. # include <limits.h> /* LONG_MAX, INT_MAX, ... */
  19. # include <stdlib.h> /* RAND_MAX */
  20. #endif
  21. #include "hclib/hclib_types.h" /* C99 standard integer types */
  22. typedef int HINT; /* Signed integer. HALCON assumes at least
  23. 4 bytes */
  24. typedef unsigned int HUINT; /* Unsigned integer. HALCON assumes at least
  25. 4 bytes */
  26. #define HUINT_MIN 0
  27. #ifndef _DOUBLE8
  28. typedef double DOUBLE8;
  29. #else
  30. typdef _DOUBLE8 DOUBLE8;
  31. #endif
  32. #ifdef __vxworks
  33. # include <types/vxTypesBase.h>
  34. # ifndef DBL_MAX
  35. # define DBL_MAX _ARCH_DBL_MAX
  36. # endif
  37. # ifndef DBL_MIN
  38. # define DBL_MIN _ARCH_DBL_MIN
  39. # endif
  40. # ifndef FLT_MAX
  41. # define FLT_MAX _ARCH_FLT_MAX
  42. # endif
  43. # ifndef FLT_MIN
  44. # define FLT_MIN _ARCH_FLT_MIN
  45. # endif
  46. #endif
  47. /* float and double epsilons: These are the differences between 1 and
  48. the smallest floating point number of type float/double that is
  49. greater than 1. As we assume IEEE 754 floating point arithmetic,
  50. the following values are used. */
  51. #ifndef FLT_EPSILON
  52. # define FLT_EPSILON 1.19209290e-07F
  53. #endif
  54. #ifndef DBL_EPSILON
  55. # define DBL_EPSILON 2.2204460492503131e-16
  56. #endif
  57. #ifndef RAND_MAX
  58. # define RAND_MAX MAXINT
  59. #endif
  60. typedef int8_t INT1; /* signed integer, 1 byte */
  61. #define INT1_MIN INT8_MIN
  62. #define INT1_MAX INT8_MAX
  63. typedef uint8_t UINT1; /* unsigned integer, 1 byte */
  64. #define UINT1_MIN 0
  65. #define UINT1_MAX UINT8_MAX
  66. typedef int16_t INT2; /* signed integer, 2 bytes */
  67. #define INT2_MIN INT16_MIN
  68. #define INT2_MAX INT16_MAX
  69. typedef uint16_t UINT2; /* unsigned integer, 2 bytes */
  70. #define UINT2_MIN 0
  71. #define UINT2_MAX UINT16_MAX
  72. typedef int32_t INT4; /* signed integer, 4 bytes */
  73. #define INT4_MIN INT32_MIN
  74. #define INT4_MAX INT32_MAX
  75. typedef uint32_t UINT4; /* unsigned integer, 4 bytes */
  76. #define UINT4_MIN 0
  77. #define UINT4_MAX UINT32_MAX
  78. /*
  79. * Defining HINT4_8 and UINT4_8 to be 64 bits on 64 bit systems and 32 bits on
  80. * 32 bit systems is a bit tricky. The obvious solution would be to use
  81. * intptr_t and uintptr_t, but this causes problems on platforms where
  82. * 'intptr_t' is ultimately derived from 'int'. Our C++ language interface has
  83. * overloaded functions with variants taking both 'int' and 'Hlong' parameters,
  84. * which is only allowed if 'int' and 'Hlong' are distinct types. Since typedef
  85. * does not create distinct types in C++, we must make sure 'Hlong' is
  86. * ultimately derived from a different type. The 'long' type nicely fits our
  87. * requirements, as it is 64 bits on all our supported platforms except for 64
  88. * bit Windows, and 32 bits on all 32 bit platforms (except for TI C6X DSPs
  89. * using COFF object format - which is obsolete - where it is 40 bits).
  90. */
  91. #if defined(_WIN64)
  92. typedef __int64 HINT4_8;
  93. typedef __int64 INT4_8;
  94. # define INT4_8_FORMAT "I64"
  95. # define INT4_8_MIN _I64_MIN
  96. # define INT4_8_MAX _I64_MAX
  97. typedef unsigned __int64 UINT4_8;
  98. # define UINT4_8_MIN 0UL
  99. # define UINT4_8_MAX _UI64_MAX
  100. # define UINT4_8_FORMAT INT4_8_FORMAT
  101. #else
  102. typedef long HINT4_8;
  103. typedef long INT4_8;
  104. # define INT4_8_MIN LONG_MIN
  105. # define INT4_8_MAX LONG_MAX
  106. # define INT4_8_FORMAT "l"
  107. typedef unsigned long UINT4_8;
  108. # define UINT4_8_MIN 0UL
  109. # define UINT4_8_MAX ULONG_MAX
  110. # define UINT4_8_FORMAT INT4_8_FORMAT
  111. #endif
  112. /* Hlong/Hulong is the same as INT4_8/UINT4_8 */
  113. typedef INT4_8 Hlong;
  114. #define HLONG_MIN INT4_8_MIN
  115. #define HLONG_MAX INT4_8_MAX
  116. #define HLONG_FORMAT INT4_8_FORMAT
  117. #define LONG_FORMAT INT4_8_FORMAT /* deprecated, use HLONG_FORMAT */
  118. typedef UINT4_8 Hulong;
  119. #define HULONG_MIN UINT4_8_MIN
  120. #define HULONG_MAX UINT4_8_MAX
  121. typedef int64_t HINT8; /* signed integer, 8 bytes */
  122. #define HINT8_MIN INT64_MIN
  123. #define HINT8_MAX INT64_MAX
  124. #if defined(_WIN32)
  125. # define HINT8_FORMAT "I64"
  126. #else
  127. # define HINT8_FORMAT "ll"
  128. #endif
  129. typedef uint64_t HUINT8; /* unsigned integer, 8 bytes */
  130. #define HUINT8_MIN 0U
  131. #define HUINT8_MAX UINT64_MAX
  132. #if !defined(HC_LARGE_IMAGES)
  133. # define HIMGCOOR_MIN INT2_MIN
  134. # define HIMGCOOR_MAX INT2_MAX
  135. # define HITEMCNT_MIN INT4_MIN
  136. # define HITEMCNT_MAX INT4_MAX
  137. # define HSUBCOOR_MIN FLT_MIN
  138. # define HSUBCOOR_MAX FLT_MAX
  139. # define HSUBCOOR_EPS FLT_EPSILON
  140. # define HSUBATTR_MIN FLT_MIN
  141. # define HSUBATTR_MAX FLT_MAX
  142. #else
  143. # define HIMGCOOR_MIN INT4_MIN
  144. # define HIMGCOOR_MAX INT4_MAX
  145. # define HITEMCNT_MIN INT4_8_MIN
  146. # define HITEMCNT_MAX INT4_8_MAX
  147. # define HSUBCOOR_MIN DBL_MIN
  148. # define HSUBCOOR_MAX DBL_MAX
  149. # define HSUBCOOR_EPS DBL_EPSILON
  150. # define HSUBATTR_MIN DBL_MIN
  151. # define HSUBATTR_MAX DBL_MAX
  152. #endif
  153. /*
  154. * Define the largest double that can be safely casted to INT4_8 without
  155. * turning negative.
  156. */
  157. #if INT4_8_MAX == INT4_MAX
  158. # define INT_4_8_MAXDOUBLE (double)INT4_MAX
  159. #else
  160. # define INT_4_8_MAXDOUBLE (double)(HINT8_MAX - 1023)
  161. #endif
  162. /* At least an address must fit into MACHINE_WORD */
  163. typedef intptr_t MACHINE_WORD;
  164. #endif /* !HINTDEF_H */