commit a83d75aed2fae9e0ae877642fbbd8e82b6bacca6 Author: lyao2 <lyao2@LYAO2-WS01.cisco.com> Date: Fri Apr 4 15:40:54 2014 +0800 check makefile commit 097bd858ef46b6febda098253cc0d48e2eb0c95c Author: lyao2 <lyao2@LYAO2-WS01.cisco.com> Date: Fri Apr 4 09:43:24 2014 +0800 add mask flag commit 34e86276000bac158abdfb839b1a5aaebac1e235 add scroll detection files
Showing the changes to codec/processing/src/scrolldetection/ScrollDetectionFuncs.cpp (1 of 8 files). Show all
Unified · Split
| @@ -0,0 +1,202 @@ | ||
| 1 | +/*! | |
| 2 | + * \copy | |
| 3 | + * Copyright (c) 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 | +#include "ScrollDetection.h" | |
| 34 | +#include "ScrollDetectionFuncs.h" | |
| 35 | + | |
| 36 | +WELSVP_NAMESPACE_BEGIN | |
| 37 | + | |
| 38 | +int32_t CheckLine(uint8_t* pData, int32_t iWidth){ | |
| 39 | + int32_t iQualified = 0; | |
| 40 | + int32_t iColorMap[8] = {0}; | |
| 41 | + int32_t iChangedTimes = 0; | |
| 42 | + int32_t iColorCounts = 0; | |
| 43 | + | |
| 44 | + RECORD_COLOR(pData[0], iColorMap); | |
| 45 | + | |
| 46 | + for (int32_t i=1; i<iWidth; i++){ | |
| 47 | + RECORD_COLOR(pData[i], iColorMap); | |
| 48 | + iChangedTimes += (pData[i] != pData[i-1]); | |
| 49 | + } | |
| 50 | + for (int32_t i=0; i<8; i++) | |
| 51 | + for (int32_t j=0; j<32; j++) | |
| 52 | + iColorCounts += ((iColorMap[i] >> j)&1); | |
| 53 | + | |
| 54 | + switch(iColorCounts){ | |
| 55 | + case 1: | |
| 56 | + iQualified = 0; | |
| 57 | + break; | |
| 58 | + case 2: | |
| 59 | + case 3: | |
| 60 | + iQualified = (iChangedTimes > 3); | |
| 61 | + break; | |
| 62 | + default: | |
| 63 | + iQualified = 1; | |
| 64 | + break; | |
| 65 | + } | |
| 66 | + return iQualified; | |
| 67 | +} | |
| 68 | + | |
| 69 | +int32_t SelectTestLine(uint8_t* pY, int32_t iWidth, int32_t iHeight, int32_t iPicHeight, | |
| 70 | + int32_t iStride, int32_t iOffsetX, int32_t iOffsetY){ | |
| 71 | + const int32_t kiHalfHeight = iHeight >> 1; | |
| 72 | + const int32_t kiMidPos = iOffsetY + kiHalfHeight; | |
| 73 | + int32_t TestPos = kiMidPos; | |
| 74 | + int32_t iOffsetAbs; | |
| 75 | + uint8_t* pTmp; | |
| 76 | + | |
| 77 | + for (iOffsetAbs = 0; iOffsetAbs < kiHalfHeight; iOffsetAbs++){ | |
| 78 | + TestPos = kiMidPos + iOffsetAbs; | |
| 79 | + if (TestPos < iPicHeight){ | |
| 80 | + pTmp = pY + TestPos * iStride + iOffsetX; | |
| 81 | + if (CheckLine(pTmp, iWidth)) break; | |
| 82 | + } | |
| 83 | + TestPos = kiMidPos - iOffsetAbs; | |
| 84 | + if(TestPos >=0){ | |
| 85 | + pTmp = pY + TestPos * iStride + iOffsetX; | |
| 86 | + if (CheckLine(pTmp, iWidth)) break; | |
| 87 | + } | |
| 88 | + } | |
| 89 | + if (iOffsetAbs == kiHalfHeight) | |
| 90 | + TestPos = -1; | |
| 91 | + return TestPos; | |
| 92 | +} | |
| 93 | + | |
| 94 | +/* | |
| 95 | + * compare pixel line between previous and current one | |
| 96 | + * return: 0 for totally equal, otherwise 1 | |
| 97 | + */ | |
| 98 | +int32_t CompareLine(uint8_t *pYSrc, uint8_t *pYRef, const int32_t kiWidth) | |
| 99 | +{ | |
| 100 | + int32_t iCmp = 1; | |
| 101 | + | |
| 102 | + if ( *((int32_t*)pYSrc) != *((int32_t*)pYRef)) return 1; | |
| 103 | + if ( *((int32_t*)(pYSrc + 4)) != *((int32_t*)(pYRef + 4))) return 1; | |
| 104 | + if ( *((int32_t*)(pYSrc + 8)) != *((int32_t*)(pYRef + 8))) return 1; | |
| 105 | + if ( kiWidth > 12 ) | |
| 106 | + iCmp = WelsMemcmp(pYSrc+12, pYRef+12, kiWidth-12); | |
| 107 | + return iCmp; | |
| 108 | +} | |
| 109 | + | |
| 110 | +void ScrollDetectionCore(SPixMap* pSrcPixMap, SPixMap* pRefPixMap, int32_t iWidth, int32_t iHeight, | |
| 111 | + int32_t iOffsetX, int32_t iOffsetY, SScrollDetectionParam &sScrollDetectionParam){ | |
| 112 | + bool bScrollDetected = 0; | |
| 113 | + uint8_t* pYLine; | |
| 114 | + uint8_t* pYTmp; | |
| 115 | + int32_t iTestPos, iSearchPos = 0, iOffsetAbs, iMaxAbs; | |
| 116 | + int32_t iPicHeight = pRefPixMap->sRect.iRectHeight; | |
| 117 | + int32_t iMinHeight = WELS_MAX(iOffsetY,0); | |
| 118 | + int32_t iMaxHeight = WELS_MIN(iOffsetY + iHeight - 1, iPicHeight-1) ;//offset_y + height - 1;// | |
| 119 | + uint8_t* pYRef, *pYSrc; | |
| 120 | + int32_t iYStride; | |
| 121 | + | |
| 122 | + pYRef = (uint8_t*)pRefPixMap->pPixel[0]; | |
| 123 | + pYSrc = (uint8_t*)pSrcPixMap->pPixel[0]; | |
| 124 | + iYStride = pRefPixMap->iStride[0]; | |
| 125 | + | |
| 126 | + iTestPos = SelectTestLine(pYSrc, iWidth, iHeight, iPicHeight, iYStride, iOffsetX, iOffsetY); | |
| 127 | + | |
| 128 | + if (iTestPos == -1){ | |
| 129 | + sScrollDetectionParam.bScrollDetectFlag = 0; | |
| 130 | + return; | |
| 131 | + } | |
| 132 | + pYLine = pYSrc + iYStride * iTestPos + iOffsetX; | |
| 133 | + iMaxAbs = WELS_MIN(WELS_MAX(iTestPos-iMinHeight-1, iMaxHeight-iTestPos),MAX_SCROLL_MV_Y); | |
| 134 | + iSearchPos = iTestPos; | |
| 135 | + for (iOffsetAbs = 0; iOffsetAbs <= iMaxAbs; iOffsetAbs++){ | |
| 136 | + iSearchPos = iTestPos + iOffsetAbs; | |
| 137 | + if (iSearchPos <= iMaxHeight){ | |
| 138 | + pYTmp = pYRef + iSearchPos * iYStride + iOffsetX; | |
| 139 | + if (!CompareLine(pYLine, pYTmp, iWidth)){ | |
| 140 | + uint8_t *pYUpper, *pYLineUpper; | |
| 141 | + int32_t iCheckedLines; | |
| 142 | + int32_t iLowOffset = WELS_MIN(iMaxHeight - iSearchPos, CHECK_OFFSET); | |
| 143 | + int32_t i; | |
| 144 | + | |
| 145 | + iCheckedLines = WELS_MIN(iTestPos - iMinHeight + iLowOffset, 2 * CHECK_OFFSET); | |
| 146 | + pYUpper = pYTmp - (iCheckedLines - iLowOffset) * iYStride; | |
| 147 | + pYLineUpper = pYLine - (iCheckedLines - iLowOffset) * iYStride; | |
| 148 | + | |
| 149 | + for(i = 0; i < iCheckedLines; i ++){ | |
| 150 | + if (CompareLine(pYLineUpper, pYUpper, iWidth)){ | |
| 151 | + break; | |
| 152 | + } | |
| 153 | + pYUpper += iYStride; | |
| 154 | + pYLineUpper += iYStride; | |
| 155 | + } | |
| 156 | + if (i == iCheckedLines){ | |
| 157 | + bScrollDetected=1; | |
| 158 | + break; | |
| 159 | + } | |
| 160 | + } | |
| 161 | + } | |
| 162 | + | |
| 163 | + iSearchPos = iTestPos - iOffsetAbs-1; | |
| 164 | + if (iSearchPos >= iMinHeight){ | |
| 165 | + pYTmp = pYRef + iSearchPos * iYStride + iOffsetX; | |
| 166 | + if (!CompareLine(pYLine, pYTmp, iWidth)) | |
| 167 | + { | |
| 168 | + uint8_t *pYUpper, *pYLineUpper; | |
| 169 | + int32_t iCheckedLines; | |
| 170 | + int32_t iUpOffset = WELS_MIN(iSearchPos - iMinHeight, CHECK_OFFSET); | |
| 171 | + int32_t i; | |
| 172 | + | |
| 173 | + pYUpper = pYTmp - iUpOffset * iYStride; | |
| 174 | + pYLineUpper = pYLine - iUpOffset * iYStride; | |
| 175 | + iCheckedLines = WELS_MIN(iMaxHeight - iTestPos + iUpOffset, 2 * CHECK_OFFSET); | |
| 176 | + | |
| 177 | + for(i = 0; i < iCheckedLines; i ++){ | |
| 178 | + if (CompareLine(pYLineUpper,pYUpper, iWidth)){ | |
| 179 | + break; | |
| 180 | + } | |
| 181 | + pYUpper += iYStride; | |
| 182 | + pYLineUpper += iYStride; | |
| 183 | + } | |
| 184 | + if (i == iCheckedLines){ | |
| 185 | + bScrollDetected=1; | |
| 186 | + break; | |
| 187 | + } | |
| 188 | + } | |
| 189 | + } | |
| 190 | + } | |
| 191 | + | |
| 192 | + if (!bScrollDetected){ | |
| 193 | + sScrollDetectionParam.bScrollDetectFlag = 0; | |
| 194 | + } | |
| 195 | + else{ | |
| 196 | + sScrollDetectionParam.bScrollDetectFlag = 1; | |
| 197 | + sScrollDetectionParam.iScrollMvY = iSearchPos - iTestPos; // pre_pos - cur_pos, change to mv | |
| 198 | + sScrollDetectionParam.iScrollMvX = 0; | |
| 199 | + } | |
| 200 | +} | |
| 201 | + | |
| 202 | +WELSVP_NAMESPACE_END | |