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 #ifdef HAVE_CVCONFIG_H
50 #include "opencv2/core/core.hpp"
51 #include "opencv2/core/core_c.h"
52 #include "opencv2/core/internal.hpp"
63 #ifdef HAVE_TEGRA_OPTIMIZATION
64 #include "opencv2/core/core_tegra.hpp"
66 #define GET_OPTIMIZED(func) (func)
73 extern const float g_8x32fTab[];
74 #define CV_8TO32F(x) cv::g_8x32fTab[(x)+128]
76 extern const ushort g_8x16uSqrTab[];
77 #define CV_SQR_8U(x) cv::g_8x16uSqrTab[(x)+255]
79 extern const char* g_HersheyGlyphs[];
81 extern const uchar g_Saturate8u[];
82 #define CV_FAST_CAST_8U(t) (assert(-256 <= (t) && (t) <= 512), cv::g_Saturate8u[(t)+256])
83 #define CV_MIN_8U(a,b) ((a) - CV_FAST_CAST_8U((a) - (b)))
84 #define CV_MAX_8U(a,b) ((a) + CV_FAST_CAST_8U((b) - (a)))
87 #if defined WIN32 || defined _WIN32
88 void deleteThreadAllocData();
89 void deleteThreadRNGData();
92 template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
97 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a + b); }
100 template<typename T1, typename T2=T1, typename T3=T1> struct OpSub
105 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a - b); }
108 template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
113 T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(b - a); }
116 template<typename T> struct OpMin
121 T operator ()(const T a, const T b) const { return std::min(a, b); }
124 template<typename T> struct OpMax
129 T operator ()(const T a, const T b) const { return std::max(a, b); }
132 inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
134 return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
135 Size(m1.cols*widthScale, m1.rows);
138 inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
140 return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
141 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
144 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
145 const Mat& m3, int widthScale=1 )
147 return (m1.flags & m2.flags & m3.flags & Mat::CONTINUOUS_FLAG) != 0 ?
148 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
151 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
152 const Mat& m3, const Mat& m4,
155 return (m1.flags & m2.flags & m3.flags & m4.flags & Mat::CONTINUOUS_FLAG) != 0 ?
156 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
159 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
160 const Mat& m3, const Mat& m4,
161 const Mat& m5, int widthScale=1 )
163 return (m1.flags & m2.flags & m3.flags & m4.flags & m5.flags & Mat::CONTINUOUS_FLAG) != 0 ?
164 Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
169 size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
172 extern volatile bool USE_SSE2;
173 extern volatile bool USE_SSE4_2;
174 extern volatile bool USE_AVX;
176 enum { BLOCK_SIZE = 1024 };
179 static inline IppiSize ippiSize(int width, int height) { IppiSize sz = { width, height}; return sz; }
180 static inline IppiSize ippiSize(Size _sz) { IppiSize sz = { _sz.width, _sz.height}; return sz; }
183 #if defined HAVE_IPP && (IPP_VERSION_MAJOR >= 7)
184 #define ARITHM_USE_IPP 1
185 #define IF_IPP(then_call, else_call) then_call
187 #define ARITHM_USE_IPP 0
188 #define IF_IPP(then_call, else_call) else_call
191 inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind)
193 if( sc.dims > 2 || (sc.cols != 1 && sc.rows != 1) || !sc.isContinuous() )
195 int cn = CV_MAT_CN(atype);
196 if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
198 return sc.size() == Size(1, 1) || sc.size() == Size(1, cn) || sc.size() == Size(cn, 1) ||
199 (sc.size() == Size(1, 4) && sc.type() == CV_64F && cn <= 4);
202 void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
206 #endif /*_CXCORE_INTERNAL_H_*/