1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #ifndef __OPENCV_PRECOMP_H__
44 #define __OPENCV_PRECOMP_H__
46 #include "opencv2/opencv_modules.hpp"
49 #include "opencv2/core/utility.hpp"
50 #include "opencv2/core/core_c.h"
51 #include "opencv2/core/cuda.hpp"
52 #include "opencv2/core/opengl.hpp"
54 #include "opencv2/core/private.hpp"
55 #include "opencv2/core/private.cuda.hpp"
56 #include "opencv2/core/ocl.hpp"
67 #ifdef HAVE_TEGRA_OPTIMIZATION
68 #include "opencv2/core/core_tegra.hpp"
70 #define GET_OPTIMIZED(func) (func)
76 typedef void (*BinaryFunc)(const uchar* src1, size_t step1,
77 const uchar* src2, size_t step2,
78 uchar* dst, size_t step, Size sz,
81 BinaryFunc getConvertFunc(int sdepth, int ddepth);
82 BinaryFunc getCopyMaskFunc(size_t esz);
84 /* default memory block for sparse array elements */
85 #define CV_SPARSE_MAT_BLOCK (1<<12)
87 /* initial hash table size */
88 #define CV_SPARSE_HASH_SIZE0 (1<<10)
90 /* maximal average node_count/hash_size ratio beyond which hash table is resized */
91 #define CV_SPARSE_HASH_RATIO 3
96 extern const float g_8x32fTab[];
97 #define CV_8TO32F(x) cv::g_8x32fTab[(x)+128]
99 extern const ushort g_8x16uSqrTab[];
100 #define CV_SQR_8U(x) cv::g_8x16uSqrTab[(x)+255]
102 extern const uchar g_Saturate8u[];
103 #define CV_FAST_CAST_8U(t) (assert(-256 <= (t) && (t) <= 512), cv::g_Saturate8u[(t)+256])
104 #define CV_MIN_8U(a,b) ((a) - CV_FAST_CAST_8U((a) - (b)))
105 #define CV_MAX_8U(a,b) ((a) + CV_FAST_CAST_8U((b) - (a)))
108 #if defined WIN32 || defined _WIN32
109 void deleteThreadAllocData();
112 template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
117 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a + b); }
120 template<typename T1, typename T2=T1, typename T3=T1> struct OpSub
125 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a - b); }
128 template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
133 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(b - a); }
136 template<typename T> struct OpMin
141 T operator ()(const T a, const T b) const { return std::min(a, b); }
144 template<typename T> struct OpMax
149 T operator ()(const T a, const T b) const { return std::max(a, b); }
152 inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
154 return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
155 Size(m1.cols*widthScale, m1.rows);
158 inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
160 return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
161 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
164 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
165 const Mat& m3, int widthScale=1 )
167 return (m1.flags & m2.flags & m3.flags & Mat::CONTINUOUS_FLAG) != 0 ?
168 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
171 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
172 const Mat& m3, const Mat& m4,
175 return (m1.flags & m2.flags & m3.flags & m4.flags & Mat::CONTINUOUS_FLAG) != 0 ?
176 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
179 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
180 const Mat& m3, const Mat& m4,
181 const Mat& m5, int widthScale=1 )
183 return (m1.flags & m2.flags & m3.flags & m4.flags & m5.flags & Mat::CONTINUOUS_FLAG) != 0 ?
184 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
189 size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
192 extern volatile bool USE_SSE2;
193 extern volatile bool USE_SSE4_2;
194 extern volatile bool USE_AVX;
196 enum { BLOCK_SIZE = 1024 };
198 #if defined HAVE_IPP && (IPP_VERSION_MAJOR >= 7)
199 #define ARITHM_USE_IPP 1
201 #define ARITHM_USE_IPP 0
204 inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind)
206 if( sc.dims > 2 || !sc.isContinuous() )
209 if(sz.width != 1 && sz.height != 1)
211 int cn = CV_MAT_CN(atype);
212 if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
214 return sz == Size(1, 1) || sz == Size(1, cn) || sz == Size(cn, 1) ||
215 (sz == Size(1, 4) && sc.type() == CV_64F && cn <= 4);
218 inline bool checkScalar(InputArray sc, int atype, int sckind, int akind)
220 if( sc.dims() > 2 || !sc.isContinuous() )
223 if(sz.width != 1 && sz.height != 1)
225 int cn = CV_MAT_CN(atype);
226 if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
228 return sz == Size(1, 1) || sz == Size(1, cn) || sz == Size(cn, 1) ||
229 (sz == Size(1, 4) && sc.type() == CV_64F && cn <= 4);
232 void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
236 CoreTLSData() : device(0), useOpenCL(-1)
242 int useOpenCL; // 1 - use, 0 - do not use, -1 - auto/not initialized
245 extern TLSData<CoreTLSData> coreTlsData;
247 #if defined(BUILD_SHARED_LIBS)
248 #if defined WIN32 || defined _WIN32 || defined WINCE
249 #define CL_RUNTIME_EXPORT __declspec(dllexport)
250 #elif defined __GNUC__ && __GNUC__ >= 4
251 #define CL_RUNTIME_EXPORT __attribute__ ((visibility ("default")))
253 #define CL_RUNTIME_EXPORT
256 #define CL_RUNTIME_EXPORT
259 extern bool __termination; // skip some cleanups, because process is terminating
260 // (for example, if ExitProcess() was already called)
264 #endif /*_CXCORE_INTERNAL_H_*/