Renesas / opencv-lib

Dependents:   RZ_A2M_Mbed_samples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cvdef.h Source File

cvdef.h

00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                          License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
00016 // Copyright (C) 2015, Itseez Inc., all rights reserved.
00017 // Third party copyrights are property of their respective owners.
00018 //
00019 // Redistribution and use in source and binary forms, with or without modification,
00020 // are permitted provided that the following conditions are met:
00021 //
00022 //   * Redistribution's of source code must retain the above copyright notice,
00023 //     this list of conditions and the following disclaimer.
00024 //
00025 //   * Redistribution's in binary form must reproduce the above copyright notice,
00026 //     this list of conditions and the following disclaimer in the documentation
00027 //     and/or other materials provided with the distribution.
00028 //
00029 //   * The name of the copyright holders may not be used to endorse or promote products
00030 //     derived from this software without specific prior written permission.
00031 //
00032 // This software is provided by the copyright holders and contributors "as is" and
00033 // any express or implied warranties, including, but not limited to, the implied
00034 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00035 // In no event shall the Intel Corporation or contributors be liable for any direct,
00036 // indirect, incidental, special, exemplary, or consequential damages
00037 // (including, but not limited to, procurement of substitute goods or services;
00038 // loss of use, data, or profits; or business interruption) however caused
00039 // and on any theory of liability, whether in contract, strict liability,
00040 // or tort (including negligence or otherwise) arising in any way out of
00041 // the use of this software, even if advised of the possibility of such damage.
00042 //
00043 //M*/
00044 
00045 #ifndef OPENCV_CORE_CVDEF_H
00046 #define OPENCV_CORE_CVDEF_H
00047 
00048 //! @addtogroup core_utils
00049 //! @{
00050 
00051 #if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER && _MSC_VER > 1300
00052 #  define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio warnings */
00053 #endif
00054 
00055 // undef problematic defines sometimes defined by system headers (windows.h in particular)
00056 #undef small
00057 #undef min
00058 #undef max
00059 #undef abs
00060 #undef Complex
00061 
00062 #if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER && _MSC_VER > 1300
00063 #  define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio warnings */
00064 #endif
00065 
00066 #include <limits.h>
00067 #include "opencv2/core/hal/interface.h"
00068 
00069 #if defined __ICL
00070 #  define CV_ICC   __ICL
00071 #elif defined __ICC
00072 #  define CV_ICC   __ICC
00073 #elif defined __ECL
00074 #  define CV_ICC   __ECL
00075 #elif defined __ECC
00076 #  define CV_ICC   __ECC
00077 #elif defined __INTEL_COMPILER
00078 #  define CV_ICC   __INTEL_COMPILER
00079 #endif
00080 
00081 #ifndef CV_INLINE
00082 #  if defined __cplusplus
00083 #    define CV_INLINE static inline
00084 #  elif defined _MSC_VER
00085 #    define CV_INLINE __inline
00086 #  else
00087 #    define CV_INLINE static
00088 #  endif
00089 #endif
00090 
00091 #if defined CV_ICC && !defined CV_ENABLE_UNROLLED
00092 #  define CV_ENABLE_UNROLLED 0
00093 #else
00094 #  define CV_ENABLE_UNROLLED 1
00095 #endif
00096 
00097 #ifdef __GNUC__
00098 #  define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
00099 #elif defined _MSC_VER
00100 #  define CV_DECL_ALIGNED(x) __declspec(align(x))
00101 #else
00102 #  define CV_DECL_ALIGNED(x)
00103 #endif
00104 
00105 /* CPU features and intrinsics support */
00106 #define CV_CPU_NONE             0
00107 #define CV_CPU_MMX              1
00108 #define CV_CPU_SSE              2
00109 #define CV_CPU_SSE2             3
00110 #define CV_CPU_SSE3             4
00111 #define CV_CPU_SSSE3            5
00112 #define CV_CPU_SSE4_1           6
00113 #define CV_CPU_SSE4_2           7
00114 #define CV_CPU_POPCNT           8
00115 #define CV_CPU_FP16             9
00116 #define CV_CPU_AVX              10
00117 #define CV_CPU_AVX2             11
00118 #define CV_CPU_FMA3             12
00119 
00120 #define CV_CPU_AVX_512F         13
00121 #define CV_CPU_AVX_512BW        14
00122 #define CV_CPU_AVX_512CD        15
00123 #define CV_CPU_AVX_512DQ        16
00124 #define CV_CPU_AVX_512ER        17
00125 #define CV_CPU_AVX_512IFMA512   18
00126 #define CV_CPU_AVX_512PF        19
00127 #define CV_CPU_AVX_512VBMI      20
00128 #define CV_CPU_AVX_512VL        21
00129 
00130 #define CV_CPU_NEON   100
00131 
00132 // when adding to this list remember to update the following enum
00133 #define CV_HARDWARE_MAX_FEATURE 255
00134 
00135 /** @brief Available CPU features.
00136 */
00137 enum CpuFeatures {
00138     CPU_MMX             = 1,
00139     CPU_SSE             = 2,
00140     CPU_SSE2            = 3,
00141     CPU_SSE3            = 4,
00142     CPU_SSSE3           = 5,
00143     CPU_SSE4_1          = 6,
00144     CPU_SSE4_2          = 7,
00145     CPU_POPCNT          = 8,
00146     CPU_FP16            = 9,
00147     CPU_AVX             = 10,
00148     CPU_AVX2            = 11,
00149     CPU_FMA3            = 12,
00150 
00151     CPU_AVX_512F        = 13,
00152     CPU_AVX_512BW       = 14,
00153     CPU_AVX_512CD       = 15,
00154     CPU_AVX_512DQ       = 16,
00155     CPU_AVX_512ER       = 17,
00156     CPU_AVX_512IFMA512  = 18,
00157     CPU_AVX_512PF       = 19,
00158     CPU_AVX_512VBMI     = 20,
00159     CPU_AVX_512VL       = 21,
00160 
00161     CPU_NEON            = 100
00162 };
00163 
00164 // do not include SSE/AVX/NEON headers for NVCC compiler
00165 #ifndef __CUDACC__
00166 
00167 #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
00168 #  include <emmintrin.h>
00169 #  define CV_MMX 1
00170 #  define CV_SSE 1
00171 #  define CV_SSE2 1
00172 #  if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
00173 #    include <pmmintrin.h>
00174 #    define CV_SSE3 1
00175 #  endif
00176 #  if defined __SSSE3__  || (defined _MSC_VER && _MSC_VER >= 1500)
00177 #    include <tmmintrin.h>
00178 #    define CV_SSSE3 1
00179 #  endif
00180 #  if defined __SSE4_1__ || (defined _MSC_VER && _MSC_VER >= 1500)
00181 #    include <smmintrin.h>
00182 #    define CV_SSE4_1 1
00183 #  endif
00184 #  if defined __SSE4_2__ || (defined _MSC_VER && _MSC_VER >= 1500)
00185 #    include <nmmintrin.h>
00186 #    define CV_SSE4_2 1
00187 #  endif
00188 #  if defined __POPCNT__ || (defined _MSC_VER && _MSC_VER >= 1500)
00189 #    ifdef _MSC_VER
00190 #      include <nmmintrin.h>
00191 #    else
00192 #      include <popcntintrin.h>
00193 #    endif
00194 #    define CV_POPCNT 1
00195 #  endif
00196 #  if defined __AVX__ || (defined _MSC_VER && _MSC_VER >= 1600 && 0)
00197 // MS Visual Studio 2010 (2012?) has no macro pre-defined to identify the use of /arch:AVX
00198 // See: http://connect.microsoft.com/VisualStudio/feedback/details/605858/arch-avx-should-define-a-predefined-macro-in-x64-and-set-a-unique-value-for-m-ix86-fp-in-win32
00199 #    include <immintrin.h>
00200 #    define CV_AVX 1
00201 #    if defined(_XCR_XFEATURE_ENABLED_MASK)
00202 #      define __xgetbv() _xgetbv(_XCR_XFEATURE_ENABLED_MASK)
00203 #    else
00204 #      define __xgetbv() 0
00205 #    endif
00206 #  endif
00207 #  if defined __AVX2__ || (defined _MSC_VER && _MSC_VER >= 1800 && 0)
00208 #    include <immintrin.h>
00209 #    define CV_AVX2 1
00210 #    if defined __FMA__
00211 #      define CV_FMA3 1
00212 #    endif
00213 #  endif
00214 #endif
00215 
00216 #if (defined WIN32 || defined _WIN32) && defined(_M_ARM)
00217 # include <Intrin.h>
00218 # include <arm_neon.h>
00219 # define CV_NEON 1
00220 # define CPU_HAS_NEON_FEATURE (true)
00221 #elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__))
00222 #  include <arm_neon.h>
00223 #  define CV_NEON 1
00224 #endif
00225 
00226 #if defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__
00227 #  define CV_VFP 1
00228 #endif
00229 
00230 #endif // __CUDACC__
00231 
00232 #ifndef CV_POPCNT
00233 #define CV_POPCNT 0
00234 #endif
00235 #ifndef CV_MMX
00236 #  define CV_MMX 0
00237 #endif
00238 #ifndef CV_SSE
00239 #  define CV_SSE 0
00240 #endif
00241 #ifndef CV_SSE2
00242 #  define CV_SSE2 0
00243 #endif
00244 #ifndef CV_SSE3
00245 #  define CV_SSE3 0
00246 #endif
00247 #ifndef CV_SSSE3
00248 #  define CV_SSSE3 0
00249 #endif
00250 #ifndef CV_SSE4_1
00251 #  define CV_SSE4_1 0
00252 #endif
00253 #ifndef CV_SSE4_2
00254 #  define CV_SSE4_2 0
00255 #endif
00256 #ifndef CV_AVX
00257 #  define CV_AVX 0
00258 #endif
00259 #ifndef CV_AVX2
00260 #  define CV_AVX2 0
00261 #endif
00262 #ifndef CV_FMA3
00263 #  define CV_FMA3 0
00264 #endif
00265 #ifndef CV_AVX_512F
00266 #  define CV_AVX_512F 0
00267 #endif
00268 #ifndef CV_AVX_512BW
00269 #  define CV_AVX_512BW 0
00270 #endif
00271 #ifndef CV_AVX_512CD
00272 #  define CV_AVX_512CD 0
00273 #endif
00274 #ifndef CV_AVX_512DQ
00275 #  define CV_AVX_512DQ 0
00276 #endif
00277 #ifndef CV_AVX_512ER
00278 #  define CV_AVX_512ER 0
00279 #endif
00280 #ifndef CV_AVX_512IFMA512
00281 #  define CV_AVX_512IFMA512 0
00282 #endif
00283 #ifndef CV_AVX_512PF
00284 #  define CV_AVX_512PF 0
00285 #endif
00286 #ifndef CV_AVX_512VBMI
00287 #  define CV_AVX_512VBMI 0
00288 #endif
00289 #ifndef CV_AVX_512VL
00290 #  define CV_AVX_512VL 0
00291 #endif
00292 
00293 #ifndef CV_NEON
00294 #  define CV_NEON 0
00295 #endif
00296 
00297 #ifndef CV_VFP
00298 #  define CV_VFP 0
00299 #endif
00300 
00301 /* fundamental constants */
00302 #define CV_PI   3.1415926535897932384626433832795
00303 #define CV_2PI 6.283185307179586476925286766559
00304 #define CV_LOG2 0.69314718055994530941723212145818
00305 
00306 #if defined __ARM_FP16_FORMAT_IEEE \
00307     && !defined __CUDACC__
00308 #  define CV_FP16_TYPE 1
00309 #else
00310 #  define CV_FP16_TYPE 0
00311 #endif
00312 
00313 typedef union Cv16suf
00314 {
00315     short i;
00316 #if CV_FP16_TYPE
00317     __fp16 h;
00318 #endif
00319     struct _fp16Format
00320     {
00321         unsigned int significand : 10;
00322         unsigned int exponent    : 5;
00323         unsigned int sign        : 1;
00324     } fmt;
00325 }
00326 Cv16suf;
00327 
00328 typedef union Cv32suf
00329 {
00330     int i;
00331     unsigned u;
00332     float f;
00333     struct _fp32Format
00334     {
00335         unsigned int significand : 23;
00336         unsigned int exponent    : 8;
00337         unsigned int sign        : 1;
00338     } fmt;
00339 }
00340 Cv32suf;
00341 
00342 typedef union Cv64suf
00343 {
00344     int64 i;
00345     uint64 u;
00346     double f;
00347 }
00348 Cv64suf;
00349 
00350 #define OPENCV_ABI_COMPATIBILITY 300
00351 
00352 #ifdef __OPENCV_BUILD
00353 #  define DISABLE_OPENCV_24_COMPATIBILITY
00354 #endif
00355 
00356 #if (defined WIN32 || defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS
00357 #  define CV_EXPORTS __declspec(dllexport)
00358 #elif defined __GNUC__ && __GNUC__ >= 4
00359 #  define CV_EXPORTS __attribute__ ((visibility ("default")))
00360 #else
00361 #  define CV_EXPORTS
00362 #endif
00363 
00364 #ifndef CV_EXTERN_C
00365 #  ifdef __cplusplus
00366 #    define CV_EXTERN_C extern "C"
00367 #  else
00368 #    define CV_EXTERN_C
00369 #  endif
00370 #endif
00371 
00372 /* special informative macros for wrapper generators */
00373 #define CV_EXPORTS_W CV_EXPORTS
00374 #define CV_EXPORTS_W_SIMPLE CV_EXPORTS
00375 #define CV_EXPORTS_AS(synonym) CV_EXPORTS
00376 #define CV_EXPORTS_W_MAP CV_EXPORTS
00377 #define CV_IN_OUT
00378 #define CV_OUT
00379 #define CV_PROP
00380 #define CV_PROP_RW
00381 #define CV_WRAP
00382 #define CV_WRAP_AS(synonym)
00383 
00384 /****************************************************************************************\
00385 *                                  Matrix type (Mat)                                     *
00386 \****************************************************************************************/
00387 
00388 #define CV_MAT_CN_MASK          ((CV_CN_MAX - 1) << CV_CN_SHIFT)
00389 #define CV_MAT_CN(flags)        ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
00390 #define CV_MAT_TYPE_MASK        (CV_DEPTH_MAX*CV_CN_MAX - 1)
00391 #define CV_MAT_TYPE(flags)      ((flags) & CV_MAT_TYPE_MASK)
00392 #define CV_MAT_CONT_FLAG_SHIFT  14
00393 #define CV_MAT_CONT_FLAG        (1 << CV_MAT_CONT_FLAG_SHIFT)
00394 #define CV_IS_MAT_CONT(flags)   ((flags) & CV_MAT_CONT_FLAG)
00395 #define CV_IS_CONT_MAT          CV_IS_MAT_CONT
00396 #define CV_SUBMAT_FLAG_SHIFT    15
00397 #define CV_SUBMAT_FLAG          (1 << CV_SUBMAT_FLAG_SHIFT)
00398 #define CV_IS_SUBMAT(flags)     ((flags) & CV_MAT_SUBMAT_FLAG)
00399 
00400 /** Size of each channel item,
00401    0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
00402 #define CV_ELEM_SIZE1(type) \
00403     ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
00404 
00405 /** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
00406 #define CV_ELEM_SIZE(type) \
00407     (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
00408 
00409 #ifndef MIN
00410 #  define MIN(a,b)  ((a) > (b) ? (b) : (a))
00411 #endif
00412 
00413 #ifndef MAX
00414 #  define MAX(a,b)  ((a) < (b) ? (b) : (a))
00415 #endif
00416 
00417 /****************************************************************************************\
00418 *          exchange-add operation for atomic operations on reference counters            *
00419 \****************************************************************************************/
00420 
00421 #ifdef CV_XADD
00422   // allow to use user-defined macro
00423 #elif defined __GNUC__
00424 #  if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__)
00425 #    ifdef __ATOMIC_ACQ_REL
00426 #      define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
00427 #    else
00428 #      define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
00429 #    endif
00430 #  else
00431 #    if defined __ATOMIC_ACQ_REL && !defined __clang__
00432        // version for gcc >= 4.7
00433 #      define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
00434 #    else
00435 #      define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
00436 #    endif
00437 #  endif
00438 #elif defined _MSC_VER && !defined RC_INVOKED
00439 #  include <intrin.h>
00440 #  define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
00441 #else
00442    CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
00443 #endif
00444 
00445 
00446 /****************************************************************************************\
00447 *                                  CV_NORETURN attribute                                 *
00448 \****************************************************************************************/
00449 
00450 #ifndef CV_NORETURN
00451 #  if defined(__GNUC__)
00452 #    define CV_NORETURN __attribute__((__noreturn__))
00453 #  elif defined(_MSC_VER) && (_MSC_VER >= 1300)
00454 #    define CV_NORETURN __declspec(noreturn)
00455 #  else
00456 #    define CV_NORETURN /* nothing by default */
00457 #  endif
00458 #endif
00459 
00460 
00461 /****************************************************************************************\
00462 *                                    C++ Move semantics                                  *
00463 \****************************************************************************************/
00464 
00465 #ifndef CV_CXX_MOVE_SEMANTICS
00466 #  if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER) && _MSC_VER >= 1600
00467 #    define CV_CXX_MOVE_SEMANTICS 1
00468 #  elif defined(__clang)
00469 #    if __has_feature(cxx_rvalue_references)
00470 #      define CV_CXX_MOVE_SEMANTICS 1
00471 #    endif
00472 #  endif
00473 #else
00474 #  if CV_CXX_MOVE_SEMANTICS == 0
00475 #    undef CV_CXX_MOVE_SEMANTICS
00476 #  endif
00477 #endif
00478 
00479 //! @}
00480 
00481 #endif // OPENCV_CORE_CVDEF_H