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 #if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER && _MSC_VER > 1300
49 #  define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio warnings */
50 #endif
51 
52 // undef problematic defines sometimes defined by system headers (windows.h in particular)
53 #undef small
54 #undef min
55 #undef max
56 #undef abs
57 #undef Complex
58 
59 #include "opencv2/hal/defs.h"
60 
61 #ifdef __OPENCV_BUILD
62 #  define DISABLE_OPENCV_24_COMPATIBILITY
63 #endif
64 
65 #if (defined WIN32 || defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS
66 #  define CV_EXPORTS __declspec(dllexport)
67 #elif defined __GNUC__ && __GNUC__ >= 4
68 #  define CV_EXPORTS __attribute__ ((visibility ("default")))
69 #else
70 #  define CV_EXPORTS
71 #endif
72 
73 #ifndef CV_EXTERN_C
74 #  ifdef __cplusplus
75 #    define CV_EXTERN_C extern "C"
76 #  else
77 #    define CV_EXTERN_C
78 #  endif
79 #endif
80 
81 /* special informative macros for wrapper generators */
82 #define CV_EXPORTS_W CV_EXPORTS
83 #define CV_EXPORTS_W_SIMPLE CV_EXPORTS
84 #define CV_EXPORTS_AS(synonym) CV_EXPORTS
85 #define CV_EXPORTS_W_MAP CV_EXPORTS
86 #define CV_IN_OUT
87 #define CV_OUT
88 #define CV_PROP
89 #define CV_PROP_RW
90 #define CV_WRAP
91 #define CV_WRAP_AS(synonym)
92 
93 /****************************************************************************************\
94 *                                  Matrix type (Mat)                                     *
95 \****************************************************************************************/
96 
97 #define CV_CN_MAX     512
98 #define CV_CN_SHIFT   3
99 #define CV_DEPTH_MAX  (1 << CV_CN_SHIFT)
100 
101 #define CV_8U   0
102 #define CV_8S   1
103 #define CV_16U  2
104 #define CV_16S  3
105 #define CV_32S  4
106 #define CV_32F  5
107 #define CV_64F  6
108 #define CV_USRTYPE1 7
109 
110 #define CV_MAT_DEPTH_MASK       (CV_DEPTH_MAX - 1)
111 #define CV_MAT_DEPTH(flags)     ((flags) & CV_MAT_DEPTH_MASK)
112 
113 #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
114 #define CV_MAKE_TYPE CV_MAKETYPE
115 
116 #define CV_8UC1 CV_MAKETYPE(CV_8U,1)
117 #define CV_8UC2 CV_MAKETYPE(CV_8U,2)
118 #define CV_8UC3 CV_MAKETYPE(CV_8U,3)
119 #define CV_8UC4 CV_MAKETYPE(CV_8U,4)
120 #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
121 
122 #define CV_8SC1 CV_MAKETYPE(CV_8S,1)
123 #define CV_8SC2 CV_MAKETYPE(CV_8S,2)
124 #define CV_8SC3 CV_MAKETYPE(CV_8S,3)
125 #define CV_8SC4 CV_MAKETYPE(CV_8S,4)
126 #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
127 
128 #define CV_16UC1 CV_MAKETYPE(CV_16U,1)
129 #define CV_16UC2 CV_MAKETYPE(CV_16U,2)
130 #define CV_16UC3 CV_MAKETYPE(CV_16U,3)
131 #define CV_16UC4 CV_MAKETYPE(CV_16U,4)
132 #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
133 
134 #define CV_16SC1 CV_MAKETYPE(CV_16S,1)
135 #define CV_16SC2 CV_MAKETYPE(CV_16S,2)
136 #define CV_16SC3 CV_MAKETYPE(CV_16S,3)
137 #define CV_16SC4 CV_MAKETYPE(CV_16S,4)
138 #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
139 
140 #define CV_32SC1 CV_MAKETYPE(CV_32S,1)
141 #define CV_32SC2 CV_MAKETYPE(CV_32S,2)
142 #define CV_32SC3 CV_MAKETYPE(CV_32S,3)
143 #define CV_32SC4 CV_MAKETYPE(CV_32S,4)
144 #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
145 
146 #define CV_32FC1 CV_MAKETYPE(CV_32F,1)
147 #define CV_32FC2 CV_MAKETYPE(CV_32F,2)
148 #define CV_32FC3 CV_MAKETYPE(CV_32F,3)
149 #define CV_32FC4 CV_MAKETYPE(CV_32F,4)
150 #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
151 
152 #define CV_64FC1 CV_MAKETYPE(CV_64F,1)
153 #define CV_64FC2 CV_MAKETYPE(CV_64F,2)
154 #define CV_64FC3 CV_MAKETYPE(CV_64F,3)
155 #define CV_64FC4 CV_MAKETYPE(CV_64F,4)
156 #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
157 
158 #define CV_MAT_CN_MASK          ((CV_CN_MAX - 1) << CV_CN_SHIFT)
159 #define CV_MAT_CN(flags)        ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
160 #define CV_MAT_TYPE_MASK        (CV_DEPTH_MAX*CV_CN_MAX - 1)
161 #define CV_MAT_TYPE(flags)      ((flags) & CV_MAT_TYPE_MASK)
162 #define CV_MAT_CONT_FLAG_SHIFT  14
163 #define CV_MAT_CONT_FLAG        (1 << CV_MAT_CONT_FLAG_SHIFT)
164 #define CV_IS_MAT_CONT(flags)   ((flags) & CV_MAT_CONT_FLAG)
165 #define CV_IS_CONT_MAT          CV_IS_MAT_CONT
166 #define CV_SUBMAT_FLAG_SHIFT    15
167 #define CV_SUBMAT_FLAG          (1 << CV_SUBMAT_FLAG_SHIFT)
168 #define CV_IS_SUBMAT(flags)     ((flags) & CV_MAT_SUBMAT_FLAG)
169 
170 /* Size of each channel item,
171    0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
172 #define CV_ELEM_SIZE1(type) \
173     ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
174 
175 /* 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
176 #define CV_ELEM_SIZE(type) \
177     (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
178 
179 #ifndef MIN
180 #  define MIN(a,b)  ((a) > (b) ? (b) : (a))
181 #endif
182 
183 #ifndef MAX
184 #  define MAX(a,b)  ((a) < (b) ? (b) : (a))
185 #endif
186 
187 /****************************************************************************************\
188 *          exchange-add operation for atomic operations on reference counters            *
189 \****************************************************************************************/
190 
191 #if defined __INTEL_COMPILER && !(defined WIN32 || defined _WIN32)
192    // atomic increment on the linux version of the Intel(tm) compiler
193 #  define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd(const_cast<void*>(reinterpret_cast<volatile void*>(addr)), delta)
194 #elif defined __GNUC__
195 #  if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__)
196 #    ifdef __ATOMIC_ACQ_REL
197 #      define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
198 #    else
199 #      define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
200 #    endif
201 #  else
202 #    if defined __ATOMIC_ACQ_REL && !defined __clang__
203        // version for gcc >= 4.7
204 #      define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
205 #    else
206 #      define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
207 #    endif
208 #  endif
209 #elif defined _MSC_VER && !defined RC_INVOKED
210 #  include <intrin.h>
211 #  define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
212 #else
CV_XADD(int * addr,int delta)213    CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
214 #endif
215 
216 
217 /****************************************************************************************\
218 *                                  CV_NORETURN attribute                                 *
219 \****************************************************************************************/
220 
221 #ifndef CV_NORETURN
222 #  if defined(__GNUC__)
223 #    define CV_NORETURN __attribute__((__noreturn__))
224 #  elif defined(_MSC_VER) && (_MSC_VER >= 1300)
225 #    define CV_NORETURN __declspec(noreturn)
226 #  else
227 #    define CV_NORETURN /* nothing by default */
228 #  endif
229 #endif
230 
231 #endif // __OPENCV_CORE_CVDEF_H__
232