• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2011-2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  * \file        :  BackgroundDetection.h
32  *
33  * \brief       :  background detection class of wels video processor class
34  *
35  * \date        :  2011/03/17
36  *
37  * \description :  1. rewrite the package code of background detection class
38  *
39  */
40 
41 #ifndef WELSVP_BACKGROUNDDETECTION_H
42 #define WELSVP_BACKGROUNDDETECTION_H
43 
44 #include "util.h"
45 #include "memory.h"
46 #include "WelsFrameWork.h"
47 #include "IWelsVP.h"
48 
49 WELSVP_NAMESPACE_BEGIN
50 
51 typedef struct {
52   int32_t       iBackgroundFlag;
53   int32_t       iSAD;
54   int32_t       iSD;
55   int32_t       iMAD;
56   int32_t       iMinSubMad;
57   int32_t       iMaxDiffSubSd;
58 } SBackgroundOU;
59 
60 class CBackgroundDetection : public IStrategy {
61  public:
62   CBackgroundDetection (int32_t iCpuFlag);
63   ~CBackgroundDetection();
64 
65   EResult Process (int32_t iType, SPixMap* pSrc, SPixMap* pRef);
66   EResult Set (int32_t iType, void* pParam);
67 
68  private:
69   struct vBGDParam {
70     uint8_t*   pCur[3];
71     uint8_t*   pRef[3];
72     int32_t    iBgdWidth;
73     int32_t    iBgdHeight;
74     int32_t    iStride[3];
75     SBackgroundOU*   pOU_array;
76     int8_t*    pBackgroundMbFlag;
77     SVAACalcResult*  pCalcRes;
78   } m_BgdParam;
79 
80   int32_t     m_iLargestFrameSize;
81 
82  private:
83   inline SBackgroundOU* AllocateOUArrayMemory (int32_t iWidth, int32_t iHeight);
84   inline int32_t  CalculateAsdChromaEdge (uint8_t* pOriRef, uint8_t* pOriCur, int32_t iStride);
85   inline bool   ForegroundDilation23Luma (SBackgroundOU* pBackgroundOU,
86                                           SBackgroundOU* pOUNeighbours[]); //Foreground_Dilation_2_3_Luma
87   inline bool   ForegroundDilation23Chroma (int8_t iNeighbourForegroundFlags, int32_t iStartSamplePos,
88       int32_t iPicStrideUV, vBGDParam* pBgdParam);//Foreground_Dilation_2_3_Chroma
89   inline void     ForegroundDilation (SBackgroundOU* pBackgroundOU, SBackgroundOU* pOUNeighbours[], vBGDParam* pBgdParam,
90                                       int32_t iChromaSampleStartPos);
91   inline void     BackgroundErosion (SBackgroundOU* pBackgroundOU, SBackgroundOU* pOUNeighbours[]);
92   inline void     SetBackgroundMbFlag (int8_t* pBackgroundMbFlag, int32_t iPicWidthInMb, int32_t iBackgroundMbFlag);
93   inline void     UpperOUForegroundCheck (SBackgroundOU* pCurOU, int8_t* pBackgroundMbFlag, int32_t iPicWidthInOU,
94                                           int32_t iPicWidthInMb);
95 
96   void    GetOUParameters (SVAACalcResult* sVaaCalcInfo, int32_t iMbIndex, int32_t iMbWidth,
97                            SBackgroundOU* pBackgroundOU);
98   void    ForegroundBackgroundDivision (vBGDParam* pBgdParam);
99   void    ForegroundDilationAndBackgroundErosion (vBGDParam* pBgdParam);
100   void    BackgroundDetection (vBGDParam* pBgdParam);
101 };
102 
103 WELSVP_NAMESPACE_END
104 
105 #endif
106