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 // Third party copyrights are property of their respective owners.
17 //
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
20 //
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
23 //
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other materials provided with the distribution.
27 //
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
30 //
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
41 //
42 //M*/
43
44 #ifndef __OPENCV_CORE_PRIVATE_HPP__
45 #define __OPENCV_CORE_PRIVATE_HPP__
46
47 #ifndef __OPENCV_BUILD
48 # error this is a private header which should not be used from outside of the OpenCV library
49 #endif
50
51 #include "opencv2/core.hpp"
52 #include "cvconfig.h"
53
54 #ifdef HAVE_EIGEN
55 # if defined __GNUC__ && defined __APPLE__
56 # pragma GCC diagnostic ignored "-Wshadow"
57 # endif
58 # include <Eigen/Core>
59 # include "opencv2/core/eigen.hpp"
60 #endif
61
62 #ifdef HAVE_TBB
63 # include "tbb/tbb_stddef.h"
64 # if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
65 # include "tbb/tbb.h"
66 # include "tbb/task.h"
67 # undef min
68 # undef max
69 # else
70 # undef HAVE_TBB
71 # endif
72 #endif
73
74 //! @cond IGNORED
75
76 namespace cv
77 {
78 #ifdef HAVE_TBB
79
80 typedef tbb::blocked_range<int> BlockedRange;
81
82 template<typename Body> static inline
parallel_for(const BlockedRange & range,const Body & body)83 void parallel_for( const BlockedRange& range, const Body& body )
84 {
85 tbb::parallel_for(range, body);
86 }
87
88 typedef tbb::split Split;
89
90 template<typename Body> static inline
parallel_reduce(const BlockedRange & range,Body & body)91 void parallel_reduce( const BlockedRange& range, Body& body )
92 {
93 tbb::parallel_reduce(range, body);
94 }
95
96 typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
97 #else
98 class BlockedRange
99 {
100 public:
101 BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
102 BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
103 int begin() const { return _begin; }
104 int end() const { return _end; }
105 int grainsize() const { return _grainsize; }
106
107 protected:
108 int _begin, _end, _grainsize;
109 };
110
111 template<typename Body> static inline
112 void parallel_for( const BlockedRange& range, const Body& body )
113 {
114 body(range);
115 }
116 typedef std::vector<Rect> ConcurrentRectVector;
117
118 class Split {};
119
120 template<typename Body> static inline
121 void parallel_reduce( const BlockedRange& range, Body& body )
122 {
123 body(range);
124 }
125 #endif
126
127 // Returns a static string if there is a parallel framework,
128 // NULL otherwise.
129 CV_EXPORTS const char* currentParallelFramework();
130 } //namespace cv
131
132 /****************************************************************************************\
133 * Common declarations *
134 \****************************************************************************************/
135
136 /* the alignment of all the allocated buffers */
137 #define CV_MALLOC_ALIGN 16
138
139 /* IEEE754 constants and macros */
140 #define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0))
141 #define CV_TOGGLE_DBL(x) ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0))
142
cvAlignPtr(const void * ptr,int align=32)143 static inline void* cvAlignPtr( const void* ptr, int align = 32 )
144 {
145 CV_DbgAssert ( (align & (align-1)) == 0 );
146 return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) );
147 }
148
cvAlign(int size,int align)149 static inline int cvAlign( int size, int align )
150 {
151 CV_DbgAssert( (align & (align-1)) == 0 && size < INT_MAX );
152 return (size + align - 1) & -align;
153 }
154
155 #ifdef IPL_DEPTH_8U
cvGetMatSize(const CvMat * mat)156 static inline cv::Size cvGetMatSize( const CvMat* mat )
157 {
158 return cv::Size(mat->cols, mat->rows);
159 }
160 #endif
161
162 namespace cv
163 {
164 CV_EXPORTS void scalarToRawData(const cv::Scalar& s, void* buf, int type, int unroll_to = 0);
165 }
166
167 // property implementation macros
168
169 #define CV_IMPL_PROPERTY_RO(type, name, member) \
170 inline type get##name() const { return member; }
171
172 #define CV_HELP_IMPL_PROPERTY(r_type, w_type, name, member) \
173 CV_IMPL_PROPERTY_RO(r_type, name, member) \
174 inline void set##name(w_type val) { member = val; }
175
176 #define CV_HELP_WRAP_PROPERTY(r_type, w_type, name, internal_name, internal_obj) \
177 r_type get##name() const { return internal_obj.get##internal_name(); } \
178 void set##name(w_type val) { internal_obj.set##internal_name(val); }
179
180 #define CV_IMPL_PROPERTY(type, name, member) CV_HELP_IMPL_PROPERTY(type, type, name, member)
181 #define CV_IMPL_PROPERTY_S(type, name, member) CV_HELP_IMPL_PROPERTY(type, const type &, name, member)
182
183 #define CV_WRAP_PROPERTY(type, name, internal_name, internal_obj) CV_HELP_WRAP_PROPERTY(type, type, name, internal_name, internal_obj)
184 #define CV_WRAP_PROPERTY_S(type, name, internal_name, internal_obj) CV_HELP_WRAP_PROPERTY(type, const type &, name, internal_name, internal_obj)
185
186 #define CV_WRAP_SAME_PROPERTY(type, name, internal_obj) CV_WRAP_PROPERTY(type, name, name, internal_obj)
187 #define CV_WRAP_SAME_PROPERTY_S(type, name, internal_obj) CV_WRAP_PROPERTY_S(type, name, name, internal_obj)
188
189 /****************************************************************************************\
190 * Structures and macros for integration with IPP *
191 \****************************************************************************************/
192
193 #ifdef HAVE_IPP
194 # include "ipp.h"
195
196 # define IPP_VERSION_X100 (IPP_VERSION_MAJOR * 100 + IPP_VERSION_MINOR)
197
198 #define IPP_ALIGN 32 // required for AVX optimization
199
200 #define setIppErrorStatus() cv::ipp::setIppStatus(-1, CV_Func, __FILE__, __LINE__)
201
ippiSize(int width,int height)202 static inline IppiSize ippiSize(int width, int height)
203 {
204 IppiSize size = { width, height };
205 return size;
206 }
207
ippiSize(const cv::Size & _size)208 static inline IppiSize ippiSize(const cv::Size & _size)
209 {
210 IppiSize size = { _size.width, _size.height };
211 return size;
212 }
213
ippiGetBorderType(int borderTypeNI)214 static inline IppiBorderType ippiGetBorderType(int borderTypeNI)
215 {
216 return borderTypeNI == cv::BORDER_CONSTANT ? ippBorderConst :
217 borderTypeNI == cv::BORDER_WRAP ? ippBorderWrap :
218 borderTypeNI == cv::BORDER_REPLICATE ? ippBorderRepl :
219 borderTypeNI == cv::BORDER_REFLECT_101 ? ippBorderMirror :
220 borderTypeNI == cv::BORDER_REFLECT ? ippBorderMirrorR : (IppiBorderType)-1;
221 }
222
ippiGetDataType(int depth)223 static inline IppDataType ippiGetDataType(int depth)
224 {
225 return depth == CV_8U ? ipp8u :
226 depth == CV_8S ? ipp8s :
227 depth == CV_16U ? ipp16u :
228 depth == CV_16S ? ipp16s :
229 depth == CV_32S ? ipp32s :
230 depth == CV_32F ? ipp32f :
231 depth == CV_64F ? ipp64f : (IppDataType)-1;
232 }
233
234 #else
235 # define IPP_VERSION_X100 0
236 #endif
237
238 #define CV_IPP_CHECK_COND (cv::ipp::useIPP())
239 #define CV_IPP_CHECK() if(CV_IPP_CHECK_COND)
240
241 #ifndef IPPI_CALL
242 # define IPPI_CALL(func) CV_Assert((func) >= 0)
243 #endif
244
245 /* IPP-compatible return codes */
246 typedef enum CvStatus
247 {
248 CV_BADMEMBLOCK_ERR = -113,
249 CV_INPLACE_NOT_SUPPORTED_ERR= -112,
250 CV_UNMATCHED_ROI_ERR = -111,
251 CV_NOTFOUND_ERR = -110,
252 CV_BADCONVERGENCE_ERR = -109,
253
254 CV_BADDEPTH_ERR = -107,
255 CV_BADROI_ERR = -106,
256 CV_BADHEADER_ERR = -105,
257 CV_UNMATCHED_FORMATS_ERR = -104,
258 CV_UNSUPPORTED_COI_ERR = -103,
259 CV_UNSUPPORTED_CHANNELS_ERR = -102,
260 CV_UNSUPPORTED_DEPTH_ERR = -101,
261 CV_UNSUPPORTED_FORMAT_ERR = -100,
262
263 CV_BADARG_ERR = -49, //ipp comp
264 CV_NOTDEFINED_ERR = -48, //ipp comp
265
266 CV_BADCHANNELS_ERR = -47, //ipp comp
267 CV_BADRANGE_ERR = -44, //ipp comp
268 CV_BADSTEP_ERR = -29, //ipp comp
269
270 CV_BADFLAG_ERR = -12,
271 CV_DIV_BY_ZERO_ERR = -11, //ipp comp
272 CV_BADCOEF_ERR = -10,
273
274 CV_BADFACTOR_ERR = -7,
275 CV_BADPOINT_ERR = -6,
276 CV_BADSCALE_ERR = -4,
277 CV_OUTOFMEM_ERR = -3,
278 CV_NULLPTR_ERR = -2,
279 CV_BADSIZE_ERR = -1,
280 CV_NO_ERR = 0,
281 CV_OK = CV_NO_ERR
282 }
283 CvStatus;
284
285 #ifdef HAVE_TEGRA_OPTIMIZATION
286 namespace tegra {
287
288 CV_EXPORTS bool useTegra();
289 CV_EXPORTS void setUseTegra(bool flag);
290
291 }
292 #endif
293
294 //! @endcond
295
296 #endif // __OPENCV_CORE_PRIVATE_HPP__
297