📄 cxsumpixels.cpp
字号:
\
ICV_SUM_EXIT_BLOCK_C##cn( sumtype_final ); \
return CV_OK; \
}
#define ICV_DEF_SUM_NOHINT_FUNC_2D( name, flavor, cn, \
__op__, arrtype, sumtype_final, sumtype, worktype, block_size )\
IPCVAPI_IMPL(CvStatus, icv##name##_##flavor##_C##cn##R,( \
const arrtype* src, int step, CvSize size, \
sumtype_final* sum ), (src, step, size, sum) ) \
{ \
ICV_SUM_ENTRY_C##cn( sumtype ); \
size.width *= cn; \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
ICV_SUM_CASE_C##cn( __op__, size.width ); \
} \
\
ICV_SUM_EXIT_C##cn( s, sumtype_final ); \
return CV_OK; \
}
#define ICV_DEF_SUM_HINT_FUNC_2D( name, flavor, cn, \
__op__, arrtype, sumtype_final, sumtype, worktype, block_size )\
IPCVAPI_IMPL(CvStatus, icv##name##_##flavor##_C##cn##R,( \
const arrtype* src, int step, CvSize size, \
sumtype_final* sum, CvHintAlgorithm /*hint*/ ), \
(src, step, size, sum, cvAlgHintAccurate) ) \
{ \
ICV_SUM_ENTRY_C##cn( sumtype ); \
size.width *= cn; \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
ICV_SUM_CASE_C##cn( __op__, size.width ); \
} \
\
ICV_SUM_EXIT_C##cn( s, sumtype_final ); \
return CV_OK; \
}
#define ICV_DEF_SUM_NOHINT_BLOCK_FUNC_2D_COI( name, flavor, \
__op__, arrtype, sumtype_final, sumtype, worktype, block_size )\
static CvStatus CV_STDCALL icv##name##_##flavor##_CnCR( \
const arrtype* src, int step, CvSize size, int cn, \
int coi, sumtype_final* sum ) \
{ \
ICV_SUM_ENTRY_BLOCK_C1(sumtype,worktype,(block_size)*(cn)); \
size.width *= cn; \
src += coi - 1; \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
while( x < size.width ) \
{ \
int limit = MIN( remaining, size.width - x ); \
remaining -= limit; \
limit += x; \
ICV_SUM_COI_CASE( __op__, limit, cn ); \
if( remaining == 0 ) \
{ \
ICV_SUM_UPDATE_C1( (block_size)*(cn) ); \
} \
} \
} \
\
ICV_SUM_EXIT_BLOCK_C1( sumtype_final ); \
return CV_OK; \
}
#define ICV_DEF_SUM_NOHINT_FUNC_2D_COI( name, flavor, \
__op__, arrtype, sumtype_final, sumtype, worktype, block_size )\
static CvStatus CV_STDCALL icv##name##_##flavor##_CnCR( \
const arrtype* src, int step, CvSize size, int cn, \
int coi, sumtype_final* sum ) \
{ \
ICV_SUM_ENTRY_C1( sumtype ); \
size.width *= cn; \
src += coi - 1; \
\
for( ; size.height--; src += step ) \
{ \
int x = 0; \
ICV_SUM_COI_CASE( __op__, size.width, cn ); \
} \
\
ICV_SUM_EXIT_C1( s, sumtype_final ); \
return CV_OK; \
}
#define ICV_DEF_SUM_ALL( name, flavor, __op__, arrtype, sumtype_final, sumtype, \
worktype, hintp_type, nohint_type, block_size ) \
ICV_DEF_SUM_##hintp_type##_FUNC_2D( name, flavor, 1, __op__, arrtype, \
sumtype_final, sumtype, worktype, block_size ) \
ICV_DEF_SUM_##hintp_type##_FUNC_2D( name, flavor, 2, __op__, arrtype, \
sumtype_final, sumtype, worktype, block_size ) \
ICV_DEF_SUM_##hintp_type##_FUNC_2D( name, flavor, 3, __op__, arrtype, \
sumtype_final, sumtype, worktype, block_size ) \
ICV_DEF_SUM_##hintp_type##_FUNC_2D( name, flavor, 4, __op__, arrtype, \
sumtype_final, sumtype, worktype, block_size ) \
ICV_DEF_SUM_##nohint_type##_FUNC_2D_COI( name, flavor, __op__, arrtype, \
sumtype_final, sumtype, worktype, block_size )
ICV_DEF_SUM_ALL( Sum, 8u, CV_NOP, uchar, double, int64, unsigned,
NOHINT_BLOCK, NOHINT_BLOCK, 1 << 24 )
ICV_DEF_SUM_ALL( Sum, 16u, CV_NOP, ushort, double, int64, unsigned,
NOHINT_BLOCK, NOHINT_BLOCK, 1 << 16 )
ICV_DEF_SUM_ALL( Sum, 16s, CV_NOP, short, double, int64, int,
NOHINT_BLOCK, NOHINT_BLOCK, 1 << 16 )
ICV_DEF_SUM_ALL( Sum, 32s, CV_NOP, int, double, double, double, NOHINT, NOHINT, 0 )
ICV_DEF_SUM_ALL( Sum, 32f, CV_NOP, float, double, double, double, HINT, NOHINT, 0 )
ICV_DEF_SUM_ALL( Sum, 64f, CV_NOP, double, double, double, double, NOHINT, NOHINT, 0 )
#define icvSum_8s_C1R 0
#define icvSum_8s_C2R 0
#define icvSum_8s_C3R 0
#define icvSum_8s_C4R 0
#define icvSum_8s_CnCR 0
CV_DEF_INIT_BIG_FUNC_TAB_2D( Sum, R )
CV_DEF_INIT_FUNC_TAB_2D( Sum, CnCR )
CV_IMPL CvScalar
cvSum( const CvArr* arr )
{
static CvBigFuncTable sum_tab;
static CvFuncTable sumcoi_tab;
static int inittab = 0;
CvScalar sum = {{0,0,0,0}};
CV_FUNCNAME("cvSum");
__BEGIN__;
int type, coi = 0;
int mat_step;
CvSize size;
CvMat stub, *mat = (CvMat*)arr;
if( !inittab )
{
icvInitSumRTable( &sum_tab );
icvInitSumCnCRTable( &sumcoi_tab );
inittab = 1;
}
if( !CV_IS_MAT(mat) )
{
if( CV_IS_MATND(mat) )
{
void* matnd = (void*)mat;
CvMatND nstub;
CvNArrayIterator iterator;
int pass_hint;
CV_CALL( cvInitNArrayIterator( 1, &matnd, 0, &nstub, &iterator ));
type = CV_MAT_TYPE(iterator.hdr[0]->type);
if( CV_MAT_CN(type) > 4 )
CV_ERROR( CV_StsOutOfRange, "The input array must have at most 4 channels" );
pass_hint = CV_MAT_DEPTH(type) == CV_32F;
if( !pass_hint )
{
CvFunc2D_1A1P func = (CvFunc2D_1A1P)(sum_tab.fn_2d[type]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
do
{
CvScalar temp = {{0,0,0,0}};
IPPI_CALL( func( iterator.ptr[0], CV_STUB_STEP,
iterator.size, temp.val ));
sum.val[0] += temp.val[0];
sum.val[1] += temp.val[1];
sum.val[2] += temp.val[2];
sum.val[3] += temp.val[3];
}
while( cvNextNArraySlice( &iterator ));
}
else
{
CvFunc2D_1A1P1I func = (CvFunc2D_1A1P1I)(sum_tab.fn_2d[type]);
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
do
{
CvScalar temp = {{0,0,0,0}};
IPPI_CALL( func( iterator.ptr[0], CV_STUB_STEP,
iterator.size, temp.val, cvAlgHintAccurate ));
sum.val[0] += temp.val[0];
sum.val[1] += temp.val[1];
sum.val[2] += temp.val[2];
sum.val[3] += temp.val[3];
}
while( cvNextNArraySlice( &iterator ));
}
EXIT;
}
else
CV_CALL( mat = cvGetMat( mat, &stub, &coi ));
}
type = CV_MAT_TYPE(mat->type);
size = cvGetMatSize( mat );
mat_step = mat->step;
if( CV_IS_MAT_CONT( mat->type ))
{
size.width *= size.height;
if( size.width <= CV_MAX_INLINE_MAT_OP_SIZE )
{
if( type == CV_32FC1 )
{
float* data = mat->data.fl;
do
{
sum.val[0] += data[size.width - 1];
}
while( --size.width );
EXIT;
}
if( type == CV_64FC1 )
{
double* data = mat->data.db;
do
{
sum.val[0] += data[size.width - 1];
}
while( --size.width );
EXIT;
}
}
size.height = 1;
mat_step = CV_STUB_STEP;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -