📄 cxconvert.cpp
字号:
{ \
int j; \
\
for( j = 0; j <= (len) - 4; j += 4, (dst) += 4*(cn))\
{ \
arrtype t0 = (src)[j]; \
arrtype t1 = (src)[j+1]; \
\
(dst)[0] = t0; \
(dst)[(cn)] = t1; \
\
t0 = (src)[j+2]; \
t1 = (src)[j+3]; \
\
(dst)[(cn)*2] = t0; \
(dst)[(cn)*3] = t1; \
} \
\
for( ; j < (len); j++, (dst) += (cn)) \
{ \
(dst)[0] = (src)[j]; \
} \
}
#define ICV_DEF_COPY_PL2PX_FUNC_2D( arrtype, flavor, cn, entry_macro ) \
IPCVAPI_IMPL( CvStatus, icvCopy_##flavor##_P##cn##C##cn##R, \
( const arrtype** src, int srcstep, \
arrtype* dst, int dststep, CvSize size ), \
(src, srcstep, dst, dststep, size)) \
{ \
entry_macro(const arrtype*, src); \
srcstep /= sizeof(src[0][0]); \
dststep /= sizeof(dst[0]); \
\
for( ; size.height--; dst += dststep ) \
{ \
ICV_DEF_PL2PX_C##cn( arrtype, size.width ); \
dst -= size.width*(cn); \
} \
\
return CV_OK; \
}
#define ICV_DEF_COPY_PL2PX_FUNC_2D_COI( arrtype, flavor ) \
IPCVAPI_IMPL( CvStatus, icvCopy_##flavor##_C1CnCR, \
( const arrtype* src, int srcstep, \
arrtype* dst, int dststep, \
CvSize size, int cn, int coi ), \
(src, srcstep, dst, dststep, size, cn, coi)) \
{ \
dst += coi - 1; \
srcstep /= sizeof(src[0]); dststep /= sizeof(dst[0]); \
\
for( ; size.height--; src += srcstep, dst += dststep ) \
{ \
ICV_DEF_PL2PX_COI( arrtype, size.width, cn ); \
dst -= size.width*(cn); \
} \
\
return CV_OK; \
}
ICV_DEF_COPY_PL2PX_FUNC_2D( uchar, 8u, 2, ICV_DEF_PX2PL2PX_ENTRY_C2 )
ICV_DEF_COPY_PL2PX_FUNC_2D( uchar, 8u, 3, ICV_DEF_PX2PL2PX_ENTRY_C3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( uchar, 8u, 4, ICV_DEF_PX2PL2PX_ENTRY_C4 )
ICV_DEF_COPY_PL2PX_FUNC_2D( ushort, 16s, 2, ICV_DEF_PX2PL2PX_ENTRY_C2 )
ICV_DEF_COPY_PL2PX_FUNC_2D( ushort, 16s, 3, ICV_DEF_PX2PL2PX_ENTRY_C3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( ushort, 16s, 4, ICV_DEF_PX2PL2PX_ENTRY_C4 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int, 32f, 2, ICV_DEF_PX2PL2PX_ENTRY_C2 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int, 32f, 3, ICV_DEF_PX2PL2PX_ENTRY_C3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int, 32f, 4, ICV_DEF_PX2PL2PX_ENTRY_C4 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int64, 64f, 2, ICV_DEF_PX2PL2PX_ENTRY_C2 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int64, 64f, 3, ICV_DEF_PX2PL2PX_ENTRY_C3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int64, 64f, 4, ICV_DEF_PX2PL2PX_ENTRY_C4 )
ICV_DEF_COPY_PL2PX_FUNC_2D_COI( uchar, 8u )
ICV_DEF_COPY_PL2PX_FUNC_2D_COI( ushort, 16s )
ICV_DEF_COPY_PL2PX_FUNC_2D_COI( int, 32f )
ICV_DEF_COPY_PL2PX_FUNC_2D_COI( int64, 64f )
#define ICV_DEF_PXPLPX_TAB( name, FROM, TO ) \
static void \
name( CvBigFuncTable* tab ) \
{ \
tab->fn_2d[CV_8UC2] = (void*)icvCopy##_8u_##FROM##2##TO##2R; \
tab->fn_2d[CV_8UC3] = (void*)icvCopy##_8u_##FROM##3##TO##3R; \
tab->fn_2d[CV_8UC4] = (void*)icvCopy##_8u_##FROM##4##TO##4R; \
\
tab->fn_2d[CV_8SC2] = (void*)icvCopy##_8u_##FROM##2##TO##2R; \
tab->fn_2d[CV_8SC3] = (void*)icvCopy##_8u_##FROM##3##TO##3R; \
tab->fn_2d[CV_8SC4] = (void*)icvCopy##_8u_##FROM##4##TO##4R; \
\
tab->fn_2d[CV_16UC2] = (void*)icvCopy##_16s_##FROM##2##TO##2R; \
tab->fn_2d[CV_16UC3] = (void*)icvCopy##_16s_##FROM##3##TO##3R; \
tab->fn_2d[CV_16UC4] = (void*)icvCopy##_16s_##FROM##4##TO##4R; \
\
tab->fn_2d[CV_16SC2] = (void*)icvCopy##_16s_##FROM##2##TO##2R; \
tab->fn_2d[CV_16SC3] = (void*)icvCopy##_16s_##FROM##3##TO##3R; \
tab->fn_2d[CV_16SC4] = (void*)icvCopy##_16s_##FROM##4##TO##4R; \
\
tab->fn_2d[CV_32SC2] = (void*)icvCopy##_32f_##FROM##2##TO##2R; \
tab->fn_2d[CV_32SC3] = (void*)icvCopy##_32f_##FROM##3##TO##3R; \
tab->fn_2d[CV_32SC4] = (void*)icvCopy##_32f_##FROM##4##TO##4R; \
\
tab->fn_2d[CV_32FC2] = (void*)icvCopy##_32f_##FROM##2##TO##2R; \
tab->fn_2d[CV_32FC3] = (void*)icvCopy##_32f_##FROM##3##TO##3R; \
tab->fn_2d[CV_32FC4] = (void*)icvCopy##_32f_##FROM##4##TO##4R; \
\
tab->fn_2d[CV_64FC2] = (void*)icvCopy##_64f_##FROM##2##TO##2R; \
tab->fn_2d[CV_64FC3] = (void*)icvCopy##_64f_##FROM##3##TO##3R; \
tab->fn_2d[CV_64FC4] = (void*)icvCopy##_64f_##FROM##4##TO##4R; \
}
#define ICV_DEF_PXPLCOI_TAB( name, FROM, TO ) \
static void \
name( CvFuncTable* tab ) \
{ \
tab->fn_2d[CV_8U] = (void*)icvCopy##_8u_##FROM##TO##CR; \
tab->fn_2d[CV_8S] = (void*)icvCopy##_8u_##FROM##TO##CR; \
tab->fn_2d[CV_16U] = (void*)icvCopy##_16s_##FROM##TO##CR; \
tab->fn_2d[CV_16S] = (void*)icvCopy##_16s_##FROM##TO##CR; \
tab->fn_2d[CV_32S] = (void*)icvCopy##_32f_##FROM##TO##CR; \
tab->fn_2d[CV_32F] = (void*)icvCopy##_32f_##FROM##TO##CR; \
tab->fn_2d[CV_64F] = (void*)icvCopy##_64f_##FROM##TO##CR; \
}
ICV_DEF_PXPLPX_TAB( icvInitSplitRTable, C, P )
ICV_DEF_PXPLCOI_TAB( icvInitSplitRCoiTable, Cn, C1 )
ICV_DEF_PXPLPX_TAB( icvInitCvtPlaneToPixRTable, P, C )
ICV_DEF_PXPLCOI_TAB( icvInitCvtPlaneToPixRCoiTable, C1, Cn )
typedef CvStatus (CV_STDCALL *CvSplitFunc)( const void* src, int srcstep,
void** dst, int dststep, CvSize size);
typedef CvStatus (CV_STDCALL *CvExtractPlaneFunc)( const void* src, int srcstep,
void* dst, int dststep,
CvSize size, int cn, int coi );
typedef CvStatus (CV_STDCALL *CvMergeFunc)( const void** src, int srcstep,
void* dst, int dststep, CvSize size);
typedef CvStatus (CV_STDCALL *CvInsertPlaneFunc)( const void* src, int srcstep,
void* dst, int dststep,
CvSize size, int cn, int coi );
CV_IMPL void
cvSplit( const void* srcarr, void* dstarr0, void* dstarr1, void* dstarr2, void* dstarr3 )
{
static CvBigFuncTable pxpl_tab;
static CvFuncTable pxplcoi_tab;
static int inittab = 0;
CV_FUNCNAME( "cvSplit" );
__BEGIN__;
CvMat stub[5], *dst[4], *src = (CvMat*)srcarr;
CvSize size;
void* dstptr[4] = { 0, 0, 0, 0 };
int type, cn, coi = 0;
int i, nzplanes = 0, nzidx = -1;
int cont_flag;
int src_step, dst_step = 0;
if( !inittab )
{
icvInitSplitRTable( &pxpl_tab );
icvInitSplitRCoiTable( &pxplcoi_tab );
inittab = 1;
}
dst[0] = (CvMat*)dstarr0;
dst[1] = (CvMat*)dstarr1;
dst[2] = (CvMat*)dstarr2;
dst[3] = (CvMat*)dstarr3;
CV_CALL( src = cvGetMat( src, stub + 4, &coi ));
//if( coi != 0 )
// CV_ERROR( CV_BadCOI, "" );
type = CV_MAT_TYPE( src->type );
cn = CV_MAT_CN( type );
cont_flag = src->type;
if( cn == 1 )
CV_ERROR( CV_BadNumChannels, "" );
for( i = 0; i < 4; i++ )
{
if( dst[i] )
{
nzplanes++;
nzidx = i;
CV_CALL( dst[i] = cvGetMat( dst[i], stub + i ));
if( CV_MAT_CN( dst[i]->type ) != 1 )
CV_ERROR( CV_BadNumChannels, "" );
if( !CV_ARE_DEPTHS_EQ( dst[i], src ))
CV_ERROR( CV_StsUnmatchedFormats, "" );
if( !CV_ARE_SIZES_EQ( dst[i], src ))
CV_ERROR( CV_StsUnmatchedSizes, "" );
if( nzplanes > i && i > 0 && dst[i]->step != dst[i-1]->step )
CV_ERROR( CV_BadStep, "" );
dst_step = dst[i]->step;
dstptr[nzplanes-1] = dst[i]->data.ptr;
cont_flag &= dst[i]->type;
}
}
src_step = src->step;
size = cvGetMatSize( src );
if( CV_IS_MAT_CONT( cont_flag ))
{
size.width *= size.height;
src_step = dst_step = CV_STUB_STEP;
size.height = 1;
}
if( nzplanes == cn )
{
CvSplitFunc func = (CvSplitFunc)pxpl_tab.fn_2d[type];
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
IPPI_CALL( func( src->data.ptr, src_step, dstptr, dst_step, size ));
}
else if( nzplanes == 1 )
{
CvExtractPlaneFunc func = (CvExtractPlaneFunc)pxplcoi_tab.fn_2d[CV_MAT_DEPTH(type)];
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
IPPI_CALL( func( src->data.ptr, src_step,
dst[nzidx]->data.ptr, dst_step,
size, cn, nzidx + 1 ));
}
else
{
CV_ERROR( CV_StsBadArg,
"Either all output planes or only one output plane should be non zero" );
}
__END__;
}
CV_IMPL void
cvMerge( const void* srcarr0, const void* srcarr1, const void* srcarr2,
const void* srcarr3, void* dstarr )
{
static CvBigFuncTable plpx_tab;
static CvFuncTable plpxcoi_tab;
static int inittab = 0;
CV_FUNCNAME( "cvMerge" );
__BEGIN__;
int src_step = 0, dst_step;
CvMat stub[5], *src[4], *dst = (CvMat*)dstarr;
CvSize size;
const void* srcptr[4] = { 0, 0, 0, 0 };
int type, cn, coi = 0;
int i, nzplanes = 0, nzidx = -1;
int cont_flag;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -