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__
48 #include "opencv2/core/core.hpp"
49 #include "opencv2/core/core_c.h"
50 #include "opencv2/core/internal.hpp"
61 #ifdef HAVE_TEGRA_OPTIMIZATION
62 #include "opencv2/core/core_tegra.hpp"
64 #define GET_OPTIMIZED(func) (func)
71 extern const float g_8x32fTab[];
72 #define CV_8TO32F(x) cv::g_8x32fTab[(x)+128]
74 extern const ushort g_8x16uSqrTab[];
75 #define CV_SQR_8U(x) cv::g_8x16uSqrTab[(x)+255]
77 extern const char* g_HersheyGlyphs[];
79 extern const uchar g_Saturate8u[];
80 #define CV_FAST_CAST_8U(t) (assert(-256 <= (t) && (t) <= 512), cv::g_Saturate8u[(t)+256])
81 #define CV_MIN_8U(a,b) ((a) - CV_FAST_CAST_8U((a) - (b)))
82 #define CV_MAX_8U(a,b) ((a) + CV_FAST_CAST_8U((b) - (a)))
85 #if defined WIN32 || defined _WIN32
86 void deleteThreadAllocData();
87 void deleteThreadRNGData();
90 template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
95 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a + b); }
98 template<typename T1, typename T2=T1, typename T3=T1> struct OpSub
103 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a - b); }
106 template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
111 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(b - a); }
114 template<typename T> struct OpMin
119 T operator ()(const T a, const T b) const { return std::min(a, b); }
122 template<typename T> struct OpMax
127 T operator ()(const T a, const T b) const { return std::max(a, b); }
130 inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
132 return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
133 Size(m1.cols*widthScale, m1.rows);
136 inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
138 return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
139 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
142 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
143 const Mat& m3, int widthScale=1 )
145 return (m1.flags & m2.flags & m3.flags & Mat::CONTINUOUS_FLAG) != 0 ?
146 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
149 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
150 const Mat& m3, const Mat& m4,
153 return (m1.flags & m2.flags & m3.flags & m4.flags & Mat::CONTINUOUS_FLAG) != 0 ?
154 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
157 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
158 const Mat& m3, const Mat& m4,
159 const Mat& m5, int widthScale=1 )
161 return (m1.flags & m2.flags & m3.flags & m4.flags & m5.flags & Mat::CONTINUOUS_FLAG) != 0 ?
162 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
167 size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
170 extern volatile bool USE_SSE2;
171 extern volatile bool USE_SSE4_2;
172 extern volatile bool USE_AVX;
174 enum { BLOCK_SIZE = 1024 };
177 static inline IppiSize ippiSize(int width, int height) { IppiSize sz = { width, height}; return sz; }
178 static inline IppiSize ippiSize(Size _sz) { IppiSize sz = { _sz.width, _sz.height}; return sz; }
181 #if defined HAVE_IPP && (IPP_VERSION_MAJOR >= 7)
182 #define ARITHM_USE_IPP 1
183 #define IF_IPP(then_call, else_call) then_call
185 #define ARITHM_USE_IPP 0
186 #define IF_IPP(then_call, else_call) else_call
189 inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind)
191 if( sc.dims > 2 || (sc.cols != 1 && sc.rows != 1) || !sc.isContinuous() )
193 int cn = CV_MAT_CN(atype);
194 if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
196 return sc.size() == Size(1, 1) || sc.size() == Size(1, cn) || sc.size() == Size(cn, 1) ||
197 (sc.size() == Size(1, 4) && sc.type() == CV_64F && cn <= 4);
200 void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
204 #endif /*_CXCORE_INTERNAL_H_*/