cvconvert.cpp.svn-base

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

SVN-BASE
1,330
字号
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                        Intel License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of Intel Corporation may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#include "_cv.h"

/****************************************************************************************\
*                             Conversion pixel -> plane                                  *
\****************************************************************************************/


#define  ICV_DEF_PX2PL_C2( arrtype, len )           \
{                                                   \
    int j;                                          \
                                                    \
    for( j = 0; j < (len); j++, (src) += 2 )        \
    {                                               \
        arrtype t0 = (src)[0];                      \
        arrtype t1 = (src)[1];                      \
                                                    \
        plane[0][j] = t0;                           \
        plane[1][j] = t1;                           \
    }                                               \
}


#define  ICV_DEF_PX2PL_C3( arrtype, len )           \
{                                                   \
    int j;                                          \
                                                    \
    for( j = 0; j < (len); j++, (src) += 3 )        \
    {                                               \
        arrtype t0 = (src)[0];                      \
        arrtype t1 = (src)[1];                      \
        arrtype t2 = (src)[2];                      \
                                                    \
        plane[0][j] = t0;                           \
        plane[1][j] = t1;                           \
        plane[2][j] = t2;                           \
    }                                               \
}


#define  ICV_DEF_PX2PL_C4( arrtype, len )           \
{                                                   \
    int j;                                          \
                                                    \
    for( j = 0; j < (len); j++, (src) += 4 )        \
    {                                               \
        arrtype t0 = (src)[0];                      \
        arrtype t1 = (src)[1];                      \
                                                    \
        plane[0][j] = t0;                           \
        plane[1][j] = t1;                           \
                                                    \
        t0 = (src)[2];                              \
        t1 = (src)[3];                              \
                                                    \
        plane[2][j] = t0;                           \
        plane[3][j] = t1;                           \
    }                                               \
}


#define  ICV_DEF_PX2PL_COI( arrtype, len, cn )          \
{                                                       \
    int j;                                              \
                                                        \
    for( j = 0; j <= (len) - 4; j += 4, (src) += 4*(cn))\
    {                                                   \
        arrtype t0 = (src)[0];                          \
        arrtype t1 = (src)[(cn)];                       \
                                                        \
        (dst)[j] = t0;                                  \
        (dst)[j+1] = t1;                                \
                                                        \
        t0 = (src)[(cn)*2];                             \
        t1 = (src)[(cn)*3];                             \
                                                        \
        (dst)[j+2] = t0;                                \
        (dst)[j+3] = t1;                                \
    }                                                   \
                                                        \
    for( ; j < (len); j++, (src) += (cn))               \
    {                                                   \
        (dst)[j] = (src)[0];                            \
    }                                                   \
}


#define  ICV_DEF_COPY_PX2PL_FUNC_2D( arrtype, flavor, cn )              \
IPCVAPI_IMPL( CvStatus, icvCopy_##flavor##_C##cn##P##cn##R,             \
( const arrtype* src, int srcstep,                                      \
  arrtype** dst, int dststep, CvSize size ))                            \
{                                                                       \
    arrtype* plane[] = { 0, 0, 0, 0 };                                  \
    int i;                                                              \
                                                                        \
    for( i = 0; i < cn; i++ )                                           \
    {                                                                   \
        plane[i] = dst[i];                                              \
    }                                                                   \
                                                                        \
    for( ; size.height--; (char*&)src += srcstep,                       \
                          (char*&)(plane[0]) += dststep,                \
                          (char*&)(plane[1]) += dststep,                \
                          (char*&)(plane[2]) += dststep,                \
                          (char*&)(plane[3]) += dststep )               \
    {                                                                   \
        ICV_DEF_PX2PL_C##cn( arrtype, size.width );                     \
        src -= size.width*(cn);                                         \
    }                                                                   \
                                                                        \
    return CV_OK;                                                       \
}


#define  ICV_DEF_COPY_PX2PL_FUNC_2D_COI( arrtype, flavor )              \
IPCVAPI_IMPL( CvStatus, icvCopy_##flavor##_CnC1CR,                      \
( const arrtype* src, int srcstep, arrtype* dst, int dststep,           \
  CvSize size, int cn, int coi ))                                       \
{                                                                       \
    src += coi - 1;                                                     \
    for( ; size.height--; (char*&)src += srcstep,                       \
                          (char*&)dst += dststep )                      \
    {                                                                   \
        ICV_DEF_PX2PL_COI( arrtype, size.width, cn );                   \
        src -= size.width*(cn);                                         \
    }                                                                   \
                                                                        \
    return CV_OK;                                                       \
}


ICV_DEF_COPY_PX2PL_FUNC_2D( uchar, 8u, 2 )
ICV_DEF_COPY_PX2PL_FUNC_2D( uchar, 8u, 3 )
ICV_DEF_COPY_PX2PL_FUNC_2D( uchar, 8u, 4 )
ICV_DEF_COPY_PX2PL_FUNC_2D( ushort, 16u, 2 )
ICV_DEF_COPY_PX2PL_FUNC_2D( ushort, 16u, 3 )
ICV_DEF_COPY_PX2PL_FUNC_2D( ushort, 16u, 4 )
ICV_DEF_COPY_PX2PL_FUNC_2D( int, 32s, 2 )
ICV_DEF_COPY_PX2PL_FUNC_2D( int, 32s, 3 )
ICV_DEF_COPY_PX2PL_FUNC_2D( int, 32s, 4 )
ICV_DEF_COPY_PX2PL_FUNC_2D( int64, 64f, 2 )
ICV_DEF_COPY_PX2PL_FUNC_2D( int64, 64f, 3 )
ICV_DEF_COPY_PX2PL_FUNC_2D( int64, 64f, 4 )


ICV_DEF_COPY_PX2PL_FUNC_2D_COI( uchar, 8u )
ICV_DEF_COPY_PX2PL_FUNC_2D_COI( ushort, 16u )
ICV_DEF_COPY_PX2PL_FUNC_2D_COI( int, 32s )
ICV_DEF_COPY_PX2PL_FUNC_2D_COI( int64, 64f )


/****************************************************************************************\
*                             Conversion plane -> pixel                                  *
\****************************************************************************************/


#define  ICV_DEF_PL2PX_C2( arrtype, len )           \
{                                                   \
    int j;                                          \
                                                    \
    for( j = 0; j < (len); j++, (dst) += 2 )        \
    {                                               \
        arrtype t0 = plane[0][j];                   \
        arrtype t1 = plane[1][j];                   \
                                                    \
        dst[0] = t0;                                \
        dst[1] = t1;                                \
    }                                               \
}


#define  ICV_DEF_PL2PX_C3( arrtype, len )           \
{                                                   \
    int j;                                          \
                                                    \
    for( j = 0; j < (len); j++, (dst) += 3 )        \
    {                                               \
        arrtype t0 = plane[0][j];                   \
        arrtype t1 = plane[1][j];                   \
        arrtype t2 = plane[2][j];                   \
                                                    \
        dst[0] = t0;                                \
        dst[1] = t1;                                \
        dst[2] = t2;                                \
    }                                               \
}


#define  ICV_DEF_PL2PX_C4( arrtype, len )           \
{                                                   \
    int j;                                          \
                                                    \
    for( j = 0; j < (len); j++, (dst) += 4 )        \
    {                                               \
        arrtype t0 = plane[0][j];                   \
        arrtype t1 = plane[1][j];                   \
                                                    \
        dst[0] = t0;                                \
        dst[1] = t1;                                \
                                                    \
        t0 = plane[2][j];                           \
        t1 = plane[3][j];                           \
                                                    \
        dst[2] = t0;                                \
        dst[3] = t1;                                \
    }                                               \
}


#define  ICV_DEF_PL2PX_COI( arrtype, len, cn )          \
{                                                       \
    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;                             \

⌨️ 快捷键说明

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