Merge pull request #3384 from ilya-lavrenov:neon_new
[profile/ivi/opencv.git] / modules / core / include / opencv2 / core / base.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 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 // Third party copyrights are property of their respective owners.
17 //
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
20 //
21 //   * Redistribution's of source code must retain the above copyright notice,
22 //     this list of conditions and the following disclaimer.
23 //
24 //   * Redistribution's in binary form must reproduce the above copyright notice,
25 //     this list of conditions and the following disclaimer in the documentation
26 //     and/or other materials provided with the distribution.
27 //
28 //   * The name of the copyright holders may not be used to endorse or promote products
29 //     derived from this software without specific prior written permission.
30 //
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
41 //
42 //M*/
43
44 #ifndef __OPENCV_CORE_BASE_HPP__
45 #define __OPENCV_CORE_BASE_HPP__
46
47 #ifndef __cplusplus
48 #  error base.hpp header must be compiled as C++
49 #endif
50
51 #include <climits>
52
53 #include "opencv2/core/cvdef.h"
54 #include "opencv2/core/cvstd.hpp"
55
56 namespace cv
57 {
58
59 // error codes
60 namespace Error {
61 enum {
62     StsOk=                       0,  /* everithing is ok                */
63     StsBackTrace=               -1,  /* pseudo error for back trace     */
64     StsError=                   -2,  /* unknown /unspecified error      */
65     StsInternal=                -3,  /* internal error (bad state)      */
66     StsNoMem=                   -4,  /* insufficient memory             */
67     StsBadArg=                  -5,  /* function arg/param is bad       */
68     StsBadFunc=                 -6,  /* unsupported function            */
69     StsNoConv=                  -7,  /* iter. didn't converge           */
70     StsAutoTrace=               -8,  /* tracing                         */
71     HeaderIsNull=               -9,  /* image header is NULL            */
72     BadImageSize=              -10,  /* image size is invalid           */
73     BadOffset=                 -11,  /* offset is invalid               */
74     BadDataPtr=                -12,  /**/
75     BadStep=                   -13,  /**/
76     BadModelOrChSeq=           -14,  /**/
77     BadNumChannels=            -15,  /**/
78     BadNumChannel1U=           -16,  /**/
79     BadDepth=                  -17,  /**/
80     BadAlphaChannel=           -18,  /**/
81     BadOrder=                  -19,  /**/
82     BadOrigin=                 -20,  /**/
83     BadAlign=                  -21,  /**/
84     BadCallBack=               -22,  /**/
85     BadTileSize=               -23,  /**/
86     BadCOI=                    -24,  /**/
87     BadROISize=                -25,  /**/
88     MaskIsTiled=               -26,  /**/
89     StsNullPtr=                -27,  /* null pointer */
90     StsVecLengthErr=           -28,  /* incorrect vector length */
91     StsFilterStructContentErr= -29,  /* incorr. filter structure content */
92     StsKernelStructContentErr= -30,  /* incorr. transform kernel content */
93     StsFilterOffsetErr=        -31,  /* incorrect filter ofset value */
94     StsBadSize=                -201, /* the input/output structure size is incorrect  */
95     StsDivByZero=              -202, /* division by zero */
96     StsInplaceNotSupported=    -203, /* in-place operation is not supported */
97     StsObjectNotFound=         -204, /* request can't be completed */
98     StsUnmatchedFormats=       -205, /* formats of input/output arrays differ */
99     StsBadFlag=                -206, /* flag is wrong or not supported */
100     StsBadPoint=               -207, /* bad CvPoint */
101     StsBadMask=                -208, /* bad format of mask (neither 8uC1 nor 8sC1)*/
102     StsUnmatchedSizes=         -209, /* sizes of input/output structures do not match */
103     StsUnsupportedFormat=      -210, /* the data format/type is not supported by the function*/
104     StsOutOfRange=             -211, /* some of parameters are out of range */
105     StsParseError=             -212, /* invalid syntax/structure of the parsed file */
106     StsNotImplemented=         -213, /* the requested function/feature is not implemented */
107     StsBadMemBlock=            -214, /* an allocated block has been corrupted */
108     StsAssert=                 -215, /* assertion failed */
109     GpuNotSupported=           -216,
110     GpuApiCallError=           -217,
111     OpenGlNotSupported=        -218,
112     OpenGlApiCallError=        -219,
113     OpenCLApiCallError=        -220,
114     OpenCLDoubleNotSupported=  -221,
115     OpenCLInitError=           -222,
116     OpenCLNoAMDBlasFft=        -223
117 };
118 } //Error
119
120 // matrix decomposition types
121 enum { DECOMP_LU       = 0,
122        DECOMP_SVD      = 1,
123        DECOMP_EIG      = 2,
124        DECOMP_CHOLESKY = 3,
125        DECOMP_QR       = 4,
126        DECOMP_NORMAL   = 16
127      };
128
129 // norm types
130 enum { NORM_INF       = 1,
131        NORM_L1        = 2,
132        NORM_L2        = 4,
133        NORM_L2SQR     = 5,
134        NORM_HAMMING   = 6,
135        NORM_HAMMING2  = 7,
136        NORM_TYPE_MASK = 7,
137        NORM_RELATIVE  = 8,
138        NORM_MINMAX    = 32
139      };
140
141 // comparison types
142 enum { CMP_EQ = 0,
143        CMP_GT = 1,
144        CMP_GE = 2,
145        CMP_LT = 3,
146        CMP_LE = 4,
147        CMP_NE = 5
148      };
149
150 enum { GEMM_1_T = 1,
151        GEMM_2_T = 2,
152        GEMM_3_T = 4
153      };
154
155 enum { DFT_INVERSE        = 1,
156        DFT_SCALE          = 2,
157        DFT_ROWS           = 4,
158        DFT_COMPLEX_OUTPUT = 16,
159        DFT_REAL_OUTPUT    = 32,
160        DCT_INVERSE        = DFT_INVERSE,
161        DCT_ROWS           = DFT_ROWS
162      };
163
164 //! Various border types, image boundaries are denoted with '|'
165 enum {
166        BORDER_CONSTANT    = 0, // iiiiii|abcdefgh|iiiiiii  with some specified 'i'
167        BORDER_REPLICATE   = 1, // aaaaaa|abcdefgh|hhhhhhh
168        BORDER_REFLECT     = 2, // fedcba|abcdefgh|hgfedcb
169        BORDER_WRAP        = 3, // cdefgh|abcdefgh|abcdefg
170        BORDER_REFLECT_101 = 4, // gfedcb|abcdefgh|gfedcba
171        BORDER_TRANSPARENT = 5, // uvwxyz|absdefgh|ijklmno
172
173        BORDER_REFLECT101  = BORDER_REFLECT_101,
174        BORDER_DEFAULT     = BORDER_REFLECT_101,
175        BORDER_ISOLATED    = 16 // do not look outside of ROI
176      };
177
178
179
180 //////////////// static assert /////////////////
181
182 #define CVAUX_CONCAT_EXP(a, b) a##b
183 #define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b)
184
185 #if defined(__clang__)
186 #  ifndef __has_extension
187 #    define __has_extension __has_feature /* compatibility, for older versions of clang */
188 #  endif
189 #  if __has_extension(cxx_static_assert)
190 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
191 #  endif
192 #elif defined(__GNUC__)
193 #  if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
194 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
195 #  endif
196 #elif defined(_MSC_VER)
197 #  if _MSC_VER >= 1600 /* MSVC 10 */
198 #    define CV_StaticAssert(condition, reason)    static_assert((condition), reason " " #condition)
199 #  endif
200 #endif
201 #ifndef CV_StaticAssert
202 #  if defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 2)
203 #    define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); })
204 #  else
205      template <bool x> struct CV_StaticAssert_failed;
206      template <> struct CV_StaticAssert_failed<true> { enum { val = 1 }; };
207      template<int x> struct CV_StaticAssert_test {};
208 #    define CV_StaticAssert(condition, reason)\
209        typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast<bool>(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__)
210 #  endif
211 #endif
212
213 //! Suppress warning "-Wdeprecated-declarations" / C4996
214
215 #if defined(_MSC_VER)
216     #define CV_DO_PRAGMA(x) __pragma(x)
217 #elif defined(__GNUC__)
218     #define CV_DO_PRAGMA(x) _Pragma (#x)
219 #else
220     #define CV_DO_PRAGMA(x)
221 #endif
222
223 #ifdef _MSC_VER
224 #define CV_SUPPRESS_DEPRECATED_START \
225     CV_DO_PRAGMA(warning(push)) \
226     CV_DO_PRAGMA(warning(disable: 4996))
227 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop))
228 #elif defined (__clang__) || ((__GNUC__)  && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
229 #define CV_SUPPRESS_DEPRECATED_START \
230     CV_DO_PRAGMA(GCC diagnostic push) \
231     CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
232 #define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop)
233 #else
234 #define CV_SUPPRESS_DEPRECATED_START
235 #define CV_SUPPRESS_DEPRECATED_END
236 #endif
237
238 /*! @brief Signals an error and raises the exception.
239   By default the function prints information about the error to stderr,
240   then it either stops if setBreakOnError() had been called before or raises the exception.
241   It is possible to alternate error processing by using redirectError().
242   @param _code - error code @see CVStatus
243   @param _err - error description
244   @param _func - function name. Available only when the compiler supports getting it
245   @param _file - source file name where the error has occured
246   @param _line - line number in the source file where the error has occured
247  */
248 CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
249
250 #ifdef __GNUC__
251 # if defined __clang__ || defined __APPLE__
252 #   pragma GCC diagnostic push
253 #   pragma GCC diagnostic ignored "-Winvalid-noreturn"
254 # endif
255 #endif
256 CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const char* _func, const char* _file, int _line)
257 {
258     error(_code, _err, _func, _file, _line);
259 #ifdef __GNUC__
260 # if !defined __clang__ && !defined __APPLE__
261     // this suppresses this warning: "noreturn" function does return [enabled by default]
262     __builtin_trap();
263     // or use infinite loop: for (;;) {}
264 # endif
265 #endif
266 }
267 #ifdef __GNUC__
268 # if defined __clang__ || defined __APPLE__
269 #   pragma GCC diagnostic pop
270 # endif
271 #endif
272
273
274 #if defined __GNUC__
275 #define CV_Func __func__
276 #elif defined _MSC_VER
277 #define CV_Func __FUNCTION__
278 #else
279 #define CV_Func ""
280 #endif
281
282 #define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
283 #define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
284 #define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ )
285
286 #define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ )
287 #define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ )
288
289 #ifdef _DEBUG
290 #  define CV_DbgAssert(expr) CV_Assert(expr)
291 #else
292 #  define CV_DbgAssert(expr)
293 #endif
294
295
296
297 /////////////// saturate_cast (used in image & signal processing) ///////////////////
298
299 template<typename _Tp> static inline _Tp saturate_cast(uchar v)    { return _Tp(v); }
300 template<typename _Tp> static inline _Tp saturate_cast(schar v)    { return _Tp(v); }
301 template<typename _Tp> static inline _Tp saturate_cast(ushort v)   { return _Tp(v); }
302 template<typename _Tp> static inline _Tp saturate_cast(short v)    { return _Tp(v); }
303 template<typename _Tp> static inline _Tp saturate_cast(unsigned v) { return _Tp(v); }
304 template<typename _Tp> static inline _Tp saturate_cast(int v)      { return _Tp(v); }
305 template<typename _Tp> static inline _Tp saturate_cast(float v)    { return _Tp(v); }
306 template<typename _Tp> static inline _Tp saturate_cast(double v)   { return _Tp(v); }
307
308 template<> inline uchar saturate_cast<uchar>(schar v)        { return (uchar)std::max((int)v, 0); }
309 template<> inline uchar saturate_cast<uchar>(ushort v)       { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); }
310 template<> inline uchar saturate_cast<uchar>(int v)          { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
311 template<> inline uchar saturate_cast<uchar>(short v)        { return saturate_cast<uchar>((int)v); }
312 template<> inline uchar saturate_cast<uchar>(unsigned v)     { return (uchar)std::min(v, (unsigned)UCHAR_MAX); }
313 template<> inline uchar saturate_cast<uchar>(float v)        { int iv = cvRound(v); return saturate_cast<uchar>(iv); }
314 template<> inline uchar saturate_cast<uchar>(double v)       { int iv = cvRound(v); return saturate_cast<uchar>(iv); }
315
316 template<> inline schar saturate_cast<schar>(uchar v)        { return (schar)std::min((int)v, SCHAR_MAX); }
317 template<> inline schar saturate_cast<schar>(ushort v)       { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); }
318 template<> inline schar saturate_cast<schar>(int v)          { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); }
319 template<> inline schar saturate_cast<schar>(short v)        { return saturate_cast<schar>((int)v); }
320 template<> inline schar saturate_cast<schar>(unsigned v)     { return (schar)std::min(v, (unsigned)SCHAR_MAX); }
321 template<> inline schar saturate_cast<schar>(float v)        { int iv = cvRound(v); return saturate_cast<schar>(iv); }
322 template<> inline schar saturate_cast<schar>(double v)       { int iv = cvRound(v); return saturate_cast<schar>(iv); }
323
324 template<> inline ushort saturate_cast<ushort>(schar v)      { return (ushort)std::max((int)v, 0); }
325 template<> inline ushort saturate_cast<ushort>(short v)      { return (ushort)std::max((int)v, 0); }
326 template<> inline ushort saturate_cast<ushort>(int v)        { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); }
327 template<> inline ushort saturate_cast<ushort>(unsigned v)   { return (ushort)std::min(v, (unsigned)USHRT_MAX); }
328 template<> inline ushort saturate_cast<ushort>(float v)      { int iv = cvRound(v); return saturate_cast<ushort>(iv); }
329 template<> inline ushort saturate_cast<ushort>(double v)     { int iv = cvRound(v); return saturate_cast<ushort>(iv); }
330
331 template<> inline short saturate_cast<short>(ushort v)       { return (short)std::min((int)v, SHRT_MAX); }
332 template<> inline short saturate_cast<short>(int v)          { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); }
333 template<> inline short saturate_cast<short>(unsigned v)     { return (short)std::min(v, (unsigned)SHRT_MAX); }
334 template<> inline short saturate_cast<short>(float v)        { int iv = cvRound(v); return saturate_cast<short>(iv); }
335 template<> inline short saturate_cast<short>(double v)       { int iv = cvRound(v); return saturate_cast<short>(iv); }
336
337 template<> inline int saturate_cast<int>(float v)            { return cvRound(v); }
338 template<> inline int saturate_cast<int>(double v)           { return cvRound(v); }
339
340 // we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
341 template<> inline unsigned saturate_cast<unsigned>(float v)  { return cvRound(v); }
342 template<> inline unsigned saturate_cast<unsigned>(double v) { return cvRound(v); }
343
344
345
346 //////////////////////////////// low-level functions ////////////////////////////////
347
348 CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
349 CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
350 CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
351 CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
352
353 CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n);
354 CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n);
355 CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize);
356 CV_EXPORTS float normL1_(const float* a, const float* b, int n);
357 CV_EXPORTS float normL2Sqr_(const float* a, const float* b, int n);
358
359 CV_EXPORTS void exp(const float* src, float* dst, int n);
360 CV_EXPORTS void log(const float* src, float* dst, int n);
361 CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees);
362 CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n);
363
364 //! computes cube root of the argument
365 CV_EXPORTS_W float cubeRoot(float val);
366 //! computes the angle in degrees (0..360) of the vector (x,y)
367 CV_EXPORTS_W float fastAtan2(float y, float x);
368
369
370
371 /////////////////////////////////// inline norms ////////////////////////////////////
372
373 template<typename _Tp, typename _AccTp> static inline
374 _AccTp normL2Sqr(const _Tp* a, int n)
375 {
376     _AccTp s = 0;
377     int i=0;
378 #if CV_ENABLE_UNROLLED
379     for( ; i <= n - 4; i += 4 )
380     {
381         _AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3];
382         s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
383     }
384 #endif
385     for( ; i < n; i++ )
386     {
387         _AccTp v = a[i];
388         s += v*v;
389     }
390     return s;
391 }
392
393 template<typename _Tp, typename _AccTp> static inline
394 _AccTp normL1(const _Tp* a, int n)
395 {
396     _AccTp s = 0;
397     int i = 0;
398 #if CV_ENABLE_UNROLLED
399     for(; i <= n - 4; i += 4 )
400     {
401         s += (_AccTp)std::abs(a[i]) + (_AccTp)std::abs(a[i+1]) +
402             (_AccTp)std::abs(a[i+2]) + (_AccTp)std::abs(a[i+3]);
403     }
404 #endif
405     for( ; i < n; i++ )
406         s += std::abs(a[i]);
407     return s;
408 }
409
410 template<typename _Tp, typename _AccTp> static inline
411 _AccTp normInf(const _Tp* a, int n)
412 {
413     _AccTp s = 0;
414     for( int i = 0; i < n; i++ )
415         s = std::max(s, (_AccTp)std::abs(a[i]));
416     return s;
417 }
418
419 template<typename _Tp, typename _AccTp> static inline
420 _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n)
421 {
422     _AccTp s = 0;
423     int i= 0;
424 #if CV_ENABLE_UNROLLED
425     for(; i <= n - 4; i += 4 )
426     {
427         _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
428         s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
429     }
430 #endif
431     for( ; i < n; i++ )
432     {
433         _AccTp v = _AccTp(a[i] - b[i]);
434         s += v*v;
435     }
436     return s;
437 }
438
439 template<> inline
440 float normL2Sqr(const float* a, const float* b, int n)
441 {
442     if( n >= 8 )
443         return normL2Sqr_(a, b, n);
444     float s = 0;
445     for( int i = 0; i < n; i++ )
446     {
447         float v = a[i] - b[i];
448         s += v*v;
449     }
450     return s;
451 }
452
453 template<typename _Tp, typename _AccTp> static inline
454 _AccTp normL1(const _Tp* a, const _Tp* b, int n)
455 {
456     _AccTp s = 0;
457     int i= 0;
458 #if CV_ENABLE_UNROLLED
459     for(; i <= n - 4; i += 4 )
460     {
461         _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
462         s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3);
463     }
464 #endif
465     for( ; i < n; i++ )
466     {
467         _AccTp v = _AccTp(a[i] - b[i]);
468         s += std::abs(v);
469     }
470     return s;
471 }
472
473 template<> inline
474 float normL1(const float* a, const float* b, int n)
475 {
476     if( n >= 8 )
477         return normL1_(a, b, n);
478     float s = 0;
479     for( int i = 0; i < n; i++ )
480     {
481         float v = a[i] - b[i];
482         s += std::abs(v);
483     }
484     return s;
485 }
486
487 template<> inline
488 int normL1(const uchar* a, const uchar* b, int n)
489 {
490     return normL1_(a, b, n);
491 }
492
493 template<typename _Tp, typename _AccTp> static inline
494 _AccTp normInf(const _Tp* a, const _Tp* b, int n)
495 {
496     _AccTp s = 0;
497     for( int i = 0; i < n; i++ )
498     {
499         _AccTp v0 = a[i] - b[i];
500         s = std::max(s, std::abs(v0));
501     }
502     return s;
503 }
504
505
506
507 ////////////////// forward declarations for important OpenCV types //////////////////
508
509 template<typename _Tp, int cn> class Vec;
510 template<typename _Tp, int m, int n> class Matx;
511
512 template<typename _Tp> class Complex;
513 template<typename _Tp> class Point_;
514 template<typename _Tp> class Point3_;
515 template<typename _Tp> class Size_;
516 template<typename _Tp> class Rect_;
517 template<typename _Tp> class Scalar_;
518
519 class CV_EXPORTS RotatedRect;
520 class CV_EXPORTS Range;
521 class CV_EXPORTS TermCriteria;
522 class CV_EXPORTS KeyPoint;
523 class CV_EXPORTS DMatch;
524 class CV_EXPORTS RNG;
525
526 class CV_EXPORTS Mat;
527 class CV_EXPORTS MatExpr;
528
529 class CV_EXPORTS UMat;
530
531 class CV_EXPORTS SparseMat;
532 typedef Mat MatND;
533
534 template<typename _Tp> class Mat_;
535 template<typename _Tp> class SparseMat_;
536
537 class CV_EXPORTS MatConstIterator;
538 class CV_EXPORTS SparseMatIterator;
539 class CV_EXPORTS SparseMatConstIterator;
540 template<typename _Tp> class MatIterator_;
541 template<typename _Tp> class MatConstIterator_;
542 template<typename _Tp> class SparseMatIterator_;
543 template<typename _Tp> class SparseMatConstIterator_;
544
545 namespace ogl
546 {
547     class CV_EXPORTS Buffer;
548     class CV_EXPORTS Texture2D;
549     class CV_EXPORTS Arrays;
550 }
551
552 namespace cuda
553 {
554     class CV_EXPORTS GpuMat;
555     class CV_EXPORTS CudaMem;
556     class CV_EXPORTS Stream;
557     class CV_EXPORTS Event;
558 }
559
560 namespace cudev
561 {
562     template <typename _Tp> class GpuMat_;
563 }
564
565 namespace ipp
566 {
567 CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL,
568                              int line = 0);
569 CV_EXPORTS int getIppStatus();
570 CV_EXPORTS String getIppErrorLocation();
571 CV_EXPORTS bool useIPP();
572 CV_EXPORTS void setUseIPP(bool flag);
573
574 } // ipp
575
576 #if CV_NEON
577
578 inline int32x2_t cv_vrnd_s32_f32(float32x2_t v)
579 {
580     static int32x2_t v_sign = vdup_n_s32(1 << 31),
581         v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f));
582
583     int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v)));
584     return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition)));
585 }
586
587 inline int32x4_t cv_vrndq_s32_f32(float32x4_t v)
588 {
589     static int32x4_t v_sign = vdupq_n_s32(1 << 31),
590         v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f));
591
592     int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v)));
593     return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition)));
594 }
595
596 inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v)
597 {
598     static float32x2_t v_05 = vdup_n_f32(0.5f);
599     return vcvt_u32_f32(vadd_f32(v, v_05));
600 }
601
602 inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v)
603 {
604     static float32x4_t v_05 = vdupq_n_f32(0.5f);
605     return vcvtq_u32_f32(vaddq_f32(v, v_05));
606 }
607
608 inline float32x4_t cv_vrecpq_f32(float32x4_t val)
609 {
610     float32x4_t reciprocal = vrecpeq_f32(val);
611     reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal);
612     reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal);
613     return reciprocal;
614 }
615
616 inline float32x2_t cv_vrecp_f32(float32x2_t val)
617 {
618     float32x2_t reciprocal = vrecpe_f32(val);
619     reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal);
620     reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal);
621     return reciprocal;
622 }
623
624 inline float32x4_t cv_vrsqrtq_f32(float32x4_t val)
625 {
626     float32x4_t e = vrsqrteq_f32(val);
627     e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e);
628     e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e);
629     return e;
630 }
631
632 inline float32x2_t cv_vrsqrt_f32(float32x2_t val)
633 {
634     float32x2_t e = vrsqrte_f32(val);
635     e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e);
636     e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e);
637     return e;
638 }
639
640 inline float32x4_t cv_vsqrtq_f32(float32x4_t val)
641 {
642     return cv_vrecpq_f32(cv_vrsqrtq_f32(val));
643 }
644
645 inline float32x2_t cv_vsqrt_f32(float32x2_t val)
646 {
647     return cv_vrecp_f32(cv_vrsqrt_f32(val));
648 }
649
650 #endif
651
652 } // cv
653
654 #endif //__OPENCV_CORE_BASE_HPP__