-/*M///////////////////////////////////////////////////////////////////////////////////////\r
-//\r
-// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
-//\r
-// By downloading, copying, installing or using the software you agree to this license.\r
-// If you do not agree to this license, do not download, install,\r
-// copy or use the software.\r
-//\r
-//\r
-// License Agreement\r
-// For Open Source Computer Vision Library\r
-//\r
-// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.\r
-// Copyright (C) 2009, Willow Garage Inc., all rights reserved.\r
-// Third party copyrights are property of their respective owners.\r
-//\r
-// Redistribution and use in source and binary forms, with or without modification,\r
-// are permitted provided that the following conditions are met:\r
-//\r
-// * Redistribution's of source code must retain the above copyright notice,\r
-// this list of conditions and the following disclaimer.\r
-//\r
-// * Redistribution's in binary form must reproduce the above copyright notice,\r
-// this list of conditions and the following disclaimer in the documentation\r
-// and/or other materials provided with the distribution.\r
-//\r
-// * The name of the copyright holders may not be used to endorse or promote products\r
-// derived from this software without specific prior written permission.\r
-//\r
-// This software is provided by the copyright holders and contributors "as is" and\r
-// any express or implied warranties, including, but not limited to, the implied\r
-// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
-// In no event shall the Intel Corporation or contributors be liable for any direct,\r
-// indirect, incidental, special, exemplary, or consequential damages\r
-// (including, but not limited to, procurement of substitute goods or services;\r
-// loss of use, data, or profits; or business interruption) however caused\r
-// and on any theory of liability, whether in contract, strict liability,\r
-// or tort (including negligence or otherwise) arising in any way out of\r
-// the use of this software, even if advised of the possibility of such damage.\r
-//\r
-//M*/\r
-\r
-#ifndef _CXCORE_INTERNAL_H_\r
-#define _CXCORE_INTERNAL_H_\r
-\r
-#if defined _MSC_VER && _MSC_VER >= 1200\r
- /* disable warnings related to inline functions */\r
- #pragma warning( disable: 4711 4710 4514 )\r
-#endif\r
-\r
-typedef unsigned long ulong;\r
-\r
-#ifdef __BORLANDC__\r
- #define WIN32\r
- #define CV_DLL\r
-#endif\r
-\r
-#include "cxcore.h"\r
-#include "cxmisc.h"\r
-\r
-#include <assert.h>\r
-#include <ctype.h>\r
-#include <float.h>\r
-#include <limits.h>\r
-#include <math.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-\r
-#if defined WIN32 || defined WINCE\r
-#ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?)\r
-#define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx\r
-#endif\r
-#include <windows.h>\r
-#undef small\r
-#undef min\r
-#undef max\r
-#else\r
-#include <pthread.h>\r
-#include <sys/mman.h>\r
-#endif\r
-\r
-#ifdef HAVE_CONFIG_H\r
-#include <cvconfig.h>\r
-#endif\r
-\r
-#ifdef HAVE_IPP\r
-#include "ipp.h"\r
-#endif\r
-\r
-namespace cv\r
-{\r
-\r
-// -128.f ... 255.f\r
-extern const float g_8x32fTab[];\r
-#define CV_8TO32F(x) cv::g_8x32fTab[(x)+128]\r
-\r
-extern const ushort g_8x16uSqrTab[];\r
-#define CV_SQR_8U(x) cv::g_8x16uSqrTab[(x)+255]\r
-\r
-extern const char* g_HersheyGlyphs[];\r
-\r
-extern const signed char g_DepthToType[];\r
-#define IplToCvDepth( depth ) \\r
- cv::g_DepthToType[(((depth) & 255) >> 2) + ((depth) < 0)]\r
-\r
-extern const uchar g_Saturate8u[];\r
-#define CV_FAST_CAST_8U(t) (assert(-256 <= (t) && (t) <= 512), cv::g_Saturate8u[(t)+256])\r
-#define CV_MIN_8U(a,b) ((a) - CV_FAST_CAST_8U((a) - (b)))\r
-#define CV_MAX_8U(a,b) ((a) + CV_FAST_CAST_8U((b) - (a)))\r
-\r
-typedef void (*CopyMaskFunc)(const Mat& src, Mat& dst, const Mat& mask);\r
-\r
-extern CopyMaskFunc g_copyMaskFuncTab[];\r
-\r
-static inline CopyMaskFunc getCopyMaskFunc(int esz)\r
-{\r
- CV_Assert( (unsigned)esz <= 32U );\r
- CopyMaskFunc func = g_copyMaskFuncTab[esz];\r
- CV_Assert( func != 0 );\r
- return func;\r
-}\r
-\r
-#ifdef WIN32\r
-void deleteThreadAllocData();\r
-void deleteThreadRNGData();\r
-#endif\r
-\r
-template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd\r
-{\r
- typedef T1 type1;\r
- typedef T2 type2;\r
- typedef T3 rtype;\r
- T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a + b); }\r
-};\r
-\r
-template<typename T1, typename T2=T1, typename T3=T1> struct OpSub\r
-{\r
- typedef T1 type1;\r
- typedef T2 type2;\r
- typedef T3 rtype;\r
- T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a - b); }\r
-};\r
-\r
-template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub\r
-{\r
- typedef T1 type1;\r
- typedef T2 type2;\r
- typedef T3 rtype;\r
- T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(b - a); }\r
-};\r
-\r
-template<typename T1, typename T2=T1, typename T3=T1> struct OpMul\r
-{\r
- typedef T1 type1;\r
- typedef T2 type2;\r
- typedef T3 rtype;\r
- T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a * b); }\r
-};\r
-\r
-template<typename T1, typename T2=T1, typename T3=T1> struct OpDiv\r
-{\r
- typedef T1 type1;\r
- typedef T2 type2;\r
- typedef T3 rtype;\r
- T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a / b); }\r
-};\r
-\r
-template<typename T> struct OpMin\r
-{\r
- typedef T type1;\r
- typedef T type2;\r
- typedef T rtype;\r
- T operator ()(T a, T b) const { return std::min(a, b); }\r
-};\r
-\r
-template<typename T> struct OpMax\r
-{\r
- typedef T type1;\r
- typedef T type2;\r
- typedef T rtype;\r
- T operator ()(T a, T b) const { return std::max(a, b); }\r
-};\r
-\r
-static inline Size getContinuousSize( const Mat& m1, int widthScale=1 )\r
-{\r
- return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :\r
- Size(m1.cols*widthScale, m1.rows);\r
-}\r
-\r
-static inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )\r
-{\r
- return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?\r
- Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);\r
-}\r
-\r
-static inline Size getContinuousSize( const Mat& m1, const Mat& m2,\r
- const Mat& m3, int widthScale=1 )\r
-{\r
- return (m1.flags & m2.flags & m3.flags & Mat::CONTINUOUS_FLAG) != 0 ?\r
- Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);\r
-}\r
-\r
-static inline Size getContinuousSize( const Mat& m1, const Mat& m2,\r
- const Mat& m3, const Mat& m4,\r
- int widthScale=1 )\r
-{\r
- return (m1.flags & m2.flags & m3.flags & m4.flags & Mat::CONTINUOUS_FLAG) != 0 ?\r
- Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);\r
-}\r
-\r
-static inline Size getContinuousSize( const Mat& m1, const Mat& m2,\r
- const Mat& m3, const Mat& m4,\r
- const Mat& m5, int widthScale=1 )\r
-{\r
- return (m1.flags & m2.flags & m3.flags & m4.flags & m5.flags & Mat::CONTINUOUS_FLAG) != 0 ?\r
- Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);\r
-}\r
-\r
-struct NoVec\r
-{\r
- int operator()(const void*, const void*, void*, int) const { return 0; }\r
-};\r
-\r
-template<class Op, class VecOp> static void\r
-binaryOpC1_( const Mat& srcmat1, const Mat& srcmat2, Mat& dstmat )\r
-{\r
- Op op; VecOp vecOp;\r
- typedef typename Op::type1 T1;\r
- typedef typename Op::type2 T2;\r
- typedef typename Op::rtype DT;\r
-\r
- const T1* src1 = (const T1*)srcmat1.data;\r
- const T2* src2 = (const T2*)srcmat2.data;\r
- DT* dst = (DT*)dstmat.data;\r
- size_t step1 = srcmat1.step/sizeof(src1[0]);\r
- size_t step2 = srcmat2.step/sizeof(src2[0]);\r
- size_t step = dstmat.step/sizeof(dst[0]);\r
- Size size = getContinuousSize( srcmat1, srcmat2, dstmat, dstmat.channels() );\r
-\r
- if( size.width == 1 )\r
- {\r
- for( ; size.height--; src1 += step1, src2 += step2, dst += step )\r
- dst[0] = op( src1[0], src2[0] );\r
- return;\r
- }\r
-\r
- for( ; size.height--; src1 += step1, src2 += step2, dst += step )\r
- {\r
- int x = vecOp(src1, src2, dst, size.width);\r
- for( ; x <= size.width - 4; x += 4 )\r
- {\r
- DT f0, f1;\r
- f0 = op( src1[x], src2[x] );\r
- f1 = op( src1[x+1], src2[x+1] );\r
- dst[x] = f0;\r
- dst[x+1] = f1;\r
- f0 = op(src1[x+2], src2[x+2]);\r
- f1 = op(src1[x+3], src2[x+3]);\r
- dst[x+2] = f0;\r
- dst[x+3] = f1;\r
- }\r
-\r
- for( ; x < size.width; x++ )\r
- dst[x] = op( src1[x], src2[x] );\r
- }\r
-}\r
-\r
-typedef void (*BinaryFunc)(const Mat& src1, const Mat& src2, Mat& dst);\r
-\r
-template<class Op> static void\r
-binarySOpCn_( const Mat& srcmat, Mat& dstmat, const Scalar& _scalar )\r
-{\r
- Op op;\r
- typedef typename Op::type1 T;\r
- typedef typename Op::type2 WT;\r
- typedef typename Op::rtype DT;\r
- const T* src0 = (const T*)srcmat.data;\r
- DT* dst0 = (DT*)dstmat.data;\r
- size_t step1 = srcmat.step/sizeof(src0[0]);\r
- size_t step = dstmat.step/sizeof(dst0[0]);\r
- int cn = dstmat.channels();\r
- Size size = getContinuousSize( srcmat, dstmat, cn );\r
- WT scalar[12];\r
- _scalar.convertTo(scalar, cn, 12);\r
-\r
- for( ; size.height--; src0 += step1, dst0 += step )\r
- {\r
- int i, len = size.width;\r
- const T* src = src0;\r
- T* dst = dst0;\r
-\r
- for( ; (len -= 12) >= 0; dst += 12, src += 12 )\r
- {\r
- DT t0 = op(src[0], scalar[0]);\r
- DT t1 = op(src[1], scalar[1]);\r
- dst[0] = t0; dst[1] = t1;\r
-\r
- t0 = op(src[2], scalar[2]);\r
- t1 = op(src[3], scalar[3]);\r
- dst[2] = t0; dst[3] = t1;\r
-\r
- t0 = op(src[4], scalar[4]);\r
- t1 = op(src[5], scalar[5]);\r
- dst[4] = t0; dst[5] = t1;\r
-\r
- t0 = op(src[6], scalar[6]);\r
- t1 = op(src[7], scalar[7]);\r
- dst[6] = t0; dst[7] = t1;\r
-\r
- t0 = op(src[8], scalar[8]);\r
- t1 = op(src[9], scalar[9]);\r
- dst[8] = t0; dst[9] = t1;\r
-\r
- t0 = op(src[10], scalar[10]);\r
- t1 = op(src[11], scalar[11]);\r
- dst[10] = t0; dst[11] = t1;\r
- }\r
-\r
- for( (len) += 12, i = 0; i < (len); i++ )\r
- dst[i] = op((WT)src[i], scalar[i]);\r
- }\r
-}\r
-\r
-template<class Op> static void\r
-binarySOpC1_( const Mat& srcmat, Mat& dstmat, double _scalar )\r
-{\r
- Op op;\r
- typedef typename Op::type1 T;\r
- typedef typename Op::type2 WT;\r
- typedef typename Op::rtype DT;\r
- WT scalar = saturate_cast<WT>(_scalar);\r
- const T* src = (const T*)srcmat.data;\r
- DT* dst = (DT*)dstmat.data;\r
- size_t step1 = srcmat.step/sizeof(src[0]);\r
- size_t step = dstmat.step/sizeof(dst[0]);\r
- Size size = srcmat.size();\r
- \r
- size.width *= srcmat.channels();\r
- if( srcmat.isContinuous() && dstmat.isContinuous() )\r
- {\r
- size.width *= size.height;\r
- size.height = 1;\r
- }\r
-\r
- for( ; size.height--; src += step1, dst += step )\r
- {\r
- int x;\r
- for( x = 0; x <= size.width - 4; x += 4 )\r
- {\r
- DT f0 = op( src[x], scalar );\r
- DT f1 = op( src[x+1], scalar );\r
- dst[x] = f0;\r
- dst[x+1] = f1;\r
- f0 = op( src[x+2], scalar );\r
- f1 = op( src[x+3], scalar );\r
- dst[x+2] = f0;\r
- dst[x+3] = f1;\r
- }\r
-\r
- for( ; x < size.width; x++ )\r
- dst[x] = op( src[x], scalar );\r
- }\r
-}\r
-\r
-typedef void (*BinarySFuncCn)(const Mat& src1, Mat& dst, const Scalar& scalar);\r
-typedef void (*BinarySFuncC1)(const Mat& src1, Mat& dst, double scalar);\r
-\r
-}\r
-\r
-#endif /*_CXCORE_INTERNAL_H_*/\r
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+// By downloading, copying, installing or using the software you agree to this license.
+// If you do not agree to this license, do not download, install,
+// copy or use the software.
+//
+//
+// License Agreement
+// For Open Source Computer Vision Library
+//
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
+// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// * Redistribution's of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// * Redistribution's in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// * The name of the copyright holders may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
+#ifndef _CXCORE_INTERNAL_H_
+#define _CXCORE_INTERNAL_H_
+
+#if defined _MSC_VER && _MSC_VER >= 1200
+ /* disable warnings related to inline functions */
+ #pragma warning( disable: 4711 4710 4514 )
+#endif
+
+typedef unsigned long ulong;
+
+#ifdef __BORLANDC__
+#ifndef WIN32
+ #define WIN32
+#endif
+ #define CV_DLL
+#endif
+
+#include "cxcore.h"
+#include "cxmisc.h"
+
+#include <assert.h>
+#include <ctype.h>
+#include <float.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if defined WIN32 || defined _WIN32
+# ifndef WIN32
+# define WIN32
+# endif
+# ifndef _WIN32
+# define _WIN32
+# endif
+#endif
+
+#if defined WIN32 || defined WINCE
+#ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?)
+#define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
+#endif
+#include <windows.h>
+#undef small
+#undef min
+#undef max
+#else
+#include <pthread.h>
+#include <sys/mman.h>
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include <cvconfig.h>
+#endif
+
+#ifdef HAVE_IPP
+#include "ipp.h"
+#endif
+
+namespace cv
+{
+
+// -128.f ... 255.f
+extern const float g_8x32fTab[];
+#define CV_8TO32F(x) cv::g_8x32fTab[(x)+128]
+
+extern const ushort g_8x16uSqrTab[];
+#define CV_SQR_8U(x) cv::g_8x16uSqrTab[(x)+255]
+
+extern const char* g_HersheyGlyphs[];
+
+extern const signed char g_DepthToType[];
+#define IplToCvDepth( depth ) \
+ cv::g_DepthToType[(((depth) & 255) >> 2) + ((depth) < 0)]
+
+extern const uchar g_Saturate8u[];
+#define CV_FAST_CAST_8U(t) (assert(-256 <= (t) && (t) <= 512), cv::g_Saturate8u[(t)+256])
+#define CV_MIN_8U(a,b) ((a) - CV_FAST_CAST_8U((a) - (b)))
+#define CV_MAX_8U(a,b) ((a) + CV_FAST_CAST_8U((b) - (a)))
+
+typedef void (*CopyMaskFunc)(const Mat& src, Mat& dst, const Mat& mask);
+
+extern CopyMaskFunc g_copyMaskFuncTab[];
+
+static inline CopyMaskFunc getCopyMaskFunc(int esz)
+{
+ CV_Assert( (unsigned)esz <= 32U );
+ CopyMaskFunc func = g_copyMaskFuncTab[esz];
+ CV_Assert( func != 0 );
+ return func;
+}
+
+#if defined WIN32 || defined _WIN32
+void deleteThreadAllocData();
+void deleteThreadRNGData();
+#endif
+
+template<typename T1, typename T2=T1, typename T3=T1> struct OpAdd
+{
+ typedef T1 type1;
+ typedef T2 type2;
+ typedef T3 rtype;
+ T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a + b); }
+};
+
+template<typename T1, typename T2=T1, typename T3=T1> struct OpSub
+{
+ typedef T1 type1;
+ typedef T2 type2;
+ typedef T3 rtype;
+ T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a - b); }
+};
+
+template<typename T1, typename T2=T1, typename T3=T1> struct OpRSub
+{
+ typedef T1 type1;
+ typedef T2 type2;
+ typedef T3 rtype;
+ T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(b - a); }
+};
+
+template<typename T1, typename T2=T1, typename T3=T1> struct OpMul
+{
+ typedef T1 type1;
+ typedef T2 type2;
+ typedef T3 rtype;
+ T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a * b); }
+};
+
+template<typename T1, typename T2=T1, typename T3=T1> struct OpDiv
+{
+ typedef T1 type1;
+ typedef T2 type2;
+ typedef T3 rtype;
+ T3 operator ()(T1 a, T2 b) const { return saturate_cast<T3>(a / b); }
+};
+
+template<typename T> struct OpMin
+{
+ typedef T type1;
+ typedef T type2;
+ typedef T rtype;
+ T operator ()(T a, T b) const { return std::min(a, b); }
+};
+
+template<typename T> struct OpMax
+{
+ typedef T type1;
+ typedef T type2;
+ typedef T rtype;
+ T operator ()(T a, T b) const { return std::max(a, b); }
+};
+
+static inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
+{
+ return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
+ Size(m1.cols*widthScale, m1.rows);
+}
+
+static inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
+{
+ return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
+ Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
+}
+
+static inline Size getContinuousSize( const Mat& m1, const Mat& m2,
+ const Mat& m3, int widthScale=1 )
+{
+ return (m1.flags & m2.flags & m3.flags & Mat::CONTINUOUS_FLAG) != 0 ?
+ Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
+}
+
+static inline Size getContinuousSize( const Mat& m1, const Mat& m2,
+ const Mat& m3, const Mat& m4,
+ int widthScale=1 )
+{
+ return (m1.flags & m2.flags & m3.flags & m4.flags & Mat::CONTINUOUS_FLAG) != 0 ?
+ Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
+}
+
+static inline Size getContinuousSize( const Mat& m1, const Mat& m2,
+ const Mat& m3, const Mat& m4,
+ const Mat& m5, int widthScale=1 )
+{
+ return (m1.flags & m2.flags & m3.flags & m4.flags & m5.flags & Mat::CONTINUOUS_FLAG) != 0 ?
+ Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
+}
+
+struct NoVec
+{
+ int operator()(const void*, const void*, void*, int) const { return 0; }
+};
+
+template<class Op, class VecOp> static void
+binaryOpC1_( const Mat& srcmat1, const Mat& srcmat2, Mat& dstmat )
+{
+ Op op; VecOp vecOp;
+ typedef typename Op::type1 T1;
+ typedef typename Op::type2 T2;
+ typedef typename Op::rtype DT;
+
+ const T1* src1 = (const T1*)srcmat1.data;
+ const T2* src2 = (const T2*)srcmat2.data;
+ DT* dst = (DT*)dstmat.data;
+ size_t step1 = srcmat1.step/sizeof(src1[0]);
+ size_t step2 = srcmat2.step/sizeof(src2[0]);
+ size_t step = dstmat.step/sizeof(dst[0]);
+ Size size = getContinuousSize( srcmat1, srcmat2, dstmat, dstmat.channels() );
+
+ if( size.width == 1 )
+ {
+ for( ; size.height--; src1 += step1, src2 += step2, dst += step )
+ dst[0] = op( src1[0], src2[0] );
+ return;
+ }
+
+ for( ; size.height--; src1 += step1, src2 += step2, dst += step )
+ {
+ int x = vecOp(src1, src2, dst, size.width);
+ for( ; x <= size.width - 4; x += 4 )
+ {
+ DT f0, f1;
+ f0 = op( src1[x], src2[x] );
+ f1 = op( src1[x+1], src2[x+1] );
+ dst[x] = f0;
+ dst[x+1] = f1;
+ f0 = op(src1[x+2], src2[x+2]);
+ f1 = op(src1[x+3], src2[x+3]);
+ dst[x+2] = f0;
+ dst[x+3] = f1;
+ }
+
+ for( ; x < size.width; x++ )
+ dst[x] = op( src1[x], src2[x] );
+ }
+}
+
+typedef void (*BinaryFunc)(const Mat& src1, const Mat& src2, Mat& dst);
+
+template<class Op> static void
+binarySOpCn_( const Mat& srcmat, Mat& dstmat, const Scalar& _scalar )
+{
+ Op op;
+ typedef typename Op::type1 T;
+ typedef typename Op::type2 WT;
+ typedef typename Op::rtype DT;
+ const T* src0 = (const T*)srcmat.data;
+ DT* dst0 = (DT*)dstmat.data;
+ size_t step1 = srcmat.step/sizeof(src0[0]);
+ size_t step = dstmat.step/sizeof(dst0[0]);
+ int cn = dstmat.channels();
+ Size size = getContinuousSize( srcmat, dstmat, cn );
+ WT scalar[12];
+ _scalar.convertTo(scalar, cn, 12);
+
+ for( ; size.height--; src0 += step1, dst0 += step )
+ {
+ int i, len = size.width;
+ const T* src = src0;
+ T* dst = dst0;
+
+ for( ; (len -= 12) >= 0; dst += 12, src += 12 )
+ {
+ DT t0 = op(src[0], scalar[0]);
+ DT t1 = op(src[1], scalar[1]);
+ dst[0] = t0; dst[1] = t1;
+
+ t0 = op(src[2], scalar[2]);
+ t1 = op(src[3], scalar[3]);
+ dst[2] = t0; dst[3] = t1;
+
+ t0 = op(src[4], scalar[4]);
+ t1 = op(src[5], scalar[5]);
+ dst[4] = t0; dst[5] = t1;
+
+ t0 = op(src[6], scalar[6]);
+ t1 = op(src[7], scalar[7]);
+ dst[6] = t0; dst[7] = t1;
+
+ t0 = op(src[8], scalar[8]);
+ t1 = op(src[9], scalar[9]);
+ dst[8] = t0; dst[9] = t1;
+
+ t0 = op(src[10], scalar[10]);
+ t1 = op(src[11], scalar[11]);
+ dst[10] = t0; dst[11] = t1;
+ }
+
+ for( (len) += 12, i = 0; i < (len); i++ )
+ dst[i] = op((WT)src[i], scalar[i]);
+ }
+}
+
+template<class Op> static void
+binarySOpC1_( const Mat& srcmat, Mat& dstmat, double _scalar )
+{
+ Op op;
+ typedef typename Op::type1 T;
+ typedef typename Op::type2 WT;
+ typedef typename Op::rtype DT;
+ WT scalar = saturate_cast<WT>(_scalar);
+ const T* src = (const T*)srcmat.data;
+ DT* dst = (DT*)dstmat.data;
+ size_t step1 = srcmat.step/sizeof(src[0]);
+ size_t step = dstmat.step/sizeof(dst[0]);
+ Size size = srcmat.size();
+
+ size.width *= srcmat.channels();
+ if( srcmat.isContinuous() && dstmat.isContinuous() )
+ {
+ size.width *= size.height;
+ size.height = 1;
+ }
+
+ for( ; size.height--; src += step1, dst += step )
+ {
+ int x;
+ for( x = 0; x <= size.width - 4; x += 4 )
+ {
+ DT f0 = op( src[x], scalar );
+ DT f1 = op( src[x+1], scalar );
+ dst[x] = f0;
+ dst[x+1] = f1;
+ f0 = op( src[x+2], scalar );
+ f1 = op( src[x+3], scalar );
+ dst[x+2] = f0;
+ dst[x+3] = f1;
+ }
+
+ for( ; x < size.width; x++ )
+ dst[x] = op( src[x], scalar );
+ }
+}
+
+typedef void (*BinarySFuncCn)(const Mat& src1, Mat& dst, const Scalar& scalar);
+typedef void (*BinarySFuncC1)(const Mat& src1, Mat& dst, double scalar);
+
+}
+
+#endif /*_CXCORE_INTERNAL_H_*/