?? cxarithm.cpp
字號:
if( !maskarr )
{
if( CV_IS_MAT_CONT( src->type & dst->type ))
{
if( size.width <= CV_MAX_INLINE_MAT_OP_SIZE )
{
int len = size.width * size.height;
if( type == CV_32FC1 )
{
const float* srcdata = (const float*)(src->data.ptr);
float* dstdata = (float*)(dst->data.ptr);
do
{
dstdata[len-1] = (float)(scalar.val[0] - srcdata[len-1]);
}
while( --len );
EXIT;
}
if( type == CV_64FC1 )
{
const double* srcdata = (const double*)(src->data.ptr);
double* dstdata = (double*)(dst->data.ptr);
do
{
dstdata[len-1] = scalar.val[0] - srcdata[len-1];
}
while( --len );
EXIT;
}
}
cont_flag = 1;
}
dy = size.height;
copym_func = 0;
tdst = dst;
}
else
{
int buf_size, elem_size;
if( !CV_IS_MAT(mask) )
CV_CALL( mask = cvGetMat( mask, &maskstub ));
if( !CV_IS_MASK_ARR(mask))
CV_ERROR( CV_StsBadMask, "" );
if( !CV_ARE_SIZES_EQ( mask, dst ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
cont_flag = CV_IS_MAT_CONT( src->type & dst->type & mask->type );
elem_size = CV_ELEM_SIZE(type);
dy = CV_MAX_LOCAL_SIZE/(elem_size*size.height);
dy = MAX(dy,1);
dy = MIN(dy,size.height);
dstbuf = cvMat( dy, size.width, type );
if( !cont_flag )
dstbuf.step = cvAlign( dstbuf.step, 8 );
buf_size = dstbuf.step ? dstbuf.step*dy : size.width*elem_size;
if( buf_size > CV_MAX_LOCAL_SIZE )
{
CV_CALL( buffer = (uchar*)cvAlloc( buf_size ));
local_alloc = 0;
}
else
buffer = (uchar*)cvAlloc( buf_size );
dstbuf.data.ptr = buffer;
tdst = &dstbuf;
copym_func = icvGetCopyMaskFunc( elem_size );
}
func = (CvFunc2D_2A1P)(subr_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
src_step = src->step;
dst_step = dst->step;
tdst_step = tdst->step;
mask_step = mask ? mask->step : 0;
CV_CALL( cvScalarToRawData( &scalar, buf, sctype, 1 ));
for( y = 0; y < size.height; y += dy )
{
tsize.width = size.width;
tsize.height = dy;
if( y + dy > size.height )
tsize.height = size.height - y;
if( cont_flag || tsize.height == 1 )
{
tsize.width *= tsize.height;
tsize.height = 1;
src_step = tdst_step = dst_step = mask_step = CV_STUB_STEP;
}
IPPI_CALL( func( src->data.ptr + y*src->step, src_step,
tdst->data.ptr, tdst_step,
cvSize( tsize.width*cn, tsize.height ), buf ));
if( mask )
{
IPPI_CALL( copym_func( tdst->data.ptr, tdst_step, dst->data.ptr + y*dst->step,
dst_step, tsize, mask->data.ptr + y*mask->step, mask_step ));
}
}
__END__;
if( !local_alloc )
cvFree( &buffer );
}
/******************************* A D D ********************************/
CV_IMPL void
cvAdd( const void* srcarr1, const void* srcarr2,
void* dstarr, const void* maskarr )
{
static CvFuncTable add_tab;
static int inittab = 0;
int local_alloc = 1;
uchar* buffer = 0;
CV_FUNCNAME( "cvAdd" );
__BEGIN__;
int y, dy, type, depth, cn, cont_flag = 0;
int src1_step, src2_step, dst_step, tdst_step, mask_step;
CvMat srcstub1, *src1 = (CvMat*)srcarr1;
CvMat srcstub2, *src2 = (CvMat*)srcarr2;
CvMat dststub, *dst = (CvMat*)dstarr;
CvMat maskstub, *mask = (CvMat*)maskarr;
CvMat dstbuf, *tdst;
CvFunc2D_3A func;
CvFunc2D_3A1I func_sfs;
CvCopyMaskFunc copym_func;
CvSize size, tsize;
if( !CV_IS_MAT(src1) || !CV_IS_MAT(src2) || !CV_IS_MAT(dst))
{
if( CV_IS_MATND(src1) || CV_IS_MATND(src2) || CV_IS_MATND(dst))
{
CvArr* arrs[] = { src1, src2, dst };
CvMatND stubs[3];
CvNArrayIterator iterator;
if( maskarr )
CV_ERROR( CV_StsBadMask,
"This operation on multi-dimensional arrays does not support mask" );
CV_CALL( cvInitNArrayIterator( 3, arrs, 0, stubs, &iterator ));
type = iterator.hdr[0]->type;
iterator.size.width *= CV_MAT_CN(type);
if( !inittab )
{
icvInitAddC1RTable( &add_tab );
inittab = 1;
}
depth = CV_MAT_DEPTH(type);
if( depth <= CV_16S )
{
func_sfs = (CvFunc2D_3A1I)(add_tab.fn_2d[depth]);
if( !func_sfs )
CV_ERROR( CV_StsUnsupportedFormat, "" );
do
{
IPPI_CALL( func_sfs( iterator.ptr[0], CV_STUB_STEP,
iterator.ptr[1], CV_STUB_STEP,
iterator.ptr[2], CV_STUB_STEP,
iterator.size, 0 ));
}
while( cvNextNArraySlice( &iterator ));
}
else
{
func = (CvFunc2D_3A)(add_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
do
{
IPPI_CALL( func( iterator.ptr[0], CV_STUB_STEP,
iterator.ptr[1], CV_STUB_STEP,
iterator.ptr[2], CV_STUB_STEP,
iterator.size ));
}
while( cvNextNArraySlice( &iterator ));
}
EXIT;
}
else
{
int coi1 = 0, coi2 = 0, coi3 = 0;
CV_CALL( src1 = cvGetMat( src1, &srcstub1, &coi1 ));
CV_CALL( src2 = cvGetMat( src2, &srcstub2, &coi2 ));
CV_CALL( dst = cvGetMat( dst, &dststub, &coi3 ));
if( coi1 + coi2 + coi3 != 0 )
CV_ERROR( CV_BadCOI, "" );
}
}
if( !CV_ARE_TYPES_EQ( src1, src2 ) || !CV_ARE_TYPES_EQ( src1, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );
if( !CV_ARE_SIZES_EQ( src1, src2 ) || !CV_ARE_SIZES_EQ( src1, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );
type = CV_MAT_TYPE(src1->type);
size = cvGetMatSize( src1 );
depth = CV_MAT_DEPTH(type);
cn = CV_MAT_CN(type);
if( !mask )
{
if( CV_IS_MAT_CONT( src1->type & src2->type & dst->type ))
{
int len = size.width*size.height*cn;
if( len <= CV_MAX_INLINE_MAT_OP_SIZE*CV_MAX_INLINE_MAT_OP_SIZE )
{
if( depth == CV_32F )
{
const float* src1data = (const float*)(src1->data.ptr);
const float* src2data = (const float*)(src2->data.ptr);
float* dstdata = (float*)(dst->data.ptr);
do
{
dstdata[len-1] = (float)(src1data[len-1] + src2data[len-1]);
}
while( --len );
EXIT;
}
if( depth == CV_64F )
{
const double* src1data = (const double*)(src1->data.ptr);
const double* src2data = (const double*)(src2->data.ptr);
double* dstdata = (double*)(dst->data.ptr);
do
{
dstdata[len-1] = src1data[len-1] + src2data[len-1];
}
while( --len );
EXIT;
}
}
cont_flag = 1;
}
dy = size.height;
copym_func = 0;
tdst = dst;
}
else
{
int buf_size, elem_size;
if( !CV_IS_MAT(mask) )
CV_CALL( mask = cvGetMat( mask, &maskstub ));
if( !CV_IS_MASK_ARR(mask))
CV_ERROR( CV_StsBadMask, "" );
if( !CV_ARE_SIZES_EQ( mask, dst ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
cont_flag = CV_IS_MAT_CONT( src1->type & src2->type & dst->type & mask->type );
elem_size = CV_ELEM_SIZE(type);
dy = CV_MAX_LOCAL_SIZE/(elem_size*size.height);
dy = MAX(dy,1);
dy = MIN(dy,size.height);
dstbuf = cvMat( dy, size.width, type );
if( !cont_flag )
dstbuf.step = cvAlign( dstbuf.step, 8 );
buf_size = dstbuf.step ? dstbuf.step*dy : size.width*elem_size;
if( buf_size > CV_MAX_LOCAL_SIZE )
{
CV_CALL( buffer = (uchar*)cvAlloc( buf_size ));
local_alloc = 0;
}
else
buffer = (uchar*)cvAlloc( buf_size );
dstbuf.data.ptr = buffer;
tdst = &dstbuf;
copym_func = icvGetCopyMaskFunc( elem_size );
}
if( !inittab )
{
icvInitAddC1RTable( &add_tab );
inittab = 1;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -