cvconvert.cpp.svn-base

来自「非结构化路识别」· SVN-BASE 代码 · 共 1,330 行 · 第 1/5 页

SVN-BASE
1,330
字号
    }                                                   \
                                                        \
    for( ; j < (len); j++, (dst) += (cn))               \
    {                                                   \
        (dst)[0] = (src)[j];                            \
    }                                                   \
}


#define  ICV_DEF_COPY_PL2PX_FUNC_2D( arrtype, flavor, cn )                      \
IPCVAPI_IMPL( CvStatus,                                                         \
icvCopy_##flavor##_P##cn##C##cn##R,( const arrtype** src, int srcstep,          \
                                    arrtype* dst, int dststep, CvSize size ))   \
{                                                                               \
    const arrtype* plane[] = { 0, 0, 0, 0 };                                    \
    int i;                                                                      \
                                                                                \
    for( i = 0; i < cn; i++ )                                                   \
    {                                                                           \
        plane[i] = src[i];                                                      \
    }                                                                           \
                                                                                \
    for( ; size.height--; (char*&)dst += dststep,                               \
                          (char*&)(plane[0]) += srcstep,                        \
                          (char*&)(plane[1]) += srcstep,                        \
                          (char*&)(plane[2]) += srcstep,                        \
                          (char*&)(plane[3]) += srcstep )                       \
    {                                                                           \
        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 ))                                       \
{                                                                       \
    dst += coi - 1;                                                     \
    for( ; size.height--; (char*&)src += srcstep,                       \
                          (char*&)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_COPY_PL2PX_FUNC_2D( uchar, 8u, 3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( uchar, 8u, 4 )
ICV_DEF_COPY_PL2PX_FUNC_2D( ushort, 16u, 2 )
ICV_DEF_COPY_PL2PX_FUNC_2D( ushort, 16u, 3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( ushort, 16u, 4 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int, 32s, 2 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int, 32s, 3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int, 32s, 4 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int64, 64f, 2 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int64, 64f, 3 )
ICV_DEF_COPY_PL2PX_FUNC_2D( int64, 64f, 4 )

ICV_DEF_COPY_PL2PX_FUNC_2D_COI( uchar, 8u )
ICV_DEF_COPY_PL2PX_FUNC_2D_COI( ushort, 16u )
ICV_DEF_COPY_PL2PX_FUNC_2D_COI( int, 32s )
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_16SC2] = (void*)icvCopy##_16u_##FROM##2##TO##2R;      \
    tab->fn_2d[CV_16SC3] = (void*)icvCopy##_16u_##FROM##3##TO##3R;      \
    tab->fn_2d[CV_16SC4] = (void*)icvCopy##_16u_##FROM##4##TO##4R;      \
                                                                        \
    tab->fn_2d[CV_32SC2] = (void*)icvCopy##_32s_##FROM##2##TO##2R;      \
    tab->fn_2d[CV_32SC3] = (void*)icvCopy##_32s_##FROM##3##TO##3R;      \
    tab->fn_2d[CV_32SC4] = (void*)icvCopy##_32s_##FROM##4##TO##4R;      \
                                                                        \
    tab->fn_2d[CV_32FC2] = (void*)icvCopy##_32s_##FROM##2##TO##2R;      \
    tab->fn_2d[CV_32FC3] = (void*)icvCopy##_32s_##FROM##3##TO##3R;      \
    tab->fn_2d[CV_32FC4] = (void*)icvCopy##_32s_##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_16S] = (void*)icvCopy##_16u_##FROM##TO##CR;           \
    tab->fn_2d[CV_32S] = (void*)icvCopy##_32s_##FROM##TO##CR;           \
    tab->fn_2d[CV_32F] = (void*)icvCopy##_32s_##FROM##TO##CR;           \
    tab->fn_2d[CV_64F] = (void*)icvCopy##_64f_##FROM##TO##CR;           \
}


ICV_DEF_PXPLPX_TAB( icvInitCvtPixToPlaneRTable, C, P )
ICV_DEF_PXPLCOI_TAB( icvInitCvtPixToPlaneRCoiTable, Cn, C1 )
ICV_DEF_PXPLPX_TAB( icvInitCvtPlaneToPixRTable, P, C )
ICV_DEF_PXPLCOI_TAB( icvInitCvtPlaneToPixRCoiTable, C1, Cn )

typedef CvStatus (CV_STDCALL *CvCvtPixToPlaneFunc)( const void* src, int srcstep,
                                                    void** dst, int dststep, CvSize size);

typedef CvStatus (CV_STDCALL *CvCvtPixToPlaneCoiFunc)( const void* src, int srcstep,
                                                       void* dst, int dststep,
                                                       CvSize size, int cn, int coi );

typedef CvStatus (CV_STDCALL *CvCvtPlaneToPixFunc)( const void** src, int srcstep,
                                                    void* dst, int dststep, CvSize size);

typedef CvStatus (CV_STDCALL *CvCvtPlaneToPixCoiFunc)( const void* src, int srcstep,
                                                       void* dst, int dststep,
                                                       CvSize size, int cn, int coi );

CV_IMPL void
cvCvtPixToPlane( 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( "cvCvtPixToPlane" );

    __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 = 0, dst_step = 0;

    if( !inittab )
    {
        icvInitCvtPixToPlaneRTable( &pxpl_tab );
        icvInitCvtPixToPlaneRCoiTable( &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 = icvGetMatSize( 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 )
    {
        CvCvtPixToPlaneFunc func = (CvCvtPixToPlaneFunc)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 )
    {
        CvCvtPixToPlaneCoiFunc func = (CvCvtPixToPlaneCoiFunc)
                                      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
cvCvtPlaneToPix( 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( "cvCvtPlaneToPix" );

    __BEGIN__;

    int src_step = 0, dst_step = 0;
    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;

    if( !inittab )

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?