OpenCV453
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 }
64namespace 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
139namespace 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#ifndef CV_INLINE
205# if defined __cplusplus
206# define CV_INLINE static inline
207# elif defined _MSC_VER
208# define CV_INLINE __inline
209# else
210# define CV_INLINE static
211# endif
212#endif
213
214#ifndef CV_ALWAYS_INLINE
215#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
216#define CV_ALWAYS_INLINE inline __attribute__((always_inline))
217#elif defined(_MSC_VER)
218#define CV_ALWAYS_INLINE __forceinline
219#else
220#define CV_ALWAYS_INLINE inline
221#endif
222#endif
223
224#if defined CV_DISABLE_OPTIMIZATION || (defined CV_ICC && !defined CV_ENABLE_UNROLLED)
225# define CV_ENABLE_UNROLLED 0
226#else
227# define CV_ENABLE_UNROLLED 1
228#endif
229
230#ifdef __GNUC__
231# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
232#elif defined _MSC_VER
233# define CV_DECL_ALIGNED(x) __declspec(align(x))
234#else
235# define CV_DECL_ALIGNED(x)
236#endif
237
238/* CPU features and intrinsics support */
239#define CV_CPU_NONE 0
240#define CV_CPU_MMX 1
241#define CV_CPU_SSE 2
242#define CV_CPU_SSE2 3
243#define CV_CPU_SSE3 4
244#define CV_CPU_SSSE3 5
245#define CV_CPU_SSE4_1 6
246#define CV_CPU_SSE4_2 7
247#define CV_CPU_POPCNT 8
248#define CV_CPU_FP16 9
249#define CV_CPU_AVX 10
250#define CV_CPU_AVX2 11
251#define CV_CPU_FMA3 12
252
253#define CV_CPU_AVX_512F 13
254#define CV_CPU_AVX_512BW 14
255#define CV_CPU_AVX_512CD 15
256#define CV_CPU_AVX_512DQ 16
257#define CV_CPU_AVX_512ER 17
258#define CV_CPU_AVX_512IFMA512 18 // deprecated
259#define CV_CPU_AVX_512IFMA 18
260#define CV_CPU_AVX_512PF 19
261#define CV_CPU_AVX_512VBMI 20
262#define CV_CPU_AVX_512VL 21
263#define CV_CPU_AVX_512VBMI2 22
264#define CV_CPU_AVX_512VNNI 23
265#define CV_CPU_AVX_512BITALG 24
266#define CV_CPU_AVX_512VPOPCNTDQ 25
267#define CV_CPU_AVX_5124VNNIW 26
268#define CV_CPU_AVX_5124FMAPS 27
269
270#define CV_CPU_NEON 100
271
272#define CV_CPU_MSA 150
273
274#define CV_CPU_RISCVV 170
275
276#define CV_CPU_VSX 200
277#define CV_CPU_VSX3 201
278
279#define CV_CPU_RVV 210
280
281// CPU features groups
282#define CV_CPU_AVX512_SKX 256
283#define CV_CPU_AVX512_COMMON 257
284#define CV_CPU_AVX512_KNL 258
285#define CV_CPU_AVX512_KNM 259
286#define CV_CPU_AVX512_CNL 260
287#define CV_CPU_AVX512_CLX 261
288#define CV_CPU_AVX512_ICL 262
289
290// when adding to this list remember to update the following enum
291#define CV_HARDWARE_MAX_FEATURE 512
292
296 CPU_MMX = 1,
297 CPU_SSE = 2,
298 CPU_SSE2 = 3,
299 CPU_SSE3 = 4,
300 CPU_SSSE3 = 5,
301 CPU_SSE4_1 = 6,
302 CPU_SSE4_2 = 7,
303 CPU_POPCNT = 8,
304 CPU_FP16 = 9,
305 CPU_AVX = 10,
306 CPU_AVX2 = 11,
307 CPU_FMA3 = 12,
308
309 CPU_AVX_512F = 13,
310 CPU_AVX_512BW = 14,
311 CPU_AVX_512CD = 15,
312 CPU_AVX_512DQ = 16,
313 CPU_AVX_512ER = 17,
314 CPU_AVX_512IFMA512 = 18, // deprecated
315 CPU_AVX_512IFMA = 18,
316 CPU_AVX_512PF = 19,
317 CPU_AVX_512VBMI = 20,
318 CPU_AVX_512VL = 21,
319 CPU_AVX_512VBMI2 = 22,
320 CPU_AVX_512VNNI = 23,
321 CPU_AVX_512BITALG = 24,
322 CPU_AVX_512VPOPCNTDQ= 25,
323 CPU_AVX_5124VNNIW = 26,
324 CPU_AVX_5124FMAPS = 27,
325
326 CPU_NEON = 100,
327
328 CPU_MSA = 150,
329
330 CPU_RISCVV = 170,
331
332 CPU_VSX = 200,
333 CPU_VSX3 = 201,
334
335 CPU_RVV = 210,
336
344
345 CPU_MAX_FEATURE = 512 // see CV_HARDWARE_MAX_FEATURE
346};
347
348
349#include "cv_cpu_dispatch.h"
350
351#if !defined(CV_STRONG_ALIGNMENT) && defined(__arm__) && !(defined(__aarch64__) || defined(_M_ARM64))
352// int*, int64* should be propertly aligned pointers on ARMv7
353#define CV_STRONG_ALIGNMENT 1
354#endif
355#if !defined(CV_STRONG_ALIGNMENT)
356#define CV_STRONG_ALIGNMENT 0
357#endif
358
359/* fundamental constants */
360#define CV_PI 3.1415926535897932384626433832795
361#define CV_2PI 6.283185307179586476925286766559
362#define CV_LOG2 0.69314718055994530941723212145818
363
364#if defined __ARM_FP16_FORMAT_IEEE \
365 && !defined __CUDACC__
366# define CV_FP16_TYPE 1
367#else
368# define CV_FP16_TYPE 0
369#endif
370
371typedef union Cv16suf
372{
373 short i;
374 ushort u;
375#if CV_FP16_TYPE
376 __fp16 h;
377#endif
378}
379Cv16suf;
380
381typedef union Cv32suf
382{
383 int i;
384 unsigned u;
385 float f;
386}
387Cv32suf;
388
389typedef union Cv64suf
390{
391 int64 i;
392 uint64 u;
393 double f;
394}
395Cv64suf;
396
397#ifndef OPENCV_ABI_COMPATIBILITY
398#define OPENCV_ABI_COMPATIBILITY 400
399#endif
400
401#ifdef __OPENCV_BUILD
402# define DISABLE_OPENCV_3_COMPATIBILITY
403# define OPENCV_DISABLE_DEPRECATED_COMPATIBILITY
404#endif
405
406#ifndef CV_EXPORTS
407# if (defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined(CVAPI_EXPORTS)
408# define CV_EXPORTS __declspec(dllexport)
409# elif defined __GNUC__ && __GNUC__ >= 4 && (defined(CVAPI_EXPORTS) || defined(__APPLE__))
410# define CV_EXPORTS __attribute__ ((visibility ("default")))
411# endif
412#endif
413
414#ifndef CV_EXPORTS
415# define CV_EXPORTS
416#endif
417
418#ifdef _MSC_VER
419# define CV_EXPORTS_TEMPLATE
420#else
421# define CV_EXPORTS_TEMPLATE CV_EXPORTS
422#endif
423
424#ifndef CV_DEPRECATED
425# if defined(__GNUC__)
426# define CV_DEPRECATED __attribute__ ((deprecated))
427# elif defined(_MSC_VER)
428# define CV_DEPRECATED __declspec(deprecated)
429# else
430# define CV_DEPRECATED
431# endif
432#endif
433
434#ifndef CV_DEPRECATED_EXTERNAL
435# if defined(__OPENCV_BUILD)
436# define CV_DEPRECATED_EXTERNAL /* nothing */
437# else
438# define CV_DEPRECATED_EXTERNAL CV_DEPRECATED
439# endif
440#endif
441
442
443#ifndef CV_EXTERN_C
444# ifdef __cplusplus
445# define CV_EXTERN_C extern "C"
446# else
447# define CV_EXTERN_C
448# endif
449#endif
450
451/* special informative macros for wrapper generators */
452#define CV_EXPORTS_W CV_EXPORTS
453#define CV_EXPORTS_W_SIMPLE CV_EXPORTS
454#define CV_EXPORTS_AS(synonym) CV_EXPORTS
455#define CV_EXPORTS_W_MAP CV_EXPORTS
456#define CV_IN_OUT
457#define CV_OUT
458#define CV_PROP
459#define CV_PROP_RW
460#define CV_WRAP
461#define CV_WRAP_AS(synonym)
462#define CV_WRAP_MAPPABLE(mappable)
463#define CV_WRAP_PHANTOM(phantom_header)
464#define CV_WRAP_DEFAULT(val)
465
466/****************************************************************************************\
467* Matrix type (Mat) *
468\****************************************************************************************/
469
470#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
471#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
472#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
473#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
474#define CV_MAT_CONT_FLAG_SHIFT 14
475#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
476#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
477#define CV_IS_CONT_MAT CV_IS_MAT_CONT
478#define CV_SUBMAT_FLAG_SHIFT 15
479#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT)
480#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG)
481
484#define CV_ELEM_SIZE1(type) ((0x28442211 >> CV_MAT_DEPTH(type)*4) & 15)
485
486#define CV_ELEM_SIZE(type) (CV_MAT_CN(type)*CV_ELEM_SIZE1(type))
487
488#ifndef MIN
489# define MIN(a,b) ((a) > (b) ? (b) : (a))
490#endif
491
492#ifndef MAX
493# define MAX(a,b) ((a) < (b) ? (b) : (a))
494#endif
495
497
512#define __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST) \
513static const EnumType MEMBER_CONST = EnumType::MEMBER_CONST; \
514
515#define __CV_ENUM_CLASS_EXPOSE_2(EnumType, MEMBER_CONST, ...) \
516__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
517__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_1(EnumType, __VA_ARGS__)); \
518
519#define __CV_ENUM_CLASS_EXPOSE_3(EnumType, MEMBER_CONST, ...) \
520__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
521__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_2(EnumType, __VA_ARGS__)); \
522
523#define __CV_ENUM_CLASS_EXPOSE_4(EnumType, MEMBER_CONST, ...) \
524__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
525__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_3(EnumType, __VA_ARGS__)); \
526
527#define __CV_ENUM_CLASS_EXPOSE_5(EnumType, MEMBER_CONST, ...) \
528__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
529__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_4(EnumType, __VA_ARGS__)); \
530
531#define __CV_ENUM_CLASS_EXPOSE_6(EnumType, MEMBER_CONST, ...) \
532__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
533__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_5(EnumType, __VA_ARGS__)); \
534
535#define __CV_ENUM_CLASS_EXPOSE_7(EnumType, MEMBER_CONST, ...) \
536__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
537__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_6(EnumType, __VA_ARGS__)); \
538
539#define __CV_ENUM_CLASS_EXPOSE_8(EnumType, MEMBER_CONST, ...) \
540__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
541__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_7(EnumType, __VA_ARGS__)); \
542
543#define __CV_ENUM_CLASS_EXPOSE_9(EnumType, MEMBER_CONST, ...) \
544__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \
545__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_8(EnumType, __VA_ARGS__)); \
546
547#define __CV_ENUM_FLAGS_LOGICAL_NOT(EnumType) \
548static inline bool operator!(const EnumType& val) \
549{ \
550 typedef std::underlying_type<EnumType>::type UnderlyingType; \
551 return !static_cast<UnderlyingType>(val); \
552} \
553
554#define __CV_ENUM_FLAGS_LOGICAL_NOT_EQ(Arg1Type, Arg2Type) \
555static inline bool operator!=(const Arg1Type& a, const Arg2Type& b) \
556{ \
557 return static_cast<int>(a) != static_cast<int>(b); \
558} \
559
560#define __CV_ENUM_FLAGS_LOGICAL_EQ(Arg1Type, Arg2Type) \
561static inline bool operator==(const Arg1Type& a, const Arg2Type& b) \
562{ \
563 return static_cast<int>(a) == static_cast<int>(b); \
564} \
565
566#define __CV_ENUM_FLAGS_BITWISE_NOT(EnumType) \
567static inline EnumType operator~(const EnumType& val) \
568{ \
569 typedef std::underlying_type<EnumType>::type UnderlyingType; \
570 return static_cast<EnumType>(~static_cast<UnderlyingType>(val)); \
571} \
572
573#define __CV_ENUM_FLAGS_BITWISE_OR(EnumType, Arg1Type, Arg2Type) \
574static inline EnumType operator|(const Arg1Type& a, const Arg2Type& b) \
575{ \
576 typedef std::underlying_type<EnumType>::type UnderlyingType; \
577 return static_cast<EnumType>(static_cast<UnderlyingType>(a) | static_cast<UnderlyingType>(b)); \
578} \
579
580#define __CV_ENUM_FLAGS_BITWISE_AND(EnumType, Arg1Type, Arg2Type) \
581static inline EnumType operator&(const Arg1Type& a, const Arg2Type& b) \
582{ \
583 typedef std::underlying_type<EnumType>::type UnderlyingType; \
584 return static_cast<EnumType>(static_cast<UnderlyingType>(a) & static_cast<UnderlyingType>(b)); \
585} \
586
587#define __CV_ENUM_FLAGS_BITWISE_XOR(EnumType, Arg1Type, Arg2Type) \
588static inline EnumType operator^(const Arg1Type& a, const Arg2Type& b) \
589{ \
590 typedef std::underlying_type<EnumType>::type UnderlyingType; \
591 return static_cast<EnumType>(static_cast<UnderlyingType>(a) ^ static_cast<UnderlyingType>(b)); \
592} \
593
594#define __CV_ENUM_FLAGS_BITWISE_OR_EQ(EnumType, Arg1Type) \
595static inline EnumType& operator|=(EnumType& _this, const Arg1Type& val) \
596{ \
597 _this = static_cast<EnumType>(static_cast<int>(_this) | static_cast<int>(val)); \
598 return _this; \
599} \
600
601#define __CV_ENUM_FLAGS_BITWISE_AND_EQ(EnumType, Arg1Type) \
602static inline EnumType& operator&=(EnumType& _this, const Arg1Type& val) \
603{ \
604 _this = static_cast<EnumType>(static_cast<int>(_this) & static_cast<int>(val)); \
605 return _this; \
606} \
607
608#define __CV_ENUM_FLAGS_BITWISE_XOR_EQ(EnumType, Arg1Type) \
609static inline EnumType& operator^=(EnumType& _this, const Arg1Type& val) \
610{ \
611 _this = static_cast<EnumType>(static_cast<int>(_this) ^ static_cast<int>(val)); \
612 return _this; \
613} \
614
615#define CV_ENUM_CLASS_EXPOSE(EnumType, ...) \
616__CV_EXPAND(__CV_CAT(__CV_ENUM_CLASS_EXPOSE_, __CV_VA_NUM_ARGS(__VA_ARGS__))(EnumType, __VA_ARGS__)); \
617
618#define CV_ENUM_FLAGS(EnumType) \
619__CV_ENUM_FLAGS_LOGICAL_NOT (EnumType) \
620__CV_ENUM_FLAGS_LOGICAL_EQ (EnumType, int) \
621__CV_ENUM_FLAGS_LOGICAL_NOT_EQ (EnumType, int) \
622 \
623__CV_ENUM_FLAGS_BITWISE_NOT (EnumType) \
624__CV_ENUM_FLAGS_BITWISE_OR (EnumType, EnumType, EnumType) \
625__CV_ENUM_FLAGS_BITWISE_AND (EnumType, EnumType, EnumType) \
626__CV_ENUM_FLAGS_BITWISE_XOR (EnumType, EnumType, EnumType) \
627 \
628__CV_ENUM_FLAGS_BITWISE_OR_EQ (EnumType, EnumType) \
629__CV_ENUM_FLAGS_BITWISE_AND_EQ (EnumType, EnumType) \
630__CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType) \
631
632/****************************************************************************************\
633* static analysys *
634\****************************************************************************************/
635
636// In practice, some macro are not processed correctly (noreturn is not detected).
637// We need to use simplified definition for them.
638#ifndef CV_STATIC_ANALYSIS
639# if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__)
640# define CV_STATIC_ANALYSIS 1
641# endif
642#else
643# if defined(CV_STATIC_ANALYSIS) && !(__CV_CAT(1, CV_STATIC_ANALYSIS) == 1) // defined and not empty
644# if 0 == CV_STATIC_ANALYSIS
645# undef CV_STATIC_ANALYSIS
646# endif
647# endif
648#endif
649
650/****************************************************************************************\
651* Thread sanitizer *
652\****************************************************************************************/
653#ifndef CV_THREAD_SANITIZER
654# if defined(__has_feature)
655# if __has_feature(thread_sanitizer)
656# define CV_THREAD_SANITIZER
657# endif
658# endif
659#endif
660
661/****************************************************************************************\
662* exchange-add operation for atomic operations on reference counters *
663\****************************************************************************************/
664
665#ifdef CV_XADD
666 // allow to use user-defined macro
667#elif defined __GNUC__ || defined __clang__
668# if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) && !defined __INTEL_COMPILER
669# ifdef __ATOMIC_ACQ_REL
670# define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
671# else
672# define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
673# endif
674# else
675# if defined __ATOMIC_ACQ_REL && !defined __clang__
676 // version for gcc >= 4.7
677# define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
678# else
679# define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
680# endif
681# endif
682#elif defined _MSC_VER && !defined RC_INVOKED
683# include <intrin.h>
684# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
685#else
686 #ifdef OPENCV_FORCE_UNSAFE_XADD
687 CV_INLINE int CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
688 #else
689 #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)"
690 #endif
691#endif
692
693
694/****************************************************************************************\
695* CV_NORETURN attribute *
696\****************************************************************************************/
697
698#ifndef CV_NORETURN
699# if defined(__GNUC__)
700# define CV_NORETURN __attribute__((__noreturn__))
701# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
702# define CV_NORETURN __declspec(noreturn)
703# else
704# define CV_NORETURN /* nothing by default */
705# endif
706#endif
707
708
709/****************************************************************************************\
710* CV_NODISCARD attribute *
711* encourages the compiler to issue a warning if the return value is discarded (C++17) *
712\****************************************************************************************/
713#ifndef CV_NODISCARD
714# if defined(__GNUC__)
715# define CV_NODISCARD __attribute__((__warn_unused_result__)) // at least available with GCC 3.4
716# elif defined(__clang__) && defined(__has_attribute)
717# if __has_attribute(__warn_unused_result__)
718# define CV_NODISCARD __attribute__((__warn_unused_result__))
719# endif
720# endif
721#endif
722#ifndef CV_NODISCARD
723# define CV_NODISCARD /* nothing by default */
724#endif
725
726
727/****************************************************************************************\
728* C++ 11 *
729\****************************************************************************************/
730#ifndef CV_CXX11
731# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
732# define CV_CXX11 1
733# endif
734#else
735# if CV_CXX11 == 0
736# undef CV_CXX11
737# endif
738#endif
739#ifndef CV_CXX11
740# error "OpenCV 4.x+ requires enabled C++11 support"
741#endif
742
743#define CV_CXX_MOVE_SEMANTICS 1
744#define CV_CXX_MOVE(x) std::move(x)
745#define CV_CXX_STD_ARRAY 1
746#include <array>
747#ifndef CV_OVERRIDE
748# define CV_OVERRIDE override
749#endif
750#ifndef CV_FINAL
751# define CV_FINAL final
752#endif
753
754#ifndef CV_NOEXCEPT
755# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/)
756# define CV_NOEXCEPT noexcept
757# endif
758#endif
759#ifndef CV_NOEXCEPT
760# define CV_NOEXCEPT
761#endif
762
763#ifndef CV_CONSTEXPR
764# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/)
765# define CV_CONSTEXPR constexpr
766# endif
767#endif
768#ifndef CV_CONSTEXPR
769# define CV_CONSTEXPR
770#endif
771
772// Integer types portatibility
773#ifdef OPENCV_STDINT_HEADER
774#include OPENCV_STDINT_HEADER
775#elif defined(__cplusplus)
776#if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */
777namespace cv {
778typedef signed char int8_t;
779typedef unsigned char uint8_t;
780typedef signed short int16_t;
781typedef unsigned short uint16_t;
782typedef signed int int32_t;
783typedef unsigned int uint32_t;
784typedef signed __int64 int64_t;
785typedef unsigned __int64 uint64_t;
786}
787#elif defined(_MSC_VER) || __cplusplus >= 201103L
788#include <cstdint>
789namespace cv {
790using std::int8_t;
791using std::uint8_t;
792using std::int16_t;
793using std::uint16_t;
794using std::int32_t;
795using std::uint32_t;
796using std::int64_t;
797using std::uint64_t;
798}
799#else
800#include <stdint.h>
801namespace cv {
802typedef ::int8_t int8_t;
803typedef ::uint8_t uint8_t;
804typedef ::int16_t int16_t;
805typedef ::uint16_t uint16_t;
806typedef ::int32_t int32_t;
807typedef ::uint32_t uint32_t;
808typedef ::int64_t int64_t;
809typedef ::uint64_t uint64_t;
810}
811#endif
812#else // pure C
813#include <stdint.h>
814#endif
815
816#ifdef __cplusplus
817namespace cv
818{
819
820class float16_t
821{
822public:
823#if CV_FP16_TYPE
824
825 float16_t() : h(0) {}
826 explicit float16_t(float x) { h = (__fp16)x; }
827 operator float() const { return (float)h; }
828 static float16_t fromBits(ushort w)
829 {
830 Cv16suf u;
831 u.u = w;
832 float16_t result;
833 result.h = u.h;
834 return result;
835 }
836 static float16_t zero()
837 {
838 float16_t result;
839 result.h = (__fp16)0;
840 return result;
841 }
842 ushort bits() const
843 {
844 Cv16suf u;
845 u.h = h;
846 return u.u;
847 }
848protected:
849 __fp16 h;
850
851#else
852 float16_t() : w(0) {}
853 explicit float16_t(float x)
854 {
855 #if CV_FP16
856 __m128 v = _mm_load_ss(&x);
857 w = (ushort)_mm_cvtsi128_si32(_mm_cvtps_ph(v, 0));
858 #else
859 Cv32suf in;
860 in.f = x;
861 unsigned sign = in.u & 0x80000000;
862 in.u ^= sign;
863
864 if( in.u >= 0x47800000 )
865 w = (ushort)(in.u > 0x7f800000 ? 0x7e00 : 0x7c00);
866 else
867 {
868 if (in.u < 0x38800000)
869 {
870 in.f += 0.5f;
871 w = (ushort)(in.u - 0x3f000000);
872 }
873 else
874 {
875 unsigned t = in.u + 0xc8000fff;
876 w = (ushort)((t + ((in.u >> 13) & 1)) >> 13);
877 }
878 }
879
880 w = (ushort)(w | (sign >> 16));
881 #endif
882 }
883
884 operator float() const
885 {
886 #if CV_FP16
887 float f;
888 _mm_store_ss(&f, _mm_cvtph_ps(_mm_cvtsi32_si128(w)));
889 return f;
890 #else
891 Cv32suf out;
892
893 unsigned t = ((w & 0x7fff) << 13) + 0x38000000;
894 unsigned sign = (w & 0x8000) << 16;
895 unsigned e = w & 0x7c00;
896
897 out.u = t + (1 << 23);
898 out.u = (e >= 0x7c00 ? t + 0x38000000 :
899 e == 0 ? (static_cast<void>(out.f -= 6.103515625e-05f), out.u) : t) | sign;
900 return out.f;
901 #endif
902 }
903
904 static float16_t fromBits(ushort b)
905 {
906 float16_t result;
907 result.w = b;
908 return result;
909 }
910 static float16_t zero()
911 {
912 float16_t result;
913 result.w = (ushort)0;
914 return result;
915 }
916 ushort bits() const { return w; }
917protected:
918 ushort w;
919
920#endif
921};
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
CpuFeatures
Available CPU features.
Definition: cvdef.h:295
@ CPU_AVX512_KNM
Knights Mill with AVX-512F/CD/ER/PF/4FMAPS/4VNNIW/VPOPCNTDQ
Definition: cvdef.h:340
@ CPU_AVX512_CLX
Cascade Lake with AVX-512F/CD/BW/DQ/VL/VNNI
Definition: cvdef.h:342
@ CPU_AVX512_COMMON
Common instructions AVX-512F/CD for all CPUs that support AVX-512
Definition: cvdef.h:338
@ CPU_AVX512_SKX
Skylake-X with AVX-512F/CD/BW/DQ/VL
Definition: cvdef.h:337
@ CPU_AVX512_KNL
Knights Landing with AVX-512F/CD/ER/PF
Definition: cvdef.h:339
@ CPU_AVX512_CNL
Cannon Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI
Definition: cvdef.h:341
@ CPU_AVX512_ICL
Ice Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI/VNNI/VBMI2/BITALG/VPOPCNTDQ
Definition: cvdef.h:343
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvdef.h:372
Definition: cvdef.h:382
Definition: cvdef.h:390