EstervQrCode 1.1.1
Library for qr code manipulation
cvdef.h
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Copyright (C) 2015, Itseez Inc., all rights reserved.
17 // Third party copyrights are property of their respective owners.
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // * Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // * Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
28 //
29 // * The name of the copyright holders may not be used to endorse or promote products
30 // derived from this software without specific prior written permission.
31 //
32 // This software is provided by the copyright holders and contributors "as is" and
33 // any express or implied warranties, including, but not limited to, the implied
34 // warranties of merchantability and fitness for a particular purpose are disclaimed.
35 // In no event shall the Intel Corporation or contributors be liable for any direct,
36 // indirect, incidental, special, exemplary, or consequential damages
37 // (including, but not limited to, procurement of substitute goods or services;
38 // loss of use, data, or profits; or business interruption) however caused
39 // and on any theory of liability, whether in contract, strict liability,
40 // or tort (including negligence or otherwise) arising in any way out of
41 // the use of this software, even if advised of the possibility of such damage.
42 //
43 //M*/
44 
45 #ifndef OPENCV_CORE_CVDEF_H
46 #define OPENCV_CORE_CVDEF_H
47 
48 #include "opencv2/core/version.hpp"
49 
52 
53 #ifdef OPENCV_INCLUDE_PORT_FILE // User-provided header file with custom platform configuration
54 #include OPENCV_INCLUDE_PORT_FILE
55 #endif
56 
57 #if !defined CV_DOXYGEN && !defined CV_IGNORE_DEBUG_BUILD_GUARD
58 #if (defined(_MSC_VER) && (defined(DEBUG) || defined(_DEBUG))) || \
59  (defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_DEBUG_PEDANTIC))
60 // Guard to prevent using of binary incompatible binaries / runtimes
61 // https://github.com/opencv/opencv/pull/9161
62 #define CV__DEBUG_NS_BEGIN namespace debug_build_guard {
63 #define CV__DEBUG_NS_END }
64 namespace cv { namespace debug_build_guard { } using namespace debug_build_guard; }
65 #endif
66 #endif
67 
68 #ifndef CV__DEBUG_NS_BEGIN
69 #define CV__DEBUG_NS_BEGIN
70 #define CV__DEBUG_NS_END
71 #endif
72 
73 
74 #ifdef __OPENCV_BUILD
75 #include "cvconfig.h"
76 #endif
77 
78 #ifndef __CV_EXPAND
79 #define __CV_EXPAND(x) x
80 #endif
81 
82 #ifndef __CV_CAT
83 #define __CV_CAT__(x, y) x ## y
84 #define __CV_CAT_(x, y) __CV_CAT__(x, y)
85 #define __CV_CAT(x, y) __CV_CAT_(x, y)
86 #endif
87 
88 #define __CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
89 #define __CV_VA_NUM_ARGS(...) __CV_EXPAND(__CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
90 
91 #ifdef CV_Func
92 // keep current value (through OpenCV port file)
93 #elif defined __GNUC__ || (defined (__cpluscplus) && (__cpluscplus >= 201103))
94 #define CV_Func __func__
95 #elif defined __clang__ && (__clang_minor__ * 100 + __clang_major__ >= 305)
96 #define CV_Func __func__
97 #elif defined(__STDC_VERSION__) && (__STDC_VERSION >= 199901)
98 #define CV_Func __func__
99 #elif defined _MSC_VER
100 #define CV_Func __FUNCTION__
101 #elif defined(__INTEL_COMPILER) && (_INTEL_COMPILER >= 600)
102 #define CV_Func __FUNCTION__
103 #elif defined __IBMCPP__ && __IBMCPP__ >=500
104 #define CV_Func __FUNCTION__
105 #elif defined __BORLAND__ && (__BORLANDC__ >= 0x550)
106 #define CV_Func __FUNC__
107 #else
108 #define CV_Func "<unknown>"
109 #endif
110 
112 
114 #define CVAUX_CONCAT_EXP(a, b) a##b
115 #define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b)
116 
117 #if defined(__clang__)
118 # ifndef __has_extension
119 # define __has_extension __has_feature /* compatibility, for older versions of clang */
120 # endif
121 # if __has_extension(cxx_static_assert)
122 # define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
123 # elif __has_extension(c_static_assert)
124 # define CV_StaticAssert(condition, reason) _Static_assert((condition), reason " " #condition)
125 # endif
126 #elif defined(__GNUC__)
127 # if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
128 # define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
129 # endif
130 #elif defined(_MSC_VER)
131 # if _MSC_VER >= 1600 /* MSVC 10 */
132 # define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
133 # endif
134 #endif
135 #ifndef CV_StaticAssert
136 # if !defined(__clang__) && defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302)
137 # define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); })
138 # else
139 namespace cv {
140  template <bool x> struct CV_StaticAssert_failed;
141  template <> struct CV_StaticAssert_failed<true> { enum { val = 1 }; };
142  template<int x> struct CV_StaticAssert_test {};
143 }
144 # define CV_StaticAssert(condition, reason)\
145  typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast<bool>(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__)
146 # endif
147 #endif
148 
149 // Suppress warning "-Wdeprecated-declarations" / C4996
150 #if defined(_MSC_VER)
151  #define CV_DO_PRAGMA(x) __pragma(x)
152 #elif defined(__GNUC__)
153  #define CV_DO_PRAGMA(x) _Pragma (#x)
154 #else
155  #define CV_DO_PRAGMA(x)
156 #endif
157 
158 #ifdef _MSC_VER
159 #define CV_SUPPRESS_DEPRECATED_START \
160  CV_DO_PRAGMA(warning(push)) \
161  CV_DO_PRAGMA(warning(disable: 4996))
162 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop))
163 #elif defined (__clang__) || ((__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 405))
164 #define CV_SUPPRESS_DEPRECATED_START \
165  CV_DO_PRAGMA(GCC diagnostic push) \
166  CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
167 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop)
168 #else
169 #define CV_SUPPRESS_DEPRECATED_START
170 #define CV_SUPPRESS_DEPRECATED_END
171 #endif
172 
173 #define CV_UNUSED(name) (void)name
174 
176 
177 // undef problematic defines sometimes defined by system headers (windows.h in particular)
178 #undef small
179 #undef min
180 #undef max
181 #undef abs
182 #undef Complex
183 
184 #if defined __cplusplus
185 #include <limits>
186 #else
187 #include <limits.h>
188 #endif
189 
190 #include "opencv2/core/hal/interface.h"
191 
192 #if defined __ICL
193 # define CV_ICC __ICL
194 #elif defined __ICC
195 # define CV_ICC __ICC
196 #elif defined __ECL
197 # define CV_ICC __ECL
198 #elif defined __ECC
199 # define CV_ICC __ECC
200 #elif defined __INTEL_COMPILER
201 # define CV_ICC __INTEL_COMPILER
202 #endif
203 
204 #if defined _WIN32
205 # define CV_CDECL __cdecl
206 # define CV_STDCALL __stdcall
207 #else
208 # define CV_CDECL
209 # define CV_STDCALL
210 #endif
211 
212 #ifndef CV_INLINE
213 # if defined __cplusplus
214 # define CV_INLINE static inline
215 # elif defined _MSC_VER
216 # define CV_INLINE __inline
217 # else
218 # define CV_INLINE static
219 # endif
220 #endif
221 
222 #ifndef CV_ALWAYS_INLINE
223 #if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
224 #define CV_ALWAYS_INLINE inline __attribute__((always_inline))
225 #elif defined(_MSC_VER)
226 #define CV_ALWAYS_INLINE __forceinline
227 #else
228 #define CV_ALWAYS_INLINE inline
229 #endif
230 #endif
231 
232 #if defined CV_DISABLE_OPTIMIZATION || (defined CV_ICC && !defined CV_ENABLE_UNROLLED)
233 # define CV_ENABLE_UNROLLED 0
234 #else
235 # define CV_ENABLE_UNROLLED 1
236 #endif
237 
238 #ifdef __GNUC__
239 # define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
240 #elif defined _MSC_VER
241 # define CV_DECL_ALIGNED(x) __declspec(align(x))
242 #else
243 # define CV_DECL_ALIGNED(x)
244 #endif
245 
246 /* CPU features and intrinsics support */
247 #define CV_CPU_NONE 0
248 #define CV_CPU_MMX 1
249 #define CV_CPU_SSE 2
250 #define CV_CPU_SSE2 3
251 #define CV_CPU_SSE3 4
252 #define CV_CPU_SSSE3 5
253 #define CV_CPU_SSE4_1 6
254 #define CV_CPU_SSE4_2 7
255 #define CV_CPU_POPCNT 8
256 #define CV_CPU_FP16 9
257 #define CV_CPU_AVX 10
258 #define CV_CPU_AVX2 11
259 #define CV_CPU_FMA3 12
260 
261 #define CV_CPU_AVX_512F 13
262 #define CV_CPU_AVX_512BW 14
263 #define CV_CPU_AVX_512CD 15
264 #define CV_CPU_AVX_512DQ 16
265 #define CV_CPU_AVX_512ER 17
266 #define CV_CPU_AVX_512IFMA512 18 // deprecated
267 #define CV_CPU_AVX_512IFMA 18
268 #define CV_CPU_AVX_512PF 19
269 #define CV_CPU_AVX_512VBMI 20
270 #define CV_CPU_AVX_512VL 21
271 #define CV_CPU_AVX_512VBMI2 22
272 #define CV_CPU_AVX_512VNNI 23
273 #define CV_CPU_AVX_512BITALG 24
274 #define CV_CPU_AVX_512VPOPCNTDQ 25
275 #define CV_CPU_AVX_5124VNNIW 26
276 #define CV_CPU_AVX_5124FMAPS 27
277 
278 #define CV_CPU_NEON 100
279 #define CV_CPU_NEON_DOTPROD 101
280 #define CV_CPU_NEON_FP16 102
281 #define CV_CPU_NEON_BF16 103
282 
283 #define CV_CPU_MSA 150
284 
285 #define CV_CPU_RISCVV 170
286 
287 #define CV_CPU_VSX 200
288 #define CV_CPU_VSX3 201
289 
290 #define CV_CPU_RVV 210
291 
292 #define CV_CPU_LSX 230
293 #define CV_CPU_LASX 231
294 
295 // CPU features groups
296 #define CV_CPU_AVX512_SKX 256
297 #define CV_CPU_AVX512_COMMON 257
298 #define CV_CPU_AVX512_KNL 258
299 #define CV_CPU_AVX512_KNM 259
300 #define CV_CPU_AVX512_CNL 260
301 #define CV_CPU_AVX512_CLX 261
302 #define CV_CPU_AVX512_ICL 262
303 
304 // when adding to this list remember to update the following enum
305 #define CV_HARDWARE_MAX_FEATURE 512
306 
310  CPU_MMX = 1,
311  CPU_SSE = 2,
312  CPU_SSE2 = 3,
313  CPU_SSE3 = 4,
318  CPU_FP16 = 9,
319  CPU_AVX = 10,
320  CPU_AVX2 = 11,
321  CPU_FMA3 = 12,
322 
328  CPU_AVX_512IFMA512 = 18, // deprecated
339 
340  CPU_NEON = 100,
344 
345  CPU_MSA = 150,
346 
347  CPU_RISCVV = 170,
348 
349  CPU_VSX = 200,
350  CPU_VSX3 = 201,
351 
352  CPU_RVV = 210,
353 
354  CPU_LSX = 230,
355  CPU_LASX = 231,
356 
364 
365  CPU_MAX_FEATURE = 512 // see CV_HARDWARE_MAX_FEATURE
366 };
367 
368 
369 #include "cv_cpu_dispatch.h"
370 
371 #if !defined(CV_STRONG_ALIGNMENT) && defined(__arm__) && !(defined(__aarch64__) || defined(_M_ARM64))
372 // int*, int64* should be propertly aligned pointers on ARMv7
373 #define CV_STRONG_ALIGNMENT 1
374 #endif
375 #if !defined(CV_STRONG_ALIGNMENT)
376 #define CV_STRONG_ALIGNMENT 0
377 #endif
378 
379 /* fundamental constants */
380 #define CV_PI 3.1415926535897932384626433832795
381 #define CV_2PI 6.283185307179586476925286766559
382 #define CV_LOG2 0.69314718055994530941723212145818
383 
384 #if defined __ARM_FP16_FORMAT_IEEE \
385  && !defined __CUDACC__
386 # define CV_FP16_TYPE 1
387 #else
388 # define CV_FP16_TYPE 0
389 #endif
390 
391 typedef union Cv16suf
392 {
393  short i;
395 #if CV_FP16_TYPE
396  __fp16 h;
397 #endif
398 }
400 
401 typedef union Cv32suf
402 {
403  int i;
404  unsigned u;
405  float f;
406 }
408 
409 typedef union Cv64suf
410 {
413  double f;
414 }
416 
417 #ifndef OPENCV_ABI_COMPATIBILITY
418 #define OPENCV_ABI_COMPATIBILITY 400
419 #endif
420 
421 #ifdef __OPENCV_BUILD
422 # define DISABLE_OPENCV_3_COMPATIBILITY
423 # define OPENCV_DISABLE_DEPRECATED_COMPATIBILITY
424 #endif
425 
426 #ifndef CV_EXPORTS
427 # if (defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined(CVAPI_EXPORTS)
428 # define CV_EXPORTS __declspec(dllexport)
429 # elif defined __GNUC__ && __GNUC__ >= 4 && (defined(CVAPI_EXPORTS) || defined(__APPLE__))
430 # define CV_EXPORTS __attribute__ ((visibility ("default")))
431 # endif
432 #endif
433 
434 #ifndef CV_EXPORTS
435 # define CV_EXPORTS
436 #endif
437 
438 #ifdef _MSC_VER
439 # define CV_EXPORTS_TEMPLATE
440 #else
441 # define CV_EXPORTS_TEMPLATE CV_EXPORTS
442 #endif
443 
444 #ifndef CV_DEPRECATED
445 # if defined(__GNUC__)
446 # define CV_DEPRECATED __attribute__ ((deprecated))
447 # elif defined(_MSC_VER)
448 # define CV_DEPRECATED __declspec(deprecated)
449 # else
450 # define CV_DEPRECATED
451 # endif
452 #endif
453 
454 #ifndef CV_DEPRECATED_EXTERNAL
455 # if defined(__OPENCV_BUILD)
456 # define CV_DEPRECATED_EXTERNAL /* nothing */
457 # else
458 # define CV_DEPRECATED_EXTERNAL CV_DEPRECATED
459 # endif
460 #endif
461 
462 
463 #ifndef CV_EXTERN_C
464 # ifdef __cplusplus
465 # define CV_EXTERN_C extern "C"
466 # else
467 # define CV_EXTERN_C
468 # endif
469 #endif
470 
471 /* special informative macros for wrapper generators */
472 #define CV_EXPORTS_W CV_EXPORTS
473 #define CV_EXPORTS_W_SIMPLE CV_EXPORTS
474 #define CV_EXPORTS_AS(synonym) CV_EXPORTS
475 #define CV_EXPORTS_W_MAP CV_EXPORTS
476 #define CV_EXPORTS_W_PARAMS CV_EXPORTS
477 #define CV_IN_OUT
478 #define CV_OUT
479 #define CV_PROP
480 #define CV_PROP_RW
481 #define CV_WRAP
482 #define CV_WRAP_AS(synonym)
483 #define CV_WRAP_MAPPABLE(mappable)
484 #define CV_WRAP_PHANTOM(phantom_header)
485 #define CV_WRAP_DEFAULT(val)
486 /* Indicates that the function parameter has filesystem path semantic */
487 #define CV_WRAP_FILE_PATH
488 
489 /****************************************************************************************\
490 * Matrix type (Mat) *
491 \****************************************************************************************/
492 
493 #define CV_MAX_DIM 32
494 #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
495 #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
496 #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
497 #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
498 #define CV_MAT_CONT_FLAG_SHIFT 14
499 #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
500 #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
501 #define CV_IS_CONT_MAT CV_IS_MAT_CONT
502 #define CV_SUBMAT_FLAG_SHIFT 15
503 #define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT)
504 #define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG)
505 
508 #define CV_ELEM_SIZE1(type) ((0x28442211 >> CV_MAT_DEPTH(type)*4) & 15)
509 
510 #define CV_ELEM_SIZE(type) (CV_MAT_CN(type)*CV_ELEM_SIZE1(type))
511 
512 #ifndef MIN
513 # define MIN(a,b) ((a) > (b) ? (b) : (a))
514 #endif
515 
516 #ifndef MAX
517 # define MAX(a,b) ((a) < (b) ? (b) : (a))
518 #endif
519 
521 #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))
522 #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))
523 #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
524 #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
525 #define CV_SIGN(a) CV_CMP((a),0)
526 
528 
543 #define __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST) \
544 static const EnumType MEMBER_CONST = EnumType::MEMBER_CONST; \
545 
546 #define __CV_ENUM_CLASS_EXPOSE_2(EnumType, MEMBER_CONST, ...) \
547 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
548 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_1(EnumType, __VA_ARGS__)); \
549 
550 #define __CV_ENUM_CLASS_EXPOSE_3(EnumType, MEMBER_CONST, ...) \
551 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
552 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_2(EnumType, __VA_ARGS__)); \
553 
554 #define __CV_ENUM_CLASS_EXPOSE_4(EnumType, MEMBER_CONST, ...) \
555 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
556 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_3(EnumType, __VA_ARGS__)); \
557 
558 #define __CV_ENUM_CLASS_EXPOSE_5(EnumType, MEMBER_CONST, ...) \
559 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
560 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_4(EnumType, __VA_ARGS__)); \
561 
562 #define __CV_ENUM_CLASS_EXPOSE_6(EnumType, MEMBER_CONST, ...) \
563 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
564 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_5(EnumType, __VA_ARGS__)); \
565 
566 #define __CV_ENUM_CLASS_EXPOSE_7(EnumType, MEMBER_CONST, ...) \
567 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
568 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_6(EnumType, __VA_ARGS__)); \
569 
570 #define __CV_ENUM_CLASS_EXPOSE_8(EnumType, MEMBER_CONST, ...) \
571 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
572 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_7(EnumType, __VA_ARGS__)); \
573 
574 #define __CV_ENUM_CLASS_EXPOSE_9(EnumType, MEMBER_CONST, ...) \
575 __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
576 __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_8(EnumType, __VA_ARGS__)); \
577 
578 #define __CV_ENUM_FLAGS_LOGICAL_NOT(EnumType) \
579 static inline bool operator!(const EnumType& val) \
580 { \
581  typedef std::underlying_type<EnumType>::type UnderlyingType; \
582  return !static_cast<UnderlyingType>(val); \
583 } \
584 
585 #define __CV_ENUM_FLAGS_LOGICAL_NOT_EQ(Arg1Type, Arg2Type) \
586 static inline bool operator!=(const Arg1Type& a, const Arg2Type& b) \
587 { \
588  return static_cast<int>(a) != static_cast<int>(b); \
589 } \
590 
591 #define __CV_ENUM_FLAGS_LOGICAL_EQ(Arg1Type, Arg2Type) \
592 static inline bool operator==(const Arg1Type& a, const Arg2Type& b) \
593 { \
594  return static_cast<int>(a) == static_cast<int>(b); \
595 } \
596 
597 #define __CV_ENUM_FLAGS_BITWISE_NOT(EnumType) \
598 static inline EnumType operator~(const EnumType& val) \
599 { \
600  typedef std::underlying_type<EnumType>::type UnderlyingType; \
601  return static_cast<EnumType>(~static_cast<UnderlyingType>(val)); \
602 } \
603 
604 #define __CV_ENUM_FLAGS_BITWISE_OR(EnumType, Arg1Type, Arg2Type) \
605 static inline EnumType operator|(const Arg1Type& a, const Arg2Type& b) \
606 { \
607  typedef std::underlying_type<EnumType>::type UnderlyingType; \
608  return static_cast<EnumType>(static_cast<UnderlyingType>(a) | static_cast<UnderlyingType>(b)); \
609 } \
610 
611 #define __CV_ENUM_FLAGS_BITWISE_AND(EnumType, Arg1Type, Arg2Type) \
612 static inline EnumType operator&(const Arg1Type& a, const Arg2Type& b) \
613 { \
614  typedef std::underlying_type<EnumType>::type UnderlyingType; \
615  return static_cast<EnumType>(static_cast<UnderlyingType>(a) & static_cast<UnderlyingType>(b)); \
616 } \
617 
618 #define __CV_ENUM_FLAGS_BITWISE_XOR(EnumType, Arg1Type, Arg2Type) \
619 static inline EnumType operator^(const Arg1Type& a, const Arg2Type& b) \
620 { \
621  typedef std::underlying_type<EnumType>::type UnderlyingType; \
622  return static_cast<EnumType>(static_cast<UnderlyingType>(a) ^ static_cast<UnderlyingType>(b)); \
623 } \
624 
625 #define __CV_ENUM_FLAGS_BITWISE_OR_EQ(EnumType, Arg1Type) \
626 static inline EnumType& operator|=(EnumType& _this, const Arg1Type& val) \
627 { \
628  _this = static_cast<EnumType>(static_cast<int>(_this) | static_cast<int>(val)); \
629  return _this; \
630 } \
631 
632 #define __CV_ENUM_FLAGS_BITWISE_AND_EQ(EnumType, Arg1Type) \
633 static inline EnumType& operator&=(EnumType& _this, const Arg1Type& val) \
634 { \
635  _this = static_cast<EnumType>(static_cast<int>(_this) & static_cast<int>(val)); \
636  return _this; \
637 } \
638 
639 #define __CV_ENUM_FLAGS_BITWISE_XOR_EQ(EnumType, Arg1Type) \
640 static inline EnumType& operator^=(EnumType& _this, const Arg1Type& val) \
641 { \
642  _this = static_cast<EnumType>(static_cast<int>(_this) ^ static_cast<int>(val)); \
643  return _this; \
644 } \
645 
646 #define CV_ENUM_CLASS_EXPOSE(EnumType, ...) \
647 __CV_EXPAND(__CV_CAT(__CV_ENUM_CLASS_EXPOSE_, __CV_VA_NUM_ARGS(__VA_ARGS__))(EnumType, __VA_ARGS__)); \
648 
649 #define CV_ENUM_FLAGS(EnumType) \
650 __CV_ENUM_FLAGS_LOGICAL_NOT (EnumType) \
651 __CV_ENUM_FLAGS_LOGICAL_EQ (EnumType, int) \
652 __CV_ENUM_FLAGS_LOGICAL_NOT_EQ (EnumType, int) \
653  \
654 __CV_ENUM_FLAGS_BITWISE_NOT (EnumType) \
655 __CV_ENUM_FLAGS_BITWISE_OR (EnumType, EnumType, EnumType) \
656 __CV_ENUM_FLAGS_BITWISE_AND (EnumType, EnumType, EnumType) \
657 __CV_ENUM_FLAGS_BITWISE_XOR (EnumType, EnumType, EnumType) \
658  \
659 __CV_ENUM_FLAGS_BITWISE_OR_EQ (EnumType, EnumType) \
660 __CV_ENUM_FLAGS_BITWISE_AND_EQ (EnumType, EnumType) \
661 __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType) \
662 
663 /****************************************************************************************\
664 * static analysys *
665 \****************************************************************************************/
666 
667 // In practice, some macro are not processed correctly (noreturn is not detected).
668 // We need to use simplified definition for them.
669 #ifndef CV_STATIC_ANALYSIS
670 # if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__)
671 # define CV_STATIC_ANALYSIS 1
672 # endif
673 #else
674 # if defined(CV_STATIC_ANALYSIS) && !(__CV_CAT(1, CV_STATIC_ANALYSIS) == 1) // defined and not empty
675 # if 0 == CV_STATIC_ANALYSIS
676 # undef CV_STATIC_ANALYSIS
677 # endif
678 # endif
679 #endif
680 
681 /****************************************************************************************\
682 * Thread sanitizer *
683 \****************************************************************************************/
684 #ifndef CV_THREAD_SANITIZER
685 # if defined(__has_feature)
686 # if __has_feature(thread_sanitizer)
687 # define CV_THREAD_SANITIZER
688 # endif
689 # endif
690 #endif
691 
692 /****************************************************************************************\
693 * exchange-add operation for atomic operations on reference counters *
694 \****************************************************************************************/
695 
696 #ifdef CV_XADD
697  // allow to use user-defined macro
698 #elif defined __GNUC__ || defined __clang__
699 # if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) && !defined __INTEL_COMPILER
700 # ifdef __ATOMIC_ACQ_REL
701 # define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
702 # else
703 # define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
704 # endif
705 # else
706 # if defined __ATOMIC_ACQ_REL && !defined __clang__
707  // version for gcc >= 4.7
708 # define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
709 # else
710 # define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
711 # endif
712 # endif
713 #elif defined _MSC_VER && !defined RC_INVOKED
714 # include <intrin.h>
715 # define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
716 #else
717  #ifdef OPENCV_FORCE_UNSAFE_XADD
718  CV_INLINE int CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
719  #else
720  #error "OpenCV: can't define safe CV_XADD macro for current platform (unsupported). Define CV_XADD macro through custom port header (see OPENCV_INCLUDE_PORT_FILE)"
721  #endif
722 #endif
723 
724 
725 /****************************************************************************************\
726 * CV_NORETURN attribute *
727 \****************************************************************************************/
728 
729 #ifndef CV_NORETURN
730 # if defined(__GNUC__)
731 # define CV_NORETURN __attribute__((__noreturn__))
732 # elif defined(_MSC_VER) && (_MSC_VER >= 1300)
733 # define CV_NORETURN __declspec(noreturn)
734 # else
735 # define CV_NORETURN /* nothing by default */
736 # endif
737 #endif
738 
739 /****************************************************************************************\
740 * CV_NODISCARD_STD attribute (C++17) *
741 * encourages the compiler to issue a warning if the return value is discarded *
742 \****************************************************************************************/
743 #ifndef CV_NODISCARD_STD
744 # ifndef __has_cpp_attribute
745 // workaround preprocessor non-compliance https://reviews.llvm.org/D57851
746 # define __has_cpp_attribute(__x) 0
747 # endif
748 # if __has_cpp_attribute(nodiscard)
749 # define CV_NODISCARD_STD [[nodiscard]]
750 # elif __cplusplus >= 201703L
751 // available when compiler is C++17 compliant
752 # define CV_NODISCARD_STD [[nodiscard]]
753 # elif defined(__INTEL_COMPILER)
754  // see above, available when C++17 is enabled
755 # elif defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L
756 // available with VS2017 v15.3+ with /std:c++17 or higher; works on functions and classes
757 # define CV_NODISCARD_STD [[nodiscard]]
758 # elif defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 700) && (__cplusplus >= 201103L)
759 // available with GCC 7.0+; works on functions, works or silently fails on classes
760 # define CV_NODISCARD_STD [[nodiscard]]
761 # elif defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 408) && (__cplusplus >= 201103L)
762 // available with GCC 4.8+ but it usually does nothing and can fail noisily -- therefore not used
763 // define CV_NODISCARD_STD [[gnu::warn_unused_result]]
764 # endif
765 #endif
766 #ifndef CV_NODISCARD_STD
767 # define CV_NODISCARD_STD /* nothing by default */
768 #endif
769 
770 
771 /****************************************************************************************\
772 * C++ 11 *
773 \****************************************************************************************/
774 #ifdef __cplusplus
775 // MSVC was stuck at __cplusplus == 199711L for a long time, even where it supports C++11,
776 // so check _MSC_VER instead. See:
777 // <https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus>
778 # if defined(_MSC_VER)
779 # if _MSC_VER < 1800
780 # error "OpenCV 4.x+ requires enabled C++11 support"
781 # endif
782 # elif __cplusplus < 201103L
783 # error "OpenCV 4.x+ requires enabled C++11 support"
784 # endif
785 #endif
786 
787 #ifndef CV_CXX11
788 # define CV_CXX11 1
789 #endif
790 
791 #ifndef CV_OVERRIDE
792 # define CV_OVERRIDE override
793 #endif
794 
795 #ifndef CV_FINAL
796 # define CV_FINAL final
797 #endif
798 
799 #ifndef CV_NOEXCEPT
800 # define CV_NOEXCEPT noexcept
801 #endif
802 
803 #ifndef CV_CONSTEXPR
804 # define CV_CONSTEXPR constexpr
805 #endif
806 
807 // Integer types portability
808 #ifdef __cplusplus
809 #include <cstdint>
810 namespace cv {
811 using std::int8_t;
812 using std::uint8_t;
813 using std::int16_t;
814 using std::uint16_t;
815 using std::int32_t;
816 using std::uint32_t;
817 using std::int64_t;
818 using std::uint64_t;
819 }
820 #else // pure C
821 #include <stdint.h>
822 #endif
823 
824 #ifdef __cplusplus
825 namespace cv
826 {
827 
828 class hfloat
829 {
830 public:
831 #if CV_FP16_TYPE
832 
833  hfloat() : h(0) {}
834  explicit hfloat(float x) { h = (__fp16)x; }
835  operator float() const { return (float)h; }
836 protected:
837  __fp16 h;
838 
839 #else
840  hfloat() : w(0) {}
841  explicit hfloat(float x)
842  {
843  #if CV_FP16 && CV_AVX2
844  __m128 v = _mm_load_ss(&x);
845  w = (ushort)_mm_cvtsi128_si32(_mm_cvtps_ph(v, 0));
846  #else
847  Cv32suf in;
848  in.f = x;
849  unsigned sign = in.u & 0x80000000;
850  in.u ^= sign;
851 
852  if( in.u >= 0x47800000 )
853  w = (ushort)(in.u > 0x7f800000 ? 0x7e00 : 0x7c00);
854  else
855  {
856  if (in.u < 0x38800000)
857  {
858  in.f += 0.5f;
859  w = (ushort)(in.u - 0x3f000000);
860  }
861  else
862  {
863  unsigned t = in.u + 0xc8000fff;
864  w = (ushort)((t + ((in.u >> 13) & 1)) >> 13);
865  }
866  }
867 
868  w = (ushort)(w | (sign >> 16));
869  #endif
870  }
871 
872  operator float() const
873  {
874  #if CV_FP16 && CV_AVX2
875  float f;
876  _mm_store_ss(&f, _mm_cvtph_ps(_mm_cvtsi32_si128(w)));
877  return f;
878  #else
879  Cv32suf out;
880 
881  unsigned t = ((w & 0x7fff) << 13) + 0x38000000;
882  unsigned sign = (w & 0x8000) << 16;
883  unsigned e = w & 0x7c00;
884 
885  out.u = t + (1 << 23);
886  out.u = (e >= 0x7c00 ? t + 0x38000000 :
887  e == 0 ? (static_cast<void>(out.f -= 6.103515625e-05f), out.u) : t) | sign;
888  return out.f;
889  #endif
890  }
891 
892 protected:
893  ushort w;
894 
895 #endif
896 };
897 
898 inline hfloat hfloatFromBits(ushort w) {
899 #if CV_FP16_TYPE
900  Cv16suf u;
901  u.u = w;
902  hfloat res(float(u.h));
903  return res;
904 #else
905  Cv32suf out;
906 
907  unsigned t = ((w & 0x7fff) << 13) + 0x38000000;
908  unsigned sign = (w & 0x8000) << 16;
909  unsigned e = w & 0x7c00;
910 
911  out.u = t + (1 << 23);
912  out.u = (e >= 0x7c00 ? t + 0x38000000 :
913  e == 0 ? (static_cast<void>(out.f -= 6.103515625e-05f), out.u) : t) | sign;
914  hfloat res(out.f);
915  return res;
916 #endif
917 }
918 
919 #if !defined(__OPENCV_BUILD) && !(defined __STDCPP_FLOAT16_T__) && !(defined __ARM_NEON)
920 typedef hfloat float16_t;
921 #endif
922 
923 }
924 #endif
925 
927 
928 #ifndef __cplusplus
929 #include "opencv2/core/fast_math.hpp" // define cvRound(double)
930 #endif
931 
932 #endif // OPENCV_CORE_CVDEF_H
const CvArr CvArr * x
Definition: core_c.h:1195
int64_t int64
Definition: interface.h:61
unsigned short ushort
Definition: interface.h:52
uint64_t uint64
Definition: interface.h:62
union Cv64suf Cv64suf
CpuFeatures
Available CPU features.
Definition: cvdef.h:309
union Cv16suf Cv16suf
union Cv32suf Cv32suf
#define CV_INLINE
Definition: cvdef.h:218
@ CPU_AVX_512VBMI2
Definition: cvdef.h:333
@ CPU_AVX_512VNNI
Definition: cvdef.h:334
@ CPU_AVX2
Definition: cvdef.h:320
@ CPU_AVX_512VL
Definition: cvdef.h:332
@ CPU_AVX_512DQ
Definition: cvdef.h:326
@ CPU_AVX_512IFMA
Definition: cvdef.h:329
@ CPU_LASX
Definition: cvdef.h:355
@ CPU_POPCNT
Definition: cvdef.h:317
@ CPU_NEON_DOTPROD
Definition: cvdef.h:341
@ CPU_SSE3
Definition: cvdef.h:313
@ CPU_FMA3
Definition: cvdef.h:321
@ CPU_AVX512_KNM
Knights Mill with AVX-512F/CD/ER/PF/4FMAPS/4VNNIW/VPOPCNTDQ.
Definition: cvdef.h:360
@ CPU_AVX_5124VNNIW
Definition: cvdef.h:337
@ CPU_AVX512_CLX
Cascade Lake with AVX-512F/CD/BW/DQ/VL/VNNI.
Definition: cvdef.h:362
@ CPU_AVX_512CD
Definition: cvdef.h:325
@ CPU_AVX_512IFMA512
Definition: cvdef.h:328
@ CPU_AVX512_COMMON
Common instructions AVX-512F/CD for all CPUs that support AVX-512.
Definition: cvdef.h:358
@ CPU_AVX512_SKX
Skylake-X with AVX-512F/CD/BW/DQ/VL.
Definition: cvdef.h:357
@ CPU_AVX_5124FMAPS
Definition: cvdef.h:338
@ CPU_AVX512_KNL
Knights Landing with AVX-512F/CD/ER/PF.
Definition: cvdef.h:359
@ CPU_RVV
Definition: cvdef.h:352
@ CPU_MAX_FEATURE
Definition: cvdef.h:365
@ CPU_SSE
Definition: cvdef.h:311
@ CPU_AVX_512ER
Definition: cvdef.h:327
@ CPU_SSE4_2
Definition: cvdef.h:316
@ CPU_AVX512_CNL
Cannon Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI.
Definition: cvdef.h:361
@ CPU_NEON_FP16
Definition: cvdef.h:342
@ CPU_NEON
Definition: cvdef.h:340
@ CPU_AVX
Definition: cvdef.h:319
@ CPU_VSX
Definition: cvdef.h:349
@ CPU_MSA
Definition: cvdef.h:345
@ CPU_AVX512_ICL
Ice Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI/VNNI/VBMI2/BITALG/VPOPCNTDQ.
Definition: cvdef.h:363
@ CPU_NEON_BF16
Definition: cvdef.h:343
@ CPU_MMX
Definition: cvdef.h:310
@ CPU_SSE4_1
Definition: cvdef.h:315
@ CPU_RISCVV
Definition: cvdef.h:347
@ CPU_AVX_512BITALG
Definition: cvdef.h:335
@ CPU_AVX_512PF
Definition: cvdef.h:330
@ CPU_AVX_512BW
Definition: cvdef.h:324
@ CPU_VSX3
Definition: cvdef.h:350
@ CPU_FP16
Definition: cvdef.h:318
@ CPU_AVX_512F
Definition: cvdef.h:323
@ CPU_SSSE3
Definition: cvdef.h:314
@ CPU_AVX_512VPOPCNTDQ
Definition: cvdef.h:336
@ CPU_LSX
Definition: cvdef.h:354
@ CPU_SSE2
Definition: cvdef.h:312
@ CPU_AVX_512VBMI
Definition: cvdef.h:331
CvSize int int int CvPoint int delta
Definition: imgproc_c.h:1168
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
Definition: cvdef.h:392
ushort u
Definition: cvdef.h:394
short i
Definition: cvdef.h:393
Definition: cvdef.h:402
unsigned u
Definition: cvdef.h:404
int i
Definition: cvdef.h:403
float f
Definition: cvdef.h:405
Definition: cvdef.h:410
double f
Definition: cvdef.h:413
uint64 u
Definition: cvdef.h:412
int64 i
Definition: cvdef.h:411