• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2009-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  */
32 
33 
34 #include "ScrollDetection.h"
35 #include "ScrollDetectionFuncs.h"
36 #include "cpu.h"
37 
38 WELSVP_NAMESPACE_BEGIN
39 
Process(int32_t iType,SPixMap * pSrcPixMap,SPixMap * pRefPixMap)40 EResult CScrollDetection::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
41   if (pRefPixMap->pPixel[0] == NULL || pSrcPixMap->pPixel[0] == NULL ||
42       pRefPixMap->sRect.iRectWidth != pSrcPixMap->sRect.iRectWidth
43       || pRefPixMap->sRect.iRectHeight != pSrcPixMap->sRect.iRectHeight) {
44     return RET_INVALIDPARAM;
45   }
46 
47   if (!m_sScrollDetectionParam.bMaskInfoAvailable)
48     ScrollDetectionWithoutMask (pSrcPixMap, pRefPixMap);
49   else
50     ScrollDetectionWithMask (pSrcPixMap, pRefPixMap);
51 
52   return RET_SUCCESS;
53 }
54 
Set(int32_t iType,void * pParam)55 EResult CScrollDetection::Set (int32_t iType, void* pParam) {
56   if (pParam == NULL) {
57     return RET_INVALIDPARAM;
58   }
59   m_sScrollDetectionParam = * ((SScrollDetectionParam*)pParam);
60   return RET_SUCCESS;
61 }
62 
Get(int32_t iType,void * pParam)63 EResult CScrollDetection::Get (int32_t iType, void* pParam) {
64   if (pParam == NULL) {
65     return RET_INVALIDPARAM;
66   }
67   * ((SScrollDetectionParam*)pParam) = m_sScrollDetectionParam;
68   return RET_SUCCESS;
69 }
70 
ScrollDetectionWithMask(SPixMap * pSrcPixMap,SPixMap * pRefPixMap)71 void CScrollDetection::ScrollDetectionWithMask (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
72   int32_t iStartX, iStartY, iWidth, iHeight;
73 
74   iStartX = m_sScrollDetectionParam.sMaskRect.iRectLeft;
75   iStartY = m_sScrollDetectionParam.sMaskRect.iRectTop;
76   iWidth = m_sScrollDetectionParam.sMaskRect.iRectWidth;
77   iHeight = m_sScrollDetectionParam.sMaskRect.iRectHeight;
78 
79   iWidth /= 2;
80   iStartX += iWidth / 2;
81 
82   m_sScrollDetectionParam.iScrollMvX = 0;
83   m_sScrollDetectionParam.iScrollMvY = 0;
84   m_sScrollDetectionParam.bScrollDetectFlag = false;
85 
86   if (iStartX >= 0 && iWidth > MINIMUM_DETECT_WIDTH && iHeight > 2 * CHECK_OFFSET) {
87     ScrollDetectionCore (pSrcPixMap, pRefPixMap, iWidth, iHeight, iStartX, iStartY, m_sScrollDetectionParam);
88   }
89 }
90 
ScrollDetectionWithoutMask(SPixMap * pSrcPixMap,SPixMap * pRefPixMap)91 void CScrollDetection::ScrollDetectionWithoutMask (SPixMap* pSrcPixMap, SPixMap* pRefPixMap) {
92   int32_t iStartX, iStartY, iWidth, iHeight;
93 
94   const int32_t kiPicBorderWidth = pSrcPixMap->sRect.iRectHeight >> 4;
95   const int32_t kiRegionWidth = (int) (pSrcPixMap->sRect.iRectWidth - (kiPicBorderWidth << 1)) / 3;
96   const int32_t kiRegionHeight = (pSrcPixMap->sRect.iRectHeight * 7) >> 3;
97   const int32_t kiHieghtStride = (int) pSrcPixMap->sRect.iRectHeight * 5 / 24;
98 
99   for (int32_t i = 0; i < REGION_NUMBER; i++) {
100     iStartX = kiPicBorderWidth + (i % 3) * kiRegionWidth;
101     iStartY = -pSrcPixMap->sRect.iRectHeight * 7 / 48 + (int) (i / 3) * (kiHieghtStride);
102     iWidth = kiRegionWidth;
103     iHeight = kiRegionHeight;
104 
105     iWidth /= 2;
106     iStartX += iWidth / 2;
107 
108     ScrollDetectionCore (pSrcPixMap, pRefPixMap, iWidth, iHeight, iStartX, iStartY, m_sScrollDetectionParam);
109 
110     if (m_sScrollDetectionParam.bScrollDetectFlag && m_sScrollDetectionParam.iScrollMvY)
111       break;
112   }
113 }
114 
115 WELSVP_NAMESPACE_END
116