cvlogic.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 939 行 · 第 1/3 页
SVN-BASE
939 行
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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*/
/* ////////////////////////////////////////////////////////////////////
//
// CvMat logical operations: &, |, ^ ...
//
// */
#include "_cv.h"
/////////////////////////////////////////////////////////////////////////////////////////
// //
// Macros for logic operations //
// //
/////////////////////////////////////////////////////////////////////////////////////////
/* //////////////////////////////////////////////////////////////////////////////////////
Mat op Mat
////////////////////////////////////////////////////////////////////////////////////// */
#define ICV_DEF_BIN_LOG_OP_2D( __op__, name ) \
IPCVAPI_IMPL( CvStatus, icv##name##_8u_C1R, \
( const uchar* src1, int step1, const uchar* src2, int step2, \
uchar* dst, int step, CvSize size )) \
{ \
for( ; size.height--; src1 += step1, src2 += step2, dst += step ) \
{ \
int i; \
\
for( i = 0; i <= size.width - 16; i += 16 ) \
{ \
int t0 = __op__(((const int*)(src1+i))[0], ((const int*)(src2+i))[0]); \
int t1 = __op__(((const int*)(src1+i))[1], ((const int*)(src2+i))[1]); \
\
((int*)(dst+i))[0] = t0; \
((int*)(dst+i))[1] = t1; \
\
t0 = __op__(((const int*)(src1+i))[2], ((const int*)(src2+i))[2]); \
t1 = __op__(((const int*)(src1+i))[3], ((const int*)(src2+i))[3]); \
\
((int*)(dst+i))[2] = t0; \
((int*)(dst+i))[3] = t1; \
} \
\
for( ; i <= size.width - 4; i += 4 ) \
{ \
int t = __op__(*(const int*)(src1+i), *(const int*)(src2+i)); \
*(int*)(dst+i) = t; \
} \
\
for( ; i < size.width; i++ ) \
{ \
int t = __op__(((const uchar*)src1)[i],((const uchar*)src2)[i]); \
dst[i] = (uchar)t; \
} \
} \
\
return CV_OK; \
}
/* //////////////////////////////////////////////////////////////////////////////////////
Mat op Scalar
////////////////////////////////////////////////////////////////////////////////////// */
#define ICV_DEF_UN_LOG_OP_2D( __op__, name ) \
IPCVAPI_IMPL( CvStatus, icv##name##_8u_C1R, \
( const uchar* src0, int step1, \
uchar* dst0, int step, CvSize size, \
const uchar* scalar, int pix_size )) \
{ \
int delta = 12*pix_size; \
\
for( ; size.height--; src0 += step1, dst0 += step ) \
{ \
const uchar* src = (const uchar*)src0; \
uchar* dst = dst0; \
int i, len = size.width; \
\
while( (len -= delta) >= 0 ) \
{ \
for( i = 0; i < (delta); i += 12 ) \
{ \
int t0 = __op__(((const int*)(src+i))[0], ((const int*)(scalar+i))[0]); \
int t1 = __op__(((const int*)(src+i))[1], ((const int*)(scalar+i))[1]); \
\
((int*)(dst+i))[0] = t0; \
((int*)(dst+i))[1] = t1; \
\
t0 = __op__(((const int*)(src+i))[2], ((const int*)(scalar+i))[2]); \
\
((int*)(dst+i))[2] = t0; \
} \
src += delta; \
dst += delta; \
} \
\
for( len += delta, i = 0; i < len; i++ ) \
{ \
int t = __op__(src[i],scalar[i]); \
dst[i] = (uchar)t; \
} \
} \
\
return CV_OK; \
}
/////////////////////////////////////////////////////////////////////////////////////////
// //
// Macros for logic operations with mask //
// //
/////////////////////////////////////////////////////////////////////////////////////////
#define IPCV_MASK_LOGIC( name ) \
IPCVAPI( CvStatus, icv##name##_8u_CnMR, \
( const uchar* src1, int srcstep1, const uchar* mask, int maskstep, \
uchar* dst, int dststep, CvSize size, int pixSize )) \
IPCVAPI( CvStatus, icv##name##C_8u_CnMR, \
( uchar* dst, int dststep, const uchar* mask, int maskstep, \
CvSize size, const uchar* scalar, int pixSize ))
IPCV_MASK_LOGIC( And )
IPCV_MASK_LOGIC( Or )
IPCV_MASK_LOGIC( Xor )
/* //////////////////////////////////////////////////////////////////////////////////////
Mat op Mat
////////////////////////////////////////////////////////////////////////////////////// */
#define ICV_DEF_BIN_LOG_OP_MASK( __op__, _mask_op_, arrtype, worktype, \
src, dst, mask, len, cn ) \
{ \
int i; \
for( i = 0; i <= (len) - 4; i += 4, src += 4*(cn), dst += 4*(cn) ) \
{ \
int k = cn - 1; \
int m = 0; \
\
do \
{ \
worktype t0 = (mask)[i] ? -1 : 0; \
worktype t1 = (mask)[i+1] ? -1 : 0; \
\
t0 = _mask_op_( t0, (src)[k]); \
t1 = _mask_op_( t1, (src)[k+(cn)]); \
\
t0 = __op__( t0, (dst)[k]); \
t1 = __op__( t1, (dst)[k+(cn)]); \
\
(dst)[k] = (arrtype)t0; \
(dst)[k+(cn)] = (arrtype)t1; \
\
t0 = (mask)[i+2] ? -1 : 0; \
t1 = (mask)[i+3] ? -1 : 0; \
\
t0 = _mask_op_( t0, (src)[k+2*(cn)]); \
t1 = _mask_op_( t1, (src)[k+3*(cn)]); \
\
t0 = __op__( t0, (dst)[k+2*(cn)]); \
t1 = __op__( t1, (dst)[k+3*(cn)]); \
\
(dst)[k+2*(cn)] = (arrtype)t0; \
(dst)[k+3*(cn)] = (arrtype)t1; \
} \
while( k-- && (m || (m = (mask[i]|mask[i+1]|mask[i+2]|mask[i+3])) != 0));\
} \
\
for( ; i < (len); i++, src += cn, dst += cn ) \
{ \
int k = cn - 1; \
do \
{ \
worktype t = (mask)[i] ? -1 : 0; \
t = _mask_op_( t, (src)[k] ); \
t = __op__( t, (dst)[k] ); \
(dst)[k] = (arrtype)t; \
} \
while( k-- && mask[i] != 0 ); \
} \
}
#define ICV_DEF_BIN_LOG_OP_MASK_2D( __op__, _mask_op_, name ) \
IPCVAPI_IMPL( CvStatus, \
icv##name##_8u_CnMR,( const uchar* src, int step1, const uchar* mask, int step2, \
uchar* dst, int step, CvSize size, int cn )) \
{ \
for( ; size.height--; (char*&)src += step1, mask += step2, (char*&)dst += step ) \
{ \
const uchar* tsrc = src; \
uchar* tdst = dst; \
\
ICV_DEF_BIN_LOG_OP_MASK( __op__, _mask_op_, uchar, \
int, tsrc, tdst, mask, size.width, cn ) \
} \
\
return CV_OK; \
}
/* //////////////////////////////////////////////////////////////////////////////////////
Mat op Scalar
////////////////////////////////////////////////////////////////////////////////////// */
#define ICV_DEF_UN_LOG_OP_MASK( __op__, _mask_op_, arrtype, worktype, \
dst, mask, len, cn ) \
{ \
int i; \
for( i = 0; i <= (len) - 4; i += 4, dst += 4*(cn) ) \
{ \
int k = cn - 1; \
int m = 0; \
\
do \
{ \
arrtype value = scalar[k]; \
worktype t0 = (mask)[i] ? -1 : 0; \
worktype t1 = (mask)[i+1] ? -1 : 0; \
\
t0 = _mask_op_( t0, value ); \
t1 = _mask_op_( t1, value ); \
\
t0 = __op__( t0, (dst)[k]); \
t1 = __op__( t1, (dst)[k+(cn)]); \
\
(dst)[k] = (arrtype)t0; \
(dst)[k+(cn)] = (arrtype)t1; \
\
t0 = (mask)[i+2] ? -1 : 0; \
t1 = (mask)[i+3] ? -1 : 0; \
\
t0 = _mask_op_( t0, value ); \
t1 = _mask_op_( t1, value ); \
\
t0 = __op__( t0, (dst)[k+2*(cn)]); \
t1 = __op__( t1, (dst)[k+3*(cn)]); \
\
(dst)[k+2*(cn)] = (arrtype)t0; \
(dst)[k+3*(cn)] = (arrtype)t1; \
} \
while( k-- && (m || (m = (mask[i]|mask[i+1]|mask[i+2]|mask[i+3])) != 0));\
} \
\
for( ; i < (len); i++, dst += cn ) \
{ \
int k = cn - 1; \
do \
{ \
worktype t = (mask)[i] ? -1 : 0; \
t = _mask_op_( t, scalar[k] ); \
t = __op__( t, (dst)[k] ); \
(dst)[k] = (arrtype)t; \
} \
while( k-- && mask[i] != 0 ); \
} \
}
#define ICV_DEF_UN_LOG_OP_MASK_2D( __op__, _mask_op_, name ) \
IPCVAPI_IMPL( CvStatus, \
icv##name##C_8u_CnMR,( uchar* dst, int step, const uchar* mask, int maskstep, \
CvSize size, const uchar* scalar, int cn )) \
{ \
for( ; size.height--; mask += maskstep, (char*&)dst += step ) \
{ \
uchar* tdst = dst; \
\
ICV_DEF_UN_LOG_OP_MASK( __op__, _mask_op_, uchar, int, \
tdst, mask, size.width, cn ) \
} \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?