cvcopy.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 1,092 行 · 第 1/3 页
SVN-BASE
1,092 行
/*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 basic operations: cvCopy, cvSet
//
// */
#include "_cv.h"
#include "_cvdatastructs.h"
/////////////////////////////////////////////////////////////////////////////////////////
// //
// L/L COPY & SET FUNCTIONS //
// //
/////////////////////////////////////////////////////////////////////////////////////////
IPCVAPI_IMPL( CvStatus, icvCopy_8u_C1R, ( const uchar* src, int src_step,
uchar* dst, int dst_step, CvSize size ))
{
for( ; size.height--; src += src_step, dst += dst_step )
memcpy( dst, src, size.width );
return CV_OK;
}
IPCVAPI_IMPL( CvStatus, icvSet_8u_C1R, ( uchar* dst, int dst_step, CvSize size,
const void* scalar, int pix_size ))
{
int copy_len = 12*pix_size;
for( ; size.height--; )
{
uchar* dst_limit = dst + size.width;
while( dst + copy_len <= dst_limit )
{
memcpy( dst, scalar, copy_len );
dst += copy_len;
}
memcpy( dst, scalar, dst_limit - dst );
dst = dst_limit - size.width + dst_step;
}
return CV_OK;
}
/////////////////////////////////////////////////////////////////////////////////////////
// //
// L/L COPY WITH MASK FUNCTIONS //
// //
/////////////////////////////////////////////////////////////////////////////////////////
#define ICV_DEF_COPY_MASK_C1_CASE( type, worktype, src, dst, mask, len )\
{ \
int i; \
\
for( i = 0; i <= (len) - 4; i += 4 ) \
{ \
worktype m0 = (mask)[i] ? -1 : 0; \
worktype m1 = (mask)[i+1] ? -1 : 0; \
worktype t0 = (dst)[i]; \
worktype t1 = (dst)[i+1]; \
\
t0 ^= (t0 ^ (src)[i]) & m0; \
t1 ^= (t1 ^ (src)[i+1]) & m1; \
\
(dst)[i] = (type)t0; \
(dst)[i+1] = (type)t1; \
\
m0 = (mask)[i+2] ? -1 : 0; \
m1 = (mask)[i+3] ? -1 : 0; \
t0 = (dst)[i+2]; \
t1 = (dst)[i+3]; \
\
t0 ^= (t0 ^ (src)[i+2]) & m0; \
t1 ^= (t1 ^ (src)[i+3]) & m1; \
\
(dst)[i+2] = (type)t0; \
(dst)[i+3] = (type)t1; \
} \
\
for( ; i < (len); i++ ) \
{ \
worktype m = (mask)[i] ? -1 : 0; \
worktype t = (dst)[i]; \
\
t ^= (t ^ (src)[i]) & m; \
\
(dst)[i] = (type)t; \
} \
}
#define ICV_DEF_COPY_MASK_C3_CASE( type, worktype, src, dst, mask, len )\
{ \
int i; \
\
for( i = 0; i < (len); i++ ) \
{ \
worktype m = (mask)[i] ? -1 : 0; \
worktype t0 = (dst)[i*3]; \
worktype t1 = (dst)[i*3+1]; \
worktype t2 = (dst)[i*3+2]; \
\
t0 ^= (t0 ^ (src)[i*3]) & m; \
t1 ^= (t1 ^ (src)[i*3+1]) & m; \
t2 ^= (t2 ^ (src)[i*3+2]) & m; \
\
(dst)[i*3] = (type)t0; \
(dst)[i*3+1] = (type)t1; \
(dst)[i*3+2] = (type)t2; \
} \
}
#define ICV_DEF_COPY_MASK_C4_CASE( type, worktype, src, dst, mask, len )\
{ \
int i; \
\
for( i = 0; i < (len); i++ ) \
{ \
worktype m = (mask)[i] ? -1 : 0; \
worktype t0 = (dst)[i*4]; \
worktype t1 = (dst)[i*4+1]; \
\
t0 ^= (t0 ^ (src)[i*4]) & m; \
t1 ^= (t1 ^ (src)[i*4+1]) & m; \
\
(dst)[i*4] = (type)t0; \
(dst)[i*4+1] = (type)t1; \
\
t0 = (dst)[i*4+2]; \
t1 = (dst)[i*4+3]; \
\
t0 ^= (t0 ^ (src)[i*4+2]) & m; \
t1 ^= (t1 ^ (src)[i*4+3]) & m; \
\
(dst)[i*4+2] = (type)t0; \
(dst)[i*4+3] = (type)t1; \
} \
}
#define ICV_DEF_COPY_MASK_2D( name, type, worktype, cn ) \
IPCVAPI_IMPL( CvStatus, \
name,( const type* src, int step1, type* dst, int step, \
const uchar* mask, int step2, CvSize size )) \
{ \
for( ; size.height--; (char*&)src += step1, \
(char*&)dst += step, \
mask += step2 ) \
{ \
ICV_DEF_COPY_MASK_C##cn##_CASE( type, worktype, src, \
dst, mask, size.width ) \
} \
\
return CV_OK; \
}
#define ICV_DEF_SET_MASK_C1_CASE( type, worktype, src, dst, mask, len ) \
{ \
int i; \
\
for( i = 0; i <= (len) - 4; i += 4 ) \
{ \
worktype m0 = (mask)[i] ? -1 : 0; \
worktype m1 = (mask)[i+1] ? -1 : 0; \
worktype t0 = (dst)[i]; \
worktype t1 = (dst)[i+1]; \
\
t0 ^= (t0 ^ s0) & m0; \
t1 ^= (t1 ^ s0) & m1; \
\
(dst)[i] = (type)t0; \
(dst)[i+1] = (type)t1; \
\
m0 = (mask)[i+2] ? -1 : 0; \
m1 = (mask)[i+3] ? -1 : 0; \
t0 = (dst)[i+2]; \
t1 = (dst)[i+3]; \
\
t0 ^= (t0 ^ s0) & m0; \
t1 ^= (t1 ^ s0) & m1; \
\
(dst)[i+2] = (type)t0; \
(dst)[i+3] = (type)t1; \
} \
\
for( ; i < (len); i++ ) \
{ \
worktype m = (mask)[i] ? -1 : 0; \
worktype t = (dst)[i]; \
\
t ^= (t ^ s0) & m; \
\
(dst)[i] = (type)t; \
} \
}
#define ICV_DEF_SET_MASK_C3_CASE( type, worktype, src, dst, mask, len ) \
{ \
int i; \
\
for( i = 0; i < (len); i++ ) \
{ \
worktype m = (mask)[i] ? -1 : 0; \
worktype t0 = (dst)[i*3]; \
worktype t1 = (dst)[i*3+1]; \
worktype t2 = (dst)[i*3+2]; \
\
t0 ^= (t0 ^ s0) & m; \
t1 ^= (t1 ^ s1) & m; \
t2 ^= (t2 ^ s2) & m; \
\
(dst)[i*3] = (type)t0; \
(dst)[i*3+1] = (type)t1; \
(dst)[i*3+2] = (type)t2; \
} \
}
#define ICV_DEF_SET_MASK_C4_CASE( type, worktype, src, dst, mask, len ) \
{ \
int i; \
\
for( i = 0; i < (len); i++ ) \
{ \
worktype m = (mask)[i] ? -1 : 0; \
worktype t0 = (dst)[i*4]; \
worktype t1 = (dst)[i*4+1]; \
\
t0 ^= (t0 ^ s0) & m; \
t1 ^= (t1 ^ s1) & m; \
\
(dst)[i*4] = (type)t0; \
(dst)[i*4+1] = (type)t1; \
\
t0 = (dst)[i*4+2]; \
t1 = (dst)[i*4+3]; \
\
t0 ^= (t0 ^ s2) & m; \
t1 ^= (t1 ^ s3) & m; \
\
(dst)[i*4+2] = (type)t0; \
(dst)[i*4+3] = (type)t1; \
} \
}
#define ICV_DEF_SET_MASK_2D( name, type, worktype, cn ) \
IPCVAPI_IMPL( CvStatus, \
name,( type* dst, int step, const uchar* mask, int step2, \
CvSize size, const type* scalar )) \
{ \
ICV_UN_ENTRY_C##cn( worktype ); \
\
for( ; size.height--; mask += step2, (char*&)dst += step ) \
{ \
ICV_DEF_SET_MASK_C##cn##_CASE( type, worktype, buf, \
dst, mask, size.width ) \
} \
\
return CV_OK; \
}
ICV_DEF_SET_MASK_2D( icvSet_8u_C1MR, uchar, int, 1 )
ICV_DEF_SET_MASK_2D( icvSet_8u_C2MR, ushort, int, 1 )
ICV_DEF_SET_MASK_2D( icvSet_8u_C3MR, uchar, int, 3 )
ICV_DEF_SET_MASK_2D( icvSet_16u_C2MR, int, int, 1 )
ICV_DEF_SET_MASK_2D( icvSet_16u_C3MR, ushort, int, 3 )
ICV_DEF_SET_MASK_2D( icvSet_32s_C2MR, int64, int64, 1 )
ICV_DEF_SET_MASK_2D( icvSet_32s_C3MR, int, int, 3 )
ICV_DEF_SET_MASK_2D( icvSet_64s_C2MR, int, int, 4 )
ICV_DEF_SET_MASK_2D( icvSet_64s_C3MR, int64, int64, 3 )
ICV_DEF_SET_MASK_2D( icvSet_64s_C4MR, int64, int64, 4 )
ICV_DEF_COPY_MASK_2D( icvCopy_8u_C1MR, uchar, int, 1 )
ICV_DEF_COPY_MASK_2D( icvCopy_8u_C2MR, ushort, int, 1 )
ICV_DEF_COPY_MASK_2D( icvCopy_8u_C3MR, uchar, int, 3 )
ICV_DEF_COPY_MASK_2D( icvCopy_16u_C2MR, int, int, 1 )
ICV_DEF_COPY_MASK_2D( icvCopy_16u_C3MR, ushort, int, 3 )
ICV_DEF_COPY_MASK_2D( icvCopy_32s_C2MR, int64, int64, 1 )
ICV_DEF_COPY_MASK_2D( icvCopy_32s_C3MR, int, int, 3 )
ICV_DEF_COPY_MASK_2D( icvCopy_64s_C2MR, int, int, 4 )
ICV_DEF_COPY_MASK_2D( icvCopy_64s_C3MR, int64, int64, 3 )
ICV_DEF_COPY_MASK_2D( icvCopy_64s_C4MR, int64, int64, 4 )
CV_DEF_INIT_PIXSIZE_TAB_2D( Set, MR )
CV_DEF_INIT_PIXSIZE_TAB_2D( Copy, MR )
/////////////////////////////////////////////////////////////////////////////////////////
// //
// H/L COPY & SET FUNCTIONS //
// //
/////////////////////////////////////////////////////////////////////////////////////////
/* dst = src */
CV_IMPL void
cvCopy( const void* srcarr, void* dstarr, const void* maskarr )
{
static CvBtFuncTable copym_tab;
static int inittab = 0;
CV_FUNCNAME( "cvCopy" );
__BEGIN__;
int pix_size;
CvMat srcstub, *src = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize size;
if( !CV_IS_MAT(src) || !CV_IS_MAT(dst) )
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?