?? cxarithm.cpp
字號(hào):
iterator.size.width *= CV_MAT_CN(type);
if( !inittab )
{
icvInitSubC1RTable( &sub_tab );
inittab = 1;
}
depth = CV_MAT_DEPTH(type);
if( depth <= CV_16S )
{
func_sfs = (CvFunc2D_3A1I)(sub_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)(sub_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)(src2data[len-1] - src1data[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] = src2data[len-1] - src1data[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 )
{
icvInitSubC1RTable( &sub_tab );
inittab = 1;
}
if( depth <= CV_16S )
{
func = 0;
func_sfs = (CvFunc2D_3A1I)(sub_tab.fn_2d[depth]);
if( !func_sfs )
CV_ERROR( CV_StsUnsupportedFormat, "" );
}
else
{
func_sfs = 0;
func = (CvFunc2D_3A)(sub_tab.fn_2d[depth]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
}
src1_step = src1->step;
src2_step = src2->step;
dst_step = dst->step;
tdst_step = tdst->step;
mask_step = mask ? mask->step : 0;
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;
src1_step = src2_step = tdst_step = dst_step = mask_step = CV_STUB_STEP;
}
IPPI_CALL( depth <= CV_16S ?
func_sfs( src1->data.ptr + y*src1->step, src1_step,
src2->data.ptr + y*src2->step, src2_step,
tdst->data.ptr, tdst_step,
cvSize( tsize.width*cn, tsize.height ), 0 ) :
func( src1->data.ptr + y*src1->step, src1_step,
src2->data.ptr + y*src2->step, src2_step,
tdst->data.ptr, tdst_step,
cvSize( tsize.width*cn, tsize.height )));
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 );
}
CV_IMPL void
cvSubRS( const void* srcarr, CvScalar scalar, void* dstarr, const void* maskarr )
{
static CvFuncTable subr_tab;
static int inittab = 0;
int local_alloc = 1;
uchar* buffer = 0;
CV_FUNCNAME( "cvSubRS" );
__BEGIN__;
int sctype, y, dy, type, depth, cn, coi = 0, cont_flag = 0;
int src_step, dst_step, tdst_step, mask_step;
CvMat srcstub, *src = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvMat maskstub, *mask = (CvMat*)maskarr;
CvMat dstbuf, *tdst;
CvFunc2D_2A1P func;
CvCopyMaskFunc copym_func;
double buf[12];
int is_nd = 0;
CvSize size, tsize;
if( !inittab )
{
icvInitSubRCC1RTable( &subr_tab );
inittab = 1;
}
if( !CV_IS_MAT(src) )
{
if( CV_IS_MATND(src) )
is_nd = 1;
else
{
CV_CALL( src = cvGetMat( src, &srcstub, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
}
if( !CV_IS_MAT(dst) )
{
if( CV_IS_MATND(dst) )
is_nd = 1;
else
{
CV_CALL( dst = cvGetMat( dst, &dststub, &coi ));
if( coi != 0 )
CV_ERROR( CV_BadCOI, "" );
}
}
if( is_nd )
{
CvArr* arrs[] = { src, dst };
CvMatND stubs[2];
CvNArrayIterator iterator;
if( maskarr )
CV_ERROR( CV_StsBadMask,
"This operation on multi-dimensional arrays does not support mask" );
CV_CALL( cvInitNArrayIterator( 2, arrs, 0, stubs, &iterator ));
sctype = type = CV_MAT_TYPE(iterator.hdr[0]->type);
if( CV_MAT_DEPTH(sctype) < CV_32S )
sctype = (type & CV_MAT_CN_MASK) | CV_32SC1;
iterator.size.width *= CV_MAT_CN(type);
func = (CvFunc2D_2A1P)(subr_tab.fn_2d[CV_MAT_DEPTH(type)]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
CV_CALL( cvScalarToRawData( &scalar, buf, sctype, 1 ));
do
{
IPPI_CALL( func( iterator.ptr[0], CV_STUB_STEP,
iterator.ptr[1], CV_STUB_STEP,
iterator.size, buf ));
}
while( cvNextNArraySlice( &iterator ));
EXIT;
}
if( !CV_ARE_TYPES_EQ( src, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );
if( !CV_ARE_SIZES_EQ( src, dst ))
CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );
sctype = type = CV_MAT_TYPE(src->type);
depth = CV_MAT_DEPTH(type);
cn = CV_MAT_CN(type);
if( depth < CV_32S )
sctype = (type & CV_MAT_CN_MASK) | CV_32SC1;
size = cvGetMatSize( src );
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -