removed duplicated Hershey fonts
[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 "opencv2/opencv_modules.hpp"
47 #include "cvconfig.h"
48
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"
53
54 #include "opencv2/core/private.hpp"
55 #include "opencv2/core/private.cuda.hpp"
56 #include "opencv2/core/ocl.hpp"
57
58 #include <assert.h>
59 #include <ctype.h>
60 #include <float.h>
61 #include <limits.h>
62 #include <math.h>
63 #include <stdio.h>
64 #include <stdlib.h>
65 #include <string.h>
66
67 #ifdef HAVE_TEGRA_OPTIMIZATION
68 #include "opencv2/core/core_tegra.hpp"
69 #else
70 #define GET_OPTIMIZED(func) (func)
71 #endif
72
73 namespace cv
74 {
75
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,
79                        void*);
80
81 BinaryFunc getConvertFunc(int sdepth, int ddepth);
82 BinaryFunc getCopyMaskFunc(size_t esz);
83
84 /* default memory block for sparse array elements */
85 #define  CV_SPARSE_MAT_BLOCK     (1<<12)
86
87 /* initial hash table size */
88 #define  CV_SPARSE_HASH_SIZE0    (1<<10)
89
90 /* maximal average node_count/hash_size ratio beyond which hash table is resized */
91 #define  CV_SPARSE_HASH_RATIO    3
92
93
94
95 // -128.f ... 255.f
96 extern const float g_8x32fTab[];
97 #define CV_8TO32F(x)  cv::g_8x32fTab[(x)+128]
98
99 extern const ushort g_8x16uSqrTab[];
100 #define CV_SQR_8U(x)  cv::g_8x16uSqrTab[(x)+255]
101
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)))
106
107
108 #if defined WIN32 || defined _WIN32
109 void deleteThreadAllocData();
110 #endif
111
112 template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
113 {
114     typedef T1 type1;
115     typedef T2 type2;
116     typedef T3 rtype;
117     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a + b); }
118 };
119
120 template<typename T1, typename T2=T1, typename T3=T1> struct OpSub
121 {
122     typedef T1 type1;
123     typedef T2 type2;
124     typedef T3 rtype;
125     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(a - b); }
126 };
127
128 template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
129 {
130     typedef T1 type1;
131     typedef T2 type2;
132     typedef T3 rtype;
133     T3 operator ()(const T1 a, const T2 b) const { return saturate_cast<T3>(b - a); }
134 };
135
136 template<typename T> struct OpMin
137 {
138     typedef T type1;
139     typedef T type2;
140     typedef T rtype;
141     T operator ()(const T a, const T b) const { return std::min(a, b); }
142 };
143
144 template<typename T> struct OpMax
145 {
146     typedef T type1;
147     typedef T type2;
148     typedef T rtype;
149     T operator ()(const T a, const T b) const { return std::max(a, b); }
150 };
151
152 inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
153 {
154     return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
155         Size(m1.cols*widthScale, m1.rows);
156 }
157
158 inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
159 {
160     return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
161         Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
162 }
163
164 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
165                                const Mat& m3, int widthScale=1 )
166 {
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);
169 }
170
171 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
172                                const Mat& m3, const Mat& m4,
173                                int widthScale=1 )
174 {
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);
177 }
178
179 inline Size getContinuousSize( const Mat& m1, const Mat& m2,
180                                const Mat& m3, const Mat& m4,
181                                const Mat& m5, int widthScale=1 )
182 {
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);
185 }
186
187 struct NoVec
188 {
189     size_t operator()(const void*, const void*, void*, size_t) const { return 0; }
190 };
191
192 extern volatile bool USE_SSE2;
193 extern volatile bool USE_SSE4_2;
194 extern volatile bool USE_AVX;
195
196 enum { BLOCK_SIZE = 1024 };
197
198 #if defined HAVE_IPP && (IPP_VERSION_MAJOR >= 7)
199 #define ARITHM_USE_IPP 1
200 #else
201 #define ARITHM_USE_IPP 0
202 #endif
203
204 inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind)
205 {
206     if( sc.dims > 2 || !sc.isContinuous() )
207         return false;
208     Size sz = sc.size();
209     if(sz.width != 1 && sz.height != 1)
210         return false;
211     int cn = CV_MAT_CN(atype);
212     if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
213         return false;
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);
216 }
217
218 inline bool checkScalar(InputArray sc, int atype, int sckind, int akind)
219 {
220     if( sc.dims() > 2 || !sc.isContinuous() )
221         return false;
222     Size sz = sc.size();
223     if(sz.width != 1 && sz.height != 1)
224         return false;
225     int cn = CV_MAT_CN(atype);
226     if( akind == _InputArray::MATX && sckind != _InputArray::MATX )
227         return false;
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);
230 }
231
232 void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t blocksize );
233
234 struct CoreTLSData
235 {
236     CoreTLSData() : device(0), useOpenCL(-1)
237     {}
238
239     RNG rng;
240     int device;
241     ocl::Queue oclQueue;
242     int useOpenCL; // 1 - use, 0 - do not use, -1 - auto/not initialized
243 };
244
245 extern TLSData<CoreTLSData> coreTlsData;
246
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")))
252 #else
253 #define CL_RUNTIME_EXPORT
254 #endif
255 #else
256 #define CL_RUNTIME_EXPORT
257 #endif
258
259 extern bool __termination; // skip some cleanups, because process is terminating
260                            // (for example, if ExitProcess() was already called)
261
262 }
263
264 #endif /*_CXCORE_INTERNAL_H_*/