HIntDef.h 6.7 KB

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