| 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 | |
| 50 | //! @addtogroup core_utils |
| 51 | //! @{ |
| 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 | |
| 111 | //! @cond IGNORED |
| 112 | |
| 113 | //////////////// static assert ///////////////// |
| 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 | |
| 175 | //! @endcond |
| 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 | |
| 307 | /** @brief Available CPU features. |
| 308 | */ |
| 309 | enum CpuFeatures { |
| 310 | CPU_MMX = 1, |
| 311 | CPU_SSE = 2, |
| 312 | CPU_SSE2 = 3, |
| 313 | CPU_SSE3 = 4, |
| 314 | CPU_SSSE3 = 5, |
| 315 | CPU_SSE4_1 = 6, |
| 316 | CPU_SSE4_2 = 7, |
| 317 | CPU_POPCNT = 8, |
| 318 | CPU_FP16 = 9, |
| 319 | CPU_AVX = 10, |
| 320 | CPU_AVX2 = 11, |
| 321 | CPU_FMA3 = 12, |
| 322 | |
| 323 | CPU_AVX_512F = 13, |
| 324 | CPU_AVX_512BW = 14, |
| 325 | CPU_AVX_512CD = 15, |
| 326 | CPU_AVX_512DQ = 16, |
| 327 | CPU_AVX_512ER = 17, |
| 328 | CPU_AVX_512IFMA512 = 18, // deprecated |
| 329 | CPU_AVX_512IFMA = 18, |
| 330 | CPU_AVX_512PF = 19, |
| 331 | CPU_AVX_512VBMI = 20, |
| 332 | CPU_AVX_512VL = 21, |
| 333 | CPU_AVX_512VBMI2 = 22, |
| 334 | CPU_AVX_512VNNI = 23, |
| 335 | CPU_AVX_512BITALG = 24, |
| 336 | CPU_AVX_512VPOPCNTDQ= 25, |
| 337 | CPU_AVX_5124VNNIW = 26, |
| 338 | CPU_AVX_5124FMAPS = 27, |
| 339 | |
| 340 | CPU_NEON = 100, |
| 341 | CPU_NEON_DOTPROD = 101, |
| 342 | CPU_NEON_FP16 = 102, |
| 343 | CPU_NEON_BF16 = 103, |
| 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 | |
| 357 | CPU_AVX512_SKX = 256, //!< Skylake-X with AVX-512F/CD/BW/DQ/VL |
| 358 | CPU_AVX512_COMMON = 257, //!< Common instructions AVX-512F/CD for all CPUs that support AVX-512 |
| 359 | CPU_AVX512_KNL = 258, //!< Knights Landing with AVX-512F/CD/ER/PF |
| 360 | CPU_AVX512_KNM = 259, //!< Knights Mill with AVX-512F/CD/ER/PF/4FMAPS/4VNNIW/VPOPCNTDQ |
| 361 | CPU_AVX512_CNL = 260, //!< Cannon Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI |
| 362 | CPU_AVX512_CLX = 261, //!< Cascade Lake with AVX-512F/CD/BW/DQ/VL/VNNI |
| 363 | CPU_AVX512_ICL = 262, //!< Ice Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI/VNNI/VBMI2/BITALG/VPOPCNTDQ |
| 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) || defined(_M_ARM64EC)) |
| 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; |
| 394 | ushort u; |
| 395 | #if CV_FP16_TYPE |
| 396 | __fp16 h; |
| 397 | #endif |
| 398 | } |
| 399 | Cv16suf; |
| 400 | |
| 401 | typedef union Cv32suf |
| 402 | { |
| 403 | int i; |
| 404 | unsigned u; |
| 405 | float f; |
| 406 | } |
| 407 | Cv32suf; |
| 408 | |
| 409 | typedef union Cv64suf |
| 410 | { |
| 411 | int64 i; |
| 412 | uint64 u; |
| 413 | double f; |
| 414 | } |
| 415 | Cv64suf; |
| 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_ND // Indicates that input data should be parsed into Mat without channels |
| 482 | #define CV_WRAP |
| 483 | #define CV_WRAP_AS(synonym) |
| 484 | #define CV_WRAP_MAPPABLE(mappable) |
| 485 | #define CV_WRAP_PHANTOM(phantom_header) |
| 486 | #define CV_WRAP_DEFAULT(val) |
| 487 | /* Indicates that the function parameter has filesystem path semantic */ |
| 488 | #define CV_WRAP_FILE_PATH |
| 489 | |
| 490 | /****************************************************************************************\ |
| 491 | * Matrix type (Mat) * |
| 492 | \****************************************************************************************/ |
| 493 | |
| 494 | #define CV_MAX_DIM 32 |
| 495 | #define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) |
| 496 | #define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) |
| 497 | #define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) |
| 498 | #define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) |
| 499 | #define CV_MAT_CONT_FLAG_SHIFT 14 |
| 500 | #define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT) |
| 501 | #define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG) |
| 502 | #define CV_IS_CONT_MAT CV_IS_MAT_CONT |
| 503 | #define CV_SUBMAT_FLAG_SHIFT 15 |
| 504 | #define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT) |
| 505 | #define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) |
| 506 | |
| 507 | /** Size of each channel item, |
| 508 | 0x28442211 = 0010 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ |
| 509 | #define CV_ELEM_SIZE1(type) ((0x28442211 >> CV_MAT_DEPTH(type)*4) & 15) |
| 510 | |
| 511 | #define CV_ELEM_SIZE(type) (CV_MAT_CN(type)*CV_ELEM_SIZE1(type)) |
| 512 | |
| 513 | #ifndef MIN |
| 514 | # define MIN(a,b) ((a) > (b) ? (b) : (a)) |
| 515 | #endif |
| 516 | |
| 517 | #ifndef MAX |
| 518 | # define MAX(a,b) ((a) < (b) ? (b) : (a)) |
| 519 | #endif |
| 520 | |
| 521 | /** min & max without jumps */ |
| 522 | #define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1))) |
| 523 | #define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1))) |
| 524 | #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t)) |
| 525 | #define CV_CMP(a,b) (((a) > (b)) - ((a) < (b))) |
| 526 | #define CV_SIGN(a) CV_CMP((a),0) |
| 527 | |
| 528 | ///////////////////////////////////////// Enum operators /////////////////////////////////////// |
| 529 | |
| 530 | /** |
| 531 | |
| 532 | Provides compatibility operators for both classical and C++11 enum classes, |
| 533 | as well as exposing the C++11 enum class members for backwards compatibility |
| 534 | |
| 535 | @code |
| 536 | // Provides operators required for flag enums |
| 537 | CV_ENUM_FLAGS(AccessFlag) |
| 538 | |
| 539 | // Exposes the listed members of the enum class AccessFlag to the current namespace |
| 540 | CV_ENUM_CLASS_EXPOSE(AccessFlag, ACCESS_READ [, ACCESS_WRITE [, ...] ]); |
| 541 | @endcode |
| 542 | */ |
| 543 | |
| 544 | #define __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST) \ |
| 545 | static const EnumType MEMBER_CONST = EnumType::MEMBER_CONST; \ |
| 546 | |
| 547 | #define __CV_ENUM_CLASS_EXPOSE_2(EnumType, MEMBER_CONST, ...) \ |
| 548 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 549 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_1(EnumType, __VA_ARGS__)); \ |
| 550 | |
| 551 | #define __CV_ENUM_CLASS_EXPOSE_3(EnumType, MEMBER_CONST, ...) \ |
| 552 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 553 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_2(EnumType, __VA_ARGS__)); \ |
| 554 | |
| 555 | #define __CV_ENUM_CLASS_EXPOSE_4(EnumType, MEMBER_CONST, ...) \ |
| 556 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 557 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_3(EnumType, __VA_ARGS__)); \ |
| 558 | |
| 559 | #define __CV_ENUM_CLASS_EXPOSE_5(EnumType, MEMBER_CONST, ...) \ |
| 560 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 561 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_4(EnumType, __VA_ARGS__)); \ |
| 562 | |
| 563 | #define __CV_ENUM_CLASS_EXPOSE_6(EnumType, MEMBER_CONST, ...) \ |
| 564 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 565 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_5(EnumType, __VA_ARGS__)); \ |
| 566 | |
| 567 | #define __CV_ENUM_CLASS_EXPOSE_7(EnumType, MEMBER_CONST, ...) \ |
| 568 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 569 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_6(EnumType, __VA_ARGS__)); \ |
| 570 | |
| 571 | #define __CV_ENUM_CLASS_EXPOSE_8(EnumType, MEMBER_CONST, ...) \ |
| 572 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 573 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_7(EnumType, __VA_ARGS__)); \ |
| 574 | |
| 575 | #define __CV_ENUM_CLASS_EXPOSE_9(EnumType, MEMBER_CONST, ...) \ |
| 576 | __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ |
| 577 | __CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_8(EnumType, __VA_ARGS__)); \ |
| 578 | |
| 579 | #define __CV_ENUM_FLAGS_LOGICAL_NOT(EnumType) \ |
| 580 | static inline bool operator!(const EnumType& val) \ |
| 581 | { \ |
| 582 | typedef std::underlying_type<EnumType>::type UnderlyingType; \ |
| 583 | return !static_cast<UnderlyingType>(val); \ |
| 584 | } \ |
| 585 | |
| 586 | #define __CV_ENUM_FLAGS_LOGICAL_NOT_EQ(Arg1Type, Arg2Type) \ |
| 587 | static inline bool operator!=(const Arg1Type& a, const Arg2Type& b) \ |
| 588 | { \ |
| 589 | return static_cast<int>(a) != static_cast<int>(b); \ |
| 590 | } \ |
| 591 | |
| 592 | #define __CV_ENUM_FLAGS_LOGICAL_EQ(Arg1Type, Arg2Type) \ |
| 593 | static inline bool operator==(const Arg1Type& a, const Arg2Type& b) \ |
| 594 | { \ |
| 595 | return static_cast<int>(a) == static_cast<int>(b); \ |
| 596 | } \ |
| 597 | |
| 598 | #define __CV_ENUM_FLAGS_BITWISE_NOT(EnumType) \ |
| 599 | static inline EnumType operator~(const EnumType& val) \ |
| 600 | { \ |
| 601 | typedef std::underlying_type<EnumType>::type UnderlyingType; \ |
| 602 | return static_cast<EnumType>(~static_cast<UnderlyingType>(val)); \ |
| 603 | } \ |
| 604 | |
| 605 | #define __CV_ENUM_FLAGS_BITWISE_OR(EnumType, Arg1Type, Arg2Type) \ |
| 606 | static inline EnumType operator|(const Arg1Type& a, const Arg2Type& b) \ |
| 607 | { \ |
| 608 | typedef std::underlying_type<EnumType>::type UnderlyingType; \ |
| 609 | return static_cast<EnumType>(static_cast<UnderlyingType>(a) | static_cast<UnderlyingType>(b)); \ |
| 610 | } \ |
| 611 | |
| 612 | #define __CV_ENUM_FLAGS_BITWISE_AND(EnumType, Arg1Type, Arg2Type) \ |
| 613 | static inline EnumType operator&(const Arg1Type& a, const Arg2Type& b) \ |
| 614 | { \ |
| 615 | typedef std::underlying_type<EnumType>::type UnderlyingType; \ |
| 616 | return static_cast<EnumType>(static_cast<UnderlyingType>(a) & static_cast<UnderlyingType>(b)); \ |
| 617 | } \ |
| 618 | |
| 619 | #define __CV_ENUM_FLAGS_BITWISE_XOR(EnumType, Arg1Type, Arg2Type) \ |
| 620 | static inline EnumType operator^(const Arg1Type& a, const Arg2Type& b) \ |
| 621 | { \ |
| 622 | typedef std::underlying_type<EnumType>::type UnderlyingType; \ |
| 623 | return static_cast<EnumType>(static_cast<UnderlyingType>(a) ^ static_cast<UnderlyingType>(b)); \ |
| 624 | } \ |
| 625 | |
| 626 | #define __CV_ENUM_FLAGS_BITWISE_OR_EQ(EnumType, Arg1Type) \ |
| 627 | static inline EnumType& operator|=(EnumType& _this, const Arg1Type& val) \ |
| 628 | { \ |
| 629 | _this = static_cast<EnumType>(static_cast<int>(_this) | static_cast<int>(val)); \ |
| 630 | return _this; \ |
| 631 | } \ |
| 632 | |
| 633 | #define __CV_ENUM_FLAGS_BITWISE_AND_EQ(EnumType, Arg1Type) \ |
| 634 | static inline EnumType& operator&=(EnumType& _this, const Arg1Type& val) \ |
| 635 | { \ |
| 636 | _this = static_cast<EnumType>(static_cast<int>(_this) & static_cast<int>(val)); \ |
| 637 | return _this; \ |
| 638 | } \ |
| 639 | |
| 640 | #define __CV_ENUM_FLAGS_BITWISE_XOR_EQ(EnumType, Arg1Type) \ |
| 641 | static inline EnumType& operator^=(EnumType& _this, const Arg1Type& val) \ |
| 642 | { \ |
| 643 | _this = static_cast<EnumType>(static_cast<int>(_this) ^ static_cast<int>(val)); \ |
| 644 | return _this; \ |
| 645 | } \ |
| 646 | |
| 647 | #define CV_ENUM_CLASS_EXPOSE(EnumType, ...) \ |
| 648 | __CV_EXPAND(__CV_CAT(__CV_ENUM_CLASS_EXPOSE_, __CV_VA_NUM_ARGS(__VA_ARGS__))(EnumType, __VA_ARGS__)); \ |
| 649 | |
| 650 | #define CV_ENUM_FLAGS(EnumType) \ |
| 651 | __CV_ENUM_FLAGS_LOGICAL_NOT (EnumType) \ |
| 652 | __CV_ENUM_FLAGS_LOGICAL_EQ (EnumType, int) \ |
| 653 | __CV_ENUM_FLAGS_LOGICAL_NOT_EQ (EnumType, int) \ |
| 654 | \ |
| 655 | __CV_ENUM_FLAGS_BITWISE_NOT (EnumType) \ |
| 656 | __CV_ENUM_FLAGS_BITWISE_OR (EnumType, EnumType, EnumType) \ |
| 657 | __CV_ENUM_FLAGS_BITWISE_AND (EnumType, EnumType, EnumType) \ |
| 658 | __CV_ENUM_FLAGS_BITWISE_XOR (EnumType, EnumType, EnumType) \ |
| 659 | \ |
| 660 | __CV_ENUM_FLAGS_BITWISE_OR_EQ (EnumType, EnumType) \ |
| 661 | __CV_ENUM_FLAGS_BITWISE_AND_EQ (EnumType, EnumType) \ |
| 662 | __CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType) \ |
| 663 | |
| 664 | /****************************************************************************************\ |
| 665 | * static analysys * |
| 666 | \****************************************************************************************/ |
| 667 | |
| 668 | // In practice, some macro are not processed correctly (noreturn is not detected). |
| 669 | // We need to use simplified definition for them. |
| 670 | #ifndef CV_STATIC_ANALYSIS |
| 671 | # if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__) |
| 672 | # define CV_STATIC_ANALYSIS 1 |
| 673 | # endif |
| 674 | #else |
| 675 | # if defined(CV_STATIC_ANALYSIS) && !(__CV_CAT(1, CV_STATIC_ANALYSIS) == 1) // defined and not empty |
| 676 | # if 0 == CV_STATIC_ANALYSIS |
| 677 | # undef CV_STATIC_ANALYSIS |
| 678 | # endif |
| 679 | # endif |
| 680 | #endif |
| 681 | |
| 682 | /****************************************************************************************\ |
| 683 | * Thread sanitizer * |
| 684 | \****************************************************************************************/ |
| 685 | #ifndef CV_THREAD_SANITIZER |
| 686 | # if defined(__has_feature) |
| 687 | # if __has_feature(thread_sanitizer) |
| 688 | # define CV_THREAD_SANITIZER |
| 689 | # endif |
| 690 | # endif |
| 691 | #endif |
| 692 | |
| 693 | /****************************************************************************************\ |
| 694 | * exchange-add operation for atomic operations on reference counters * |
| 695 | \****************************************************************************************/ |
| 696 | |
| 697 | #ifdef CV_XADD |
| 698 | // allow to use user-defined macro |
| 699 | #elif defined __GNUC__ || defined __clang__ |
| 700 | # if defined __clang__ && __clang_major__ >= 3 && !defined __EMSCRIPTEN__ && !defined __INTEL_COMPILER |
| 701 | # ifdef __ATOMIC_ACQ_REL |
| 702 | # define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL) |
| 703 | # else |
| 704 | # define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4) |
| 705 | # endif |
| 706 | # else |
| 707 | # if defined __ATOMIC_ACQ_REL && !defined __clang__ |
| 708 | // version for gcc >= 4.7 |
| 709 | # define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL) |
| 710 | # else |
| 711 | # define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta)) |
| 712 | # endif |
| 713 | # endif |
| 714 | #elif defined _MSC_VER && !defined RC_INVOKED |
| 715 | # include <intrin.h> |
| 716 | # define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) |
| 717 | #else |
| 718 | #ifdef OPENCV_FORCE_UNSAFE_XADD |
| 719 | CV_INLINE int CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } |
| 720 | #else |
| 721 | #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)" |
| 722 | #endif |
| 723 | #endif |
| 724 | |
| 725 | |
| 726 | /****************************************************************************************\ |
| 727 | * CV_NORETURN attribute * |
| 728 | \****************************************************************************************/ |
| 729 | |
| 730 | #ifndef CV_NORETURN |
| 731 | # if defined(__GNUC__) |
| 732 | # define CV_NORETURN __attribute__((__noreturn__)) |
| 733 | # elif defined(_MSC_VER) && (_MSC_VER >= 1300) |
| 734 | # define CV_NORETURN __declspec(noreturn) |
| 735 | # else |
| 736 | # define CV_NORETURN /* nothing by default */ |
| 737 | # endif |
| 738 | #endif |
| 739 | |
| 740 | /****************************************************************************************\ |
| 741 | * CV_NODISCARD_STD attribute (C++17) * |
| 742 | * encourages the compiler to issue a warning if the return value is discarded * |
| 743 | \****************************************************************************************/ |
| 744 | #ifndef CV_NODISCARD_STD |
| 745 | # ifndef __has_cpp_attribute |
| 746 | // workaround preprocessor non-compliance https://reviews.llvm.org/D57851 |
| 747 | # define __has_cpp_attribute(__x) 0 |
| 748 | # endif |
| 749 | # if __has_cpp_attribute(nodiscard) |
| 750 | # if defined(__NVCC__) && __CUDACC_VER_MAJOR__ < 12 |
| 751 | # define CV_NODISCARD_STD |
| 752 | # else |
| 753 | # define CV_NODISCARD_STD [[nodiscard]] |
| 754 | # endif |
| 755 | # elif __cplusplus >= 201703L |
| 756 | // available when compiler is C++17 compliant |
| 757 | # define CV_NODISCARD_STD [[nodiscard]] |
| 758 | # elif defined(__INTEL_COMPILER) |
| 759 | // see above, available when C++17 is enabled |
| 760 | # elif defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L |
| 761 | // available with VS2017 v15.3+ with /std:c++17 or higher; works on functions and classes |
| 762 | # define CV_NODISCARD_STD [[nodiscard]] |
| 763 | # elif defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 700) && (__cplusplus >= 201103L) |
| 764 | // available with GCC 7.0+; works on functions, works or silently fails on classes |
| 765 | # define CV_NODISCARD_STD [[nodiscard]] |
| 766 | # elif defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 408) && (__cplusplus >= 201103L) |
| 767 | // available with GCC 4.8+ but it usually does nothing and can fail noisily -- therefore not used |
| 768 | // define CV_NODISCARD_STD [[gnu::warn_unused_result]] |
| 769 | # endif |
| 770 | #endif |
| 771 | #ifndef CV_NODISCARD_STD |
| 772 | # define CV_NODISCARD_STD /* nothing by default */ |
| 773 | #endif |
| 774 | |
| 775 | |
| 776 | /****************************************************************************************\ |
| 777 | * C++ 11 * |
| 778 | \****************************************************************************************/ |
| 779 | #ifdef __cplusplus |
| 780 | // MSVC was stuck at __cplusplus == 199711L for a long time, even where it supports C++11, |
| 781 | // so check _MSC_VER instead. See: |
| 782 | // <https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus> |
| 783 | # if defined(_MSC_VER) |
| 784 | # if _MSC_VER < 1800 |
| 785 | # error "OpenCV 4.x+ requires enabled C++11 support" |
| 786 | # endif |
| 787 | # elif __cplusplus < 201103L |
| 788 | # error "OpenCV 4.x+ requires enabled C++11 support" |
| 789 | # endif |
| 790 | #endif |
| 791 | |
| 792 | #ifndef CV_CXX11 |
| 793 | # define CV_CXX11 1 |
| 794 | #endif |
| 795 | |
| 796 | #ifndef CV_OVERRIDE |
| 797 | # define CV_OVERRIDE override |
| 798 | #endif |
| 799 | |
| 800 | #ifndef CV_FINAL |
| 801 | # define CV_FINAL final |
| 802 | #endif |
| 803 | |
| 804 | #ifndef CV_NOEXCEPT |
| 805 | # define CV_NOEXCEPT noexcept |
| 806 | #endif |
| 807 | |
| 808 | #ifndef CV_CONSTEXPR |
| 809 | # define CV_CONSTEXPR constexpr |
| 810 | #endif |
| 811 | |
| 812 | // Integer types portability |
| 813 | #ifdef __cplusplus |
| 814 | #include <cstdint> |
| 815 | namespace cv { |
| 816 | using std::int8_t; |
| 817 | using std::uint8_t; |
| 818 | using std::int16_t; |
| 819 | using std::uint16_t; |
| 820 | using std::int32_t; |
| 821 | using std::uint32_t; |
| 822 | using std::int64_t; |
| 823 | using std::uint64_t; |
| 824 | } |
| 825 | #else // pure C |
| 826 | #include <stdint.h> |
| 827 | #endif |
| 828 | |
| 829 | #ifdef __cplusplus |
| 830 | namespace cv |
| 831 | { |
| 832 | |
| 833 | class hfloat |
| 834 | { |
| 835 | public: |
| 836 | #if CV_FP16_TYPE |
| 837 | |
| 838 | hfloat() : h(0) {} |
| 839 | explicit hfloat(float x) { h = (__fp16)x; } |
| 840 | operator float() const { return (float)h; } |
| 841 | protected: |
| 842 | __fp16 h; |
| 843 | |
| 844 | #else |
| 845 | hfloat() : w(0) {} |
| 846 | explicit hfloat(float x) |
| 847 | { |
| 848 | #if CV_FP16 && CV_AVX2 |
| 849 | __m128 v = _mm_load_ss(p: &x); |
| 850 | w = (ushort)_mm_cvtsi128_si32(_mm_cvtps_ph(v, 0)); |
| 851 | #else |
| 852 | Cv32suf in; |
| 853 | in.f = x; |
| 854 | unsigned sign = in.u & 0x80000000; |
| 855 | in.u ^= sign; |
| 856 | |
| 857 | if( in.u >= 0x47800000 ) |
| 858 | w = (ushort)(in.u > 0x7f800000 ? 0x7e00 : 0x7c00); |
| 859 | else |
| 860 | { |
| 861 | if (in.u < 0x38800000) |
| 862 | { |
| 863 | in.f += 0.5f; |
| 864 | w = (ushort)(in.u - 0x3f000000); |
| 865 | } |
| 866 | else |
| 867 | { |
| 868 | unsigned t = in.u + 0xc8000fff; |
| 869 | w = (ushort)((t + ((in.u >> 13) & 1)) >> 13); |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | w = (ushort)(w | (sign >> 16)); |
| 874 | #endif |
| 875 | } |
| 876 | |
| 877 | operator float() const |
| 878 | { |
| 879 | #if CV_FP16 && CV_AVX2 |
| 880 | float f; |
| 881 | _mm_store_ss(p: &f, a: _mm_cvtph_ps(a: _mm_cvtsi32_si128(a: w))); |
| 882 | return f; |
| 883 | #else |
| 884 | Cv32suf out; |
| 885 | |
| 886 | unsigned t = ((w & 0x7fff) << 13) + 0x38000000; |
| 887 | unsigned sign = (w & 0x8000) << 16; |
| 888 | unsigned e = w & 0x7c00; |
| 889 | |
| 890 | out.u = t + (1 << 23); |
| 891 | out.u = (e >= 0x7c00 ? t + 0x38000000 : |
| 892 | e == 0 ? (static_cast<void>(out.f -= 6.103515625e-05f), out.u) : t) | sign; |
| 893 | return out.f; |
| 894 | #endif |
| 895 | } |
| 896 | |
| 897 | protected: |
| 898 | ushort w; |
| 899 | |
| 900 | #endif |
| 901 | }; |
| 902 | |
| 903 | inline hfloat hfloatFromBits(ushort w) { |
| 904 | #if CV_FP16_TYPE |
| 905 | Cv16suf u; |
| 906 | u.u = w; |
| 907 | hfloat res(float(u.h)); |
| 908 | return res; |
| 909 | #else |
| 910 | Cv32suf out; |
| 911 | |
| 912 | unsigned t = ((w & 0x7fff) << 13) + 0x38000000; |
| 913 | unsigned sign = (w & 0x8000) << 16; |
| 914 | unsigned e = w & 0x7c00; |
| 915 | |
| 916 | out.u = t + (1 << 23); |
| 917 | out.u = (e >= 0x7c00 ? t + 0x38000000 : |
| 918 | e == 0 ? (static_cast<void>(out.f -= 6.103515625e-05f), out.u) : t) | sign; |
| 919 | hfloat res(out.f); |
| 920 | return res; |
| 921 | #endif |
| 922 | } |
| 923 | |
| 924 | #if !defined(__OPENCV_BUILD) && !(defined __STDCPP_FLOAT16_T__) && !(defined __ARM_NEON) |
| 925 | typedef hfloat float16_t; |
| 926 | #endif |
| 927 | |
| 928 | } |
| 929 | #endif |
| 930 | |
| 931 | /** @brief Constructs the 'fourcc' code, used in video codecs and many other places. |
| 932 | Simply call it with 4 chars like `CV_FOURCC('I', 'Y', 'U', 'V')` |
| 933 | */ |
| 934 | CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4) |
| 935 | { |
| 936 | return (c1 & 255) + ((c2 & 255) << 8) + ((c3 & 255) << 16) + ((c4 & 255) << 24); |
| 937 | } |
| 938 | |
| 939 | //! Macro to construct the fourcc code of the codec. Same as CV_FOURCC() |
| 940 | #define CV_FOURCC_MACRO(c1, c2, c3, c4) (((c1) & 255) + (((c2) & 255) << 8) + (((c3) & 255) << 16) + (((c4) & 255) << 24)) |
| 941 | |
| 942 | //! @} |
| 943 | |
| 944 | #ifndef __cplusplus |
| 945 | #include "opencv2/core/fast_math.hpp" // define cvRound(double) |
| 946 | #endif |
| 947 | |
| 948 | #endif // OPENCV_CORE_CVDEF_H |
| 949 | |