⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvaccum.cpp

📁 将OpenCV移植到DSP上
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*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"

#define  ICV_DEF_ACC_FUNC( name, srctype, dsttype, cvtmacro )           \
IPCVAPI_IMPL( CvStatus,                                                 \
name,( const srctype *src, int srcstep, dsttype *dst,                   \
       int dststep, CvSize size ), (src, srcstep, dst, dststep, size )) \
                                                                        \
{                                                                       \
    srcstep /= sizeof(src[0]);                                          \
    dststep /= sizeof(dst[0]);                                          \
                                                                        \
    for( ; size.height--; src += srcstep, dst += dststep )              \
    {                                                                   \
        int x;                                                          \
        for( x = 0; x <= size.width - 4; x += 4 )                       \
        {                                                               \
            dsttype t0 = dst[x] + cvtmacro(src[x]);                     \
            dsttype t1 = dst[x + 1] + cvtmacro(src[x + 1]);             \
            dst[x] = t0;  dst[x + 1] = t1;                              \
                                                                        \
            t0 = dst[x + 2] + cvtmacro(src[x + 2]);                     \
            t1 = dst[x + 3] + cvtmacro(src[x + 3]);                     \
            dst[x + 2] = t0;  dst[x + 3] = t1;                          \
        }                                                               \
                                                                        \
        for( ; x < size.width; x++ )                                    \
            dst[x] += cvtmacro(src[x]);                                 \
    }                                                                   \
                                                                        \
    return CV_OK;                                                       \
}


ICV_DEF_ACC_FUNC( icvAdd_8u32f_C1IR, uchar, float, CV_8TO32F )
ICV_DEF_ACC_FUNC( icvAdd_32f_C1IR, float, float, CV_NOP )
ICV_DEF_ACC_FUNC( icvAddSquare_8u32f_C1IR, uchar, float, CV_8TO32F_SQR )
ICV_DEF_ACC_FUNC( icvAddSquare_32f_C1IR, float, float, CV_SQR )


#define  ICV_DEF_ACCPROD_FUNC( flavor, srctype, dsttype, cvtmacro )         \
IPCVAPI_IMPL( CvStatus, icvAddProduct_##flavor##_C1IR,                      \
( const srctype *src1, int step1, const srctype *src2, int step2,           \
  dsttype *dst, int dststep, CvSize size ),                                 \
 (src1, step1, src2, step2, dst, dststep, size) )                           \
{                                                                           \
    step1 /= sizeof(src1[0]);                                               \
    step2 /= sizeof(src2[0]);                                               \
    dststep /= sizeof(dst[0]);                                              \
                                                                            \
    for( ; size.height--; src1 += step1, src2 += step2, dst += dststep )    \
    {                                                                       \
        int x;                                                              \
        for( x = 0; x <= size.width - 4; x += 4 )                           \
        {                                                                   \
            dsttype t0 = dst[x] + cvtmacro(src1[x])*cvtmacro(src2[x]);      \
            dsttype t1 = dst[x+1] + cvtmacro(src1[x+1])*cvtmacro(src2[x+1]);\
            dst[x] = t0;  dst[x + 1] = t1;                                  \
                                                                            \
            t0 = dst[x + 2] + cvtmacro(src1[x + 2])*cvtmacro(src2[x + 2]);  \
            t1 = dst[x + 3] + cvtmacro(src1[x + 3])*cvtmacro(src2[x + 3]);  \
            dst[x + 2] = t0;  dst[x + 3] = t1;                              \
        }                                                                   \
                                                                            \
        for( ; x < size.width; x++ )                                        \
            dst[x] += cvtmacro(src1[x])*cvtmacro(src2[x]);                  \
    }                                                                       \
                                                                            \
    return CV_OK;                                                           \
}


ICV_DEF_ACCPROD_FUNC( 8u32f, uchar, float, CV_8TO32F )
ICV_DEF_ACCPROD_FUNC( 32f, float, float, CV_NOP )


#define  ICV_DEF_ACCWEIGHT_FUNC( flavor, srctype, dsttype, cvtmacro )   \
IPCVAPI_IMPL( CvStatus, icvAddWeighted_##flavor##_C1IR,                 \
( const srctype *src, int srcstep, dsttype *dst, int dststep,           \
  CvSize size, dsttype alpha ), (src, srcstep, dst, dststep, size, alpha) )\
{                                                                       \
    dsttype beta = (dsttype)(1 - alpha);                                \
    srcstep /= sizeof(src[0]);                                          \
    dststep /= sizeof(dst[0]);                                          \
                                                                        \
    for( ; size.height--; src += srcstep, dst += dststep )              \
    {                                                                   \
        int x;                                                          \
        for( x = 0; x <= size.width - 4; x += 4 )                       \
        {                                                               \
            dsttype t0 = dst[x]*beta + cvtmacro(src[x])*alpha;          \
            dsttype t1 = dst[x+1]*beta + cvtmacro(src[x+1])*alpha;      \
            dst[x] = t0; dst[x + 1] = t1;                               \
                                                                        \
            t0 = dst[x + 2]*beta + cvtmacro(src[x + 2])*alpha;          \
            t1 = dst[x + 3]*beta + cvtmacro(src[x + 3])*alpha;          \
            dst[x + 2] = t0; dst[x + 3] = t1;                           \
        }                                                               \
                                                                        \
        for( ; x < size.width; x++ )                                    \
            dst[x] = dst[x]*beta + cvtmacro(src[x])*alpha;              \
    }                                                                   \
                                                                        \
    return CV_OK;                                                       \
}


ICV_DEF_ACCWEIGHT_FUNC( 8u32f, uchar, float, CV_8TO32F )
ICV_DEF_ACCWEIGHT_FUNC( 32f, float, float, CV_NOP )


#define  ICV_DEF_ACCMASK_FUNC_C1( name, srctype, dsttype, cvtmacro )    \
IPCVAPI_IMPL( CvStatus,                                                 \
name,( const srctype *src, int srcstep, const uchar* mask, int maskstep,\
       dsttype *dst, int dststep, CvSize size ),                        \
       (src, srcstep, mask, maskstep, dst, dststep, size ))             \
{                                                                       \
    srcstep /= sizeof(src[0]);                                          \
    dststep /= sizeof(dst[0]);                                          \
                                                                        \
    for( ; size.height--; src += srcstep,                               \
                          dst += dststep, mask += maskstep )            \
    {                                                                   \
        int x;                                                          \
        for( x = 0; x <= size.width - 2; x += 2 )                       \
        {                                                               \
            if( mask[x] )                                               \
                dst[x] += cvtmacro(src[x]);                             \
            if( mask[x+1] )                                             \
                dst[x+1] += cvtmacro(src[x+1]);                         \
        }                                                               \
                                                                        \
        for( ; x < size.width; x++ )                                    \
            if( mask[x] )                                               \
                dst[x] += cvtmacro(src[x]);                             \
    }                                                                   \
                                                                        \
    return CV_OK;                                                       \
}


ICV_DEF_ACCMASK_FUNC_C1( icvAdd_8u32f_C1IMR, uchar, float, CV_8TO32F )
ICV_DEF_ACCMASK_FUNC_C1( icvAdd_32f_C1IMR, float, float, CV_NOP )
ICV_DEF_ACCMASK_FUNC_C1( icvAddSquare_8u32f_C1IMR, uchar, float, CV_8TO32F_SQR )
ICV_DEF_ACCMASK_FUNC_C1( icvAddSquare_32f_C1IMR, float, float, CV_SQR )


#define  ICV_DEF_ACCPRODUCTMASK_FUNC_C1( flavor, srctype, dsttype, cvtmacro )  \
IPCVAPI_IMPL( CvStatus, icvAddProduct_##flavor##_C1IMR,                 \
( const srctype *src1, int step1, const srctype* src2, int step2,       \
  const uchar* mask, int maskstep, dsttype *dst, int dststep, CvSize size ),\
  (src1, step1, src2, step2, mask, maskstep, dst, dststep, size ))      \
{                                                                       \
    step1 /= sizeof(src1[0]);                                           \
    step2 /= sizeof(src2[0]);                                           \
    dststep /= sizeof(dst[0]);                                          \
                                                                        \
    for( ; size.height--; src1 += step1, src2 += step2,                 \
                          dst += dststep, mask += maskstep )            \
    {                                                                   \
        int x;                                                          \
        for( x = 0; x <= size.width - 2; x += 2 )                       \
        {                                                               \
            if( mask[x] )                                               \
                dst[x] += cvtmacro(src1[x])*cvtmacro(src2[x]);          \
            if( mask[x+1] )                                             \
                dst[x+1] += cvtmacro(src1[x+1])*cvtmacro(src2[x+1]);    \
        }                                                               \
                                                                        \
        for( ; x < size.width; x++ )                                    \
            if( mask[x] )                                               \
                dst[x] += cvtmacro(src1[x])*cvtmacro(src2[x]);          \
    }                                                                   \
                                                                        \
    return CV_OK;                                                       \
}


ICV_DEF_ACCPRODUCTMASK_FUNC_C1( 8u32f, uchar, float, CV_8TO32F )
ICV_DEF_ACCPRODUCTMASK_FUNC_C1( 32f, float, float, CV_NOP )

#define  ICV_DEF_ACCWEIGHTMASK_FUNC_C1( flavor, srctype, dsttype, cvtmacro ) \
IPCVAPI_IMPL( CvStatus, icvAddWeighted_##flavor##_C1IMR,                \
( const srctype *src, int srcstep, const uchar* mask, int maskstep,     \
  dsttype *dst, int dststep, CvSize size, dsttype alpha ),              \
  (src, srcstep, mask, maskstep, dst, dststep, size, alpha ))           \
{                                                                       \
    dsttype beta = (dsttype)(1 - alpha);                                \
    srcstep /= sizeof(src[0]);                                          \
    dststep /= sizeof(dst[0]);                                          \
                                                                        \
    for( ; size.height--; src += srcstep,                               \
                          dst += dststep, mask += maskstep )            \
    {                                                                   \
        int x;                                                          \
        for( x = 0; x <= size.width - 2; x += 2 )                       \
        {                                                               \
            if( mask[x] )                                               \
                dst[x] = dst[x]*beta + cvtmacro(src[x])*alpha;          \
            if( mask[x+1] )                                             \
                dst[x+1] = dst[x+1]*beta + cvtmacro(src[x+1])*alpha;    \
        }                                                               \
                                                                        \
        for( ; x < size.width; x++ )                                    \
            if( mask[x] )                                               \
                dst[x] = dst[x]*beta + cvtmacro(src[x])*alpha;          \
    }                                                                   \
                                                                        \
    return CV_OK;                                                       \
}

ICV_DEF_ACCWEIGHTMASK_FUNC_C1( 8u32f, uchar, float, CV_8TO32F )
ICV_DEF_ACCWEIGHTMASK_FUNC_C1( 32f, float, float, CV_NOP )


#define  ICV_DEF_ACCMASK_FUNC_C3( name, srctype, dsttype, cvtmacro )    \
IPCVAPI_IMPL( CvStatus,                                                 \
name,( const srctype *src, int srcstep, const uchar* mask, int maskstep,\
       dsttype *dst, int dststep, CvSize size ),                        \
       (src, srcstep, mask, maskstep, dst, dststep, size ))             \
{                                                                       \
    srcstep /= sizeof(src[0]);                                          \
    dststep /= sizeof(dst[0]);                                          \

⌨️ 快捷键说明

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