CLAHE Python bindings
[profile/ivi/opencv.git] / modules / core / src / precomp.hpp
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 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
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.
26 //
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.
29 //
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.
40 //
41 //M*/
42
43 #ifndef __OPENCV_PRECOMP_H__
44 #define __OPENCV_PRECOMP_H__
45
46 #ifdef HAVE_CVCONFIG_H
47 #include "cvconfig.h"
48 #endif
49
50 #include "opencv2/core/core.hpp"
51 #include "opencv2/core/core_c.h"
52 #include "opencv2/core/internal.hpp"
53
54 #include <assert.h>
55 #include <ctype.h>
56 #include <float.h>
57 #include <limits.h>
58 #include <math.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62
63 #ifdef HAVE_TEGRA_OPTIMIZATION
64 #include "opencv2/core/core_tegra.hpp"
65 #else
66 #define GET_OPTIMIZED(func) (func)
67 #endif
68
69 namespace cv
70 {
71
72 // -128.f ... 255.f
73 extern const float g_8x32fTab[];
74 #define CV_8TO32F(x)  cv::g_8x32fTab[(x)+128]
75
76 extern const ushort g_8x16uSqrTab[];
77 #define CV_SQR_8U(x)  cv::g_8x16uSqrTab[(x)+255]
78
79 extern const char* g_HersheyGlyphs[];
80
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)))
85
86
87 #if defined WIN32 || defined _WIN32
88 void deleteThreadAllocData();
89 void deleteThreadRNGData();
90 #endif
91
92 template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
93 {
94     typedef T1 type1;
95     typedef T2 type2;
96     typedef T3 rtype;
97     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a + b); }
98 };
99
100 template<typename T1, typename T2=T1, typename T3=T1> struct OpSub
101 {
102     typedef T1 type1;
103     typedef T2 type2;
104     typedef T3 rtype;
105     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a - b); }
106 };
107
108 template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
109 {
110     typedef T1 type1;
111     typedef T2 type2;
112     typedef T3 rtype;
113     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(b - a); }
114 };
115
116 template<typename T> struct OpMin
117 {
118     typedef T type1;
119     typedef T type2;
120     typedef T rtype;
121     T operator ()(const T a, const T b) const { return std::min(a, b); }
122 };
123
124 template<typename T> struct OpMax
125 {
126     typedef T type1;
127     typedef T type2;
128     typedef T rtype;
129     T operator ()(const T a, const T b) const { return std::max(a, b); }
130 };
131
132 inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
133 {
134     return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
135         Size(m1.cols*widthScale, m1.rows);
136 }
137
138 inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
139 {
140     return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
141         Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
142 }
143
144 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
145                                const Mat& m3, int widthScale=1 )
146 {
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);
149 }
150
151 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
152                                const Mat& m3, const Mat& m4,
153                                int widthScale=1 )
154 {
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);
157 }
158
159 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
160                                const Mat& m3, const Mat& m4,
161                                const Mat& m5, int widthScale=1 )
162 {
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);
165 }
166
167 struct NoVec
168 {
169     size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
170 };
171
172 extern volatile bool USE_SSE2;
173 extern volatile bool USE_SSE4_2;
174 extern volatile bool USE_AVX;
175
176 enum { BLOCK_SIZE = 1024 };
177
178 #ifdef HAVE_IPP
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; }
181 #endif
182
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
186 #else
187 #define ARITHM_USE_IPP 0
188 #define IF_IPP(then_call, else_call) else_call
189 #endif
190
191 inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind)
192 {
193     if( sc.dims > 2 || (sc.cols != 1 && sc.rows != 1) || !sc.isContinuous() )
194         return false;
195     int cn = CV_MAT_CN(atype);
196     if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
197         return false;
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);
200 }
201
202 void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
203
204 }
205
206 #endif /*_CXCORE_INTERNAL_H_*/