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