Merge pull request #1263 from abidrahmank:pyCLAHE_24
[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 #include "cvconfig.h"
47
48 #include "opencv2/core/core.hpp"
49 #include "opencv2/core/core_c.h"
50 #include "opencv2/core/internal.hpp"
51
52 #include <assert.h>
53 #include <ctype.h>
54 #include <float.h>
55 #include <limits.h>
56 #include <math.h>
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60
61 #ifdef HAVE_TEGRA_OPTIMIZATION
62 #include "opencv2/core/core_tegra.hpp"
63 #else
64 #define GET_OPTIMIZED(func) (func)
65 #endif
66
67 namespace cv
68 {
69
70 // -128.f ... 255.f
71 extern const float g_8x32fTab[];
72 #define CV_8TO32F(x)  cv::g_8x32fTab[(x)+128]
73
74 extern const ushort g_8x16uSqrTab[];
75 #define CV_SQR_8U(x)  cv::g_8x16uSqrTab[(x)+255]
76
77 extern const char* g_HersheyGlyphs[];
78
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)))
83
84
85 #if defined WIN32 || defined _WIN32
86 void deleteThreadAllocData();
87 void deleteThreadRNGData();
88 #endif
89
90 template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
91 {
92     typedef T1 type1;
93     typedef T2 type2;
94     typedef T3 rtype;
95     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a + b); }
96 };
97
98 template<typename T1, typename T2=T1, typename T3=T1> struct OpSub
99 {
100     typedef T1 type1;
101     typedef T2 type2;
102     typedef T3 rtype;
103     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a - b); }
104 };
105
106 template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
107 {
108     typedef T1 type1;
109     typedef T2 type2;
110     typedef T3 rtype;
111     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(b - a); }
112 };
113
114 template<typename T> struct OpMin
115 {
116     typedef T type1;
117     typedef T type2;
118     typedef T rtype;
119     T operator ()(const T a, const T b) const { return std::min(a, b); }
120 };
121
122 template<typename T> struct OpMax
123 {
124     typedef T type1;
125     typedef T type2;
126     typedef T rtype;
127     T operator ()(const T a, const T b) const { return std::max(a, b); }
128 };
129
130 inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
131 {
132     return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
133         Size(m1.cols*widthScale, m1.rows);
134 }
135
136 inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
137 {
138     return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
139         Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
140 }
141
142 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
143                                const Mat& m3, int widthScale=1 )
144 {
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);
147 }
148
149 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
150                                const Mat& m3, const Mat& m4,
151                                int widthScale=1 )
152 {
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);
155 }
156
157 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
158                                const Mat& m3, const Mat& m4,
159                                const Mat& m5, int widthScale=1 )
160 {
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);
163 }
164
165 struct NoVec
166 {
167     size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
168 };
169
170 extern volatile bool USE_SSE2;
171 extern volatile bool USE_SSE4_2;
172 extern volatile bool USE_AVX;
173
174 enum { BLOCK_SIZE = 1024 };
175
176 #ifdef HAVE_IPP
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; }
179 #endif
180
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
184 #else
185 #define ARITHM_USE_IPP 0
186 #define IF_IPP(then_call, else_call) else_call
187 #endif
188
189 inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind)
190 {
191     if( sc.dims > 2 || (sc.cols != 1 && sc.rows != 1) || !sc.isContinuous() )
192         return false;
193     int cn = CV_MAT_CN(atype);
194     if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
195         return false;
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);
198 }
199
200 void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
201
202 }
203
204 #endif /*_CXCORE_INTERNAL_H_*/