Showing the changes to codec/processing/src/backgrounddetection/BackgroundDetection.cpp (1 of 64 files). Show all
Unified · Split
| @@ -107,16 +107,16 @@ EResult CBackgroundDetection::Set (int32_t iType, void* pParam) { · 106 unmodified lines | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | inline SBackgroundOU* CBackgroundDetection::AllocateOUArrayMemory (int32_t iWidth, int32_t iHeight) { | 109 | inline SBackgroundOU* CBackgroundDetection::AllocateOUArrayMemory (int32_t iWidth, int32_t iHeight) { |
| 110 | int32_t iMaxOUWidth = (BGD_OU_SIZE - 1 + iWidth) >> LOG2_BGD_OU_SIZE; | 110 | int32_t iMaxOUWidth = (BGD_OU_SIZE - 1 + iWidth) >> LOG2_BGD_OU_SIZE; |
| 111 | int32_t iMaxOUHeight = (BGD_OU_SIZE - 1 + iHeight) >> LOG2_BGD_OU_SIZE; | 111 | int32_t iMaxOUHeight = (BGD_OU_SIZE - 1 + iHeight) >> LOG2_BGD_OU_SIZE; |
| 112 | return (SBackgroundOU*)WelsMalloc (iMaxOUWidth * iMaxOUHeight * sizeof (SBackgroundOU)); | 112 | return (SBackgroundOU*)WelsMalloc (iMaxOUWidth * iMaxOUHeight * sizeof (SBackgroundOU)); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | void CBackgroundDetection::GetOUParameters (SVAACalcResult* sVaaCalcInfo, int32_t iMbIndex, int32_t iMbWidth, | 115 | void CBackgroundDetection::GetOUParameters (SVAACalcResult* sVaaCalcInfo, int32_t iMbIndex, int32_t iMbWidth, |
| 116 | SBackgroundOU* pBgdOU) { | 116 | SBackgroundOU* pBgdOU) { |
| 117 | int32_t iSubSD[4]; | 117 | int32_t iSubSD[4]; |
| 118 | uint8_t iSubMAD[4]; | 118 | uint8_t iSubMAD[4]; |
| 119 | int32_t iSubSAD[4]; | 119 | int32_t iSubSAD[4]; |
| 120 | 120 | ||
| 121 | uint8_t (*pMad8x8)[4]; | 121 | uint8_t (*pMad8x8)[4]; |
| 122 | int32_t (*pSad8x8)[4]; | 122 | int32_t (*pSad8x8)[4]; |
| @@ -141,9 +141,9 @@ void CBackgroundDetection::GetOUParameters (SVAACalcResult* sVaaCalcInfo, int32_ · 18 unmodified lines | |||
| 141 | iSubMAD[2] = pMad8x8[iMbIndex][2]; | 141 | iSubMAD[2] = pMad8x8[iMbIndex][2]; |
| 142 | iSubMAD[3] = pMad8x8[iMbIndex][3]; | 142 | iSubMAD[3] = pMad8x8[iMbIndex][3]; |
| 143 | 143 | ||
| 144 | pBgdOU->iSD = iSubSD[0] + iSubSD[1] + iSubSD[2] + iSubSD[3]; | 144 | pBgdOU->iSD = iSubSD[0] + iSubSD[1] + iSubSD[2] + iSubSD[3]; |
| 145 | pBgdOU->iSAD = iSubSAD[0] + iSubSAD[1] + iSubSAD[2] + iSubSAD[3]; | 145 | pBgdOU->iSAD = iSubSAD[0] + iSubSAD[1] + iSubSAD[2] + iSubSAD[3]; |
| 146 | pBgdOU->iSD = WELS_ABS (pBgdOU->iSD); | 146 | pBgdOU->iSD = WELS_ABS (pBgdOU->iSD); |
| 147 | 147 | ||
| 148 | // get the max absolute difference (MAD) of OU and min value of the MAD of sub-blocks of OU | 148 | // get the max absolute difference (MAD) of OU and min value of the MAD of sub-blocks of OU |
| 149 | pBgdOU->iMAD = WELS_MAX (WELS_MAX (iSubMAD[0], iSubMAD[1]), WELS_MAX (iSubMAD[2], iSubMAD[3])); | 149 | pBgdOU->iMAD = WELS_MAX (WELS_MAX (iSubMAD[0], iSubMAD[1]), WELS_MAX (iSubMAD[2], iSubMAD[3])); |
| @@ -155,9 +155,9 @@ void CBackgroundDetection::GetOUParameters (SVAACalcResult* sVaaCalcInfo, int32_ · 5 unmodified lines | |||
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | void CBackgroundDetection::ForegroundBackgroundDivision (vBGDParam* pBgdParam) { | 157 | void CBackgroundDetection::ForegroundBackgroundDivision (vBGDParam* pBgdParam) { |
| 158 | int32_t iPicWidthInOU = pBgdParam->iBgdWidth >> LOG2_BGD_OU_SIZE; | 158 | int32_t iPicWidthInOU = pBgdParam->iBgdWidth >> LOG2_BGD_OU_SIZE; |
| 159 | int32_t iPicHeightInOU = pBgdParam->iBgdHeight >> LOG2_BGD_OU_SIZE; | 159 | int32_t iPicHeightInOU = pBgdParam->iBgdHeight >> LOG2_BGD_OU_SIZE; |
| 160 | int32_t iPicWidthInMb = (15 + pBgdParam->iBgdWidth) >> 4; | 160 | int32_t iPicWidthInMb = (15 + pBgdParam->iBgdWidth) >> 4; |
| 161 | 161 | ||
| 162 | SBackgroundOU* pBackgroundOU = pBgdParam->pOU_array; | 162 | SBackgroundOU* pBackgroundOU = pBgdParam->pOU_array; |
| 163 | 163 | ||
| @@ -187,8 +187,8 @@ void CBackgroundDetection::ForegroundBackgroundDivision (vBGDParam* pBgdParam) { · 23 unmodified lines | |||
| 187 | } | 187 | } |
| 188 | } | 188 | } |
| 189 | inline int32_t CBackgroundDetection::CalculateAsdChromaEdge (uint8_t* pOriRef, uint8_t* pOriCur, int32_t iStride) { | 189 | inline int32_t CBackgroundDetection::CalculateAsdChromaEdge (uint8_t* pOriRef, uint8_t* pOriCur, int32_t iStride) { |
| 190 | int32_t ASD = 0; | 190 | int32_t ASD = 0; |
| 191 | int32_t idx; | 191 | int32_t idx; |
| 192 | for (idx = 0; idx < BGD_OU_SIZE_UV; idx++) { | 192 | for (idx = 0; idx < BGD_OU_SIZE_UV; idx++) { |
| 193 | ASD += *pOriCur - *pOriRef; | 193 | ASD += *pOriCur - *pOriRef; |
| 194 | pOriRef += iStride; | 194 | pOriRef += iStride; |
| @@ -199,16 +199,16 @@ inline int32_t CBackgroundDetection::CalculateAsdChromaEdge (uint8_t* pOriRef, u · 4 unmodified lines | |||
| 199 | 199 | ||
| 200 | inline bool CBackgroundDetection::ForegroundDilation23Luma (SBackgroundOU* pBackgroundOU, | 200 | inline bool CBackgroundDetection::ForegroundDilation23Luma (SBackgroundOU* pBackgroundOU, |
| 201 | SBackgroundOU* pOUNeighbours[]) { | 201 | SBackgroundOU* pOUNeighbours[]) { |
| 202 | SBackgroundOU* pOU_L = pOUNeighbours[0]; | 202 | SBackgroundOU* pOU_L = pOUNeighbours[0]; |
| 203 | SBackgroundOU* pOU_R = pOUNeighbours[1]; | 203 | SBackgroundOU* pOU_R = pOUNeighbours[1]; |
| 204 | SBackgroundOU* pOU_U = pOUNeighbours[2]; | 204 | SBackgroundOU* pOU_U = pOUNeighbours[2]; |
| 205 | SBackgroundOU* pOU_D = pOUNeighbours[3]; | 205 | SBackgroundOU* pOU_D = pOUNeighbours[3]; |
| 206 | 206 | ||
| 207 | if (pBackgroundOU->iMAD > pBackgroundOU->iMinSubMad << 1) { | 207 | if (pBackgroundOU->iMAD > pBackgroundOU->iMinSubMad << 1) { |
| 208 | int32_t iMaxNbrForegroundMad; | 208 | int32_t iMaxNbrForegroundMad; |
| 209 | int32_t iMaxNbrBackgroundMad; | 209 | int32_t iMaxNbrBackgroundMad; |
| 210 | int32_t aBackgroundMad[4]; | 210 | int32_t aBackgroundMad[4]; |
| 211 | int32_t aForegroundMad[4]; | 211 | int32_t aForegroundMad[4]; |
| 212 | 212 | ||
| 213 | aForegroundMad[0] = (pOU_L->iBackgroundFlag - 1) & pOU_L->iMAD; | 213 | aForegroundMad[0] = (pOU_L->iBackgroundFlag - 1) & pOU_L->iMAD; |
| 214 | aForegroundMad[1] = (pOU_R->iBackgroundFlag - 1) & pOU_R->iMAD; | 214 | aForegroundMad[1] = (pOU_R->iBackgroundFlag - 1) & pOU_R->iMAD; |
| @@ -232,9 +232,9 @@ inline bool CBackgroundDetection::ForegroundDilation23Luma (SBackgroundOU* pBack · 17 unmodified lines | |||
| 232 | 232 | ||
| 233 | inline bool CBackgroundDetection::ForegroundDilation23Chroma (int8_t iNeighbourForegroundFlags, | 233 | inline bool CBackgroundDetection::ForegroundDilation23Chroma (int8_t iNeighbourForegroundFlags, |
| 234 | int32_t iStartSamplePos, int32_t iPicStrideUV, vBGDParam* pBgdParam) { | 234 | int32_t iStartSamplePos, int32_t iPicStrideUV, vBGDParam* pBgdParam) { |
| 235 | static const int8_t kaOUPos[4] = {OU_LEFT, OU_RIGHT, OU_TOP, OU_BOTTOM}; | 235 | static const int8_t kaOUPos[4] = {OU_LEFT, OU_RIGHT, OU_TOP, OU_BOTTOM}; |
| 236 | int32_t aEdgeOffset[4] = {0, BGD_OU_SIZE_UV - 1, 0, iPicStrideUV* (BGD_OU_SIZE_UV - 1)}; | 236 | int32_t aEdgeOffset[4] = {0, BGD_OU_SIZE_UV - 1, 0, iPicStrideUV* (BGD_OU_SIZE_UV - 1)}; |
| 237 | int32_t iStride[4] = {iPicStrideUV, iPicStrideUV, 1, 1}; | 237 | int32_t iStride[4] = {iPicStrideUV, iPicStrideUV, 1, 1}; |
| 238 | 238 | ||
| 239 | // V component first, high probability because V stands for red color and human skin colors have more weight on this component | 239 | // V component first, high probability because V stands for red color and human skin colors have more weight on this component |
| 240 | for (int32_t i = 0; i < 4; i++) { | 240 | for (int32_t i = 0; i < 4; i++) { |
| @@ -262,8 +262,8 @@ inline bool CBackgroundDetection::ForegroundDilation23Chroma (int8_t iNeighbourF · 21 unmodified lines | |||
| 262 | 262 | ||
| 263 | inline void CBackgroundDetection::ForegroundDilation (SBackgroundOU* pBackgroundOU, SBackgroundOU* pOUNeighbours[], | 263 | inline void CBackgroundDetection::ForegroundDilation (SBackgroundOU* pBackgroundOU, SBackgroundOU* pOUNeighbours[], |
| 264 | vBGDParam* pBgdParam, int32_t iChromaSampleStartPos) { | 264 | vBGDParam* pBgdParam, int32_t iChromaSampleStartPos) { |
| 265 | int32_t iPicStrideUV = pBgdParam->iStride[1]; | 265 | int32_t iPicStrideUV = pBgdParam->iStride[1]; |
| 266 | int32_t iSumNeighBackgroundFlags = pOUNeighbours[0]->iBackgroundFlag + pOUNeighbours[1]->iBackgroundFlag + | 266 | int32_t iSumNeighBackgroundFlags = pOUNeighbours[0]->iBackgroundFlag + pOUNeighbours[1]->iBackgroundFlag + |
| 267 | pOUNeighbours[2]->iBackgroundFlag + pOUNeighbours[3]->iBackgroundFlag; | 267 | pOUNeighbours[2]->iBackgroundFlag + pOUNeighbours[3]->iBackgroundFlag; |
| 268 | 268 | ||
| 269 | if (pBackgroundOU->iSAD > BGD_OU_SIZE * Q_FACTOR) { | 269 | if (pBackgroundOU->iSAD > BGD_OU_SIZE * Q_FACTOR) { |
| @@ -318,10 +318,10 @@ inline void CBackgroundDetection::SetBackgroundMbFlag (int8_t* pBackgroundMbFlag · 48 unmodified lines | |||
| 318 | inline void CBackgroundDetection::UpperOUForegroundCheck (SBackgroundOU* pCurOU, int8_t* pBackgroundMbFlag, | 318 | inline void CBackgroundDetection::UpperOUForegroundCheck (SBackgroundOU* pCurOU, int8_t* pBackgroundMbFlag, |
| 319 | int32_t iPicWidthInOU, int32_t iPicWidthInMb) { | 319 | int32_t iPicWidthInOU, int32_t iPicWidthInMb) { |
| 320 | if (pCurOU->iSAD > BGD_OU_SIZE * Q_FACTOR) { | 320 | if (pCurOU->iSAD > BGD_OU_SIZE * Q_FACTOR) { |
| 321 | SBackgroundOU* pOU_L = pCurOU - 1; | 321 | SBackgroundOU* pOU_L = pCurOU - 1; |
| 322 | SBackgroundOU* pOU_R = pCurOU + 1; | 322 | SBackgroundOU* pOU_R = pCurOU + 1; |
| 323 | SBackgroundOU* pOU_U = pCurOU - iPicWidthInOU; | 323 | SBackgroundOU* pOU_U = pCurOU - iPicWidthInOU; |
| 324 | SBackgroundOU* pOU_D = pCurOU + iPicWidthInOU; | 324 | SBackgroundOU* pOU_D = pCurOU + iPicWidthInOU; |
| 325 | if (pOU_L->iBackgroundFlag + pOU_R->iBackgroundFlag + pOU_U->iBackgroundFlag + pOU_D->iBackgroundFlag <= 1) { | 325 | if (pOU_L->iBackgroundFlag + pOU_R->iBackgroundFlag + pOU_U->iBackgroundFlag + pOU_D->iBackgroundFlag <= 1) { |
| 326 | SetBackgroundMbFlag (pBackgroundMbFlag, iPicWidthInMb, 0); | 326 | SetBackgroundMbFlag (pBackgroundMbFlag, iPicWidthInMb, 0); |
| 327 | pCurOU->iBackgroundFlag = 0; | 327 | pCurOU->iBackgroundFlag = 0; |
| @@ -330,21 +330,21 @@ inline void CBackgroundDetection::UpperOUForegroundCheck (SBackgroundOU* pCurOU, · 2 unmodified lines | |||
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | void CBackgroundDetection::ForegroundDilationAndBackgroundErosion (vBGDParam* pBgdParam) { | 332 | void CBackgroundDetection::ForegroundDilationAndBackgroundErosion (vBGDParam* pBgdParam) { |
| 333 | int32_t iPicStrideUV = pBgdParam->iStride[1]; | 333 | int32_t iPicStrideUV = pBgdParam->iStride[1]; |
| 334 | int32_t iPicWidthInOU = pBgdParam->iBgdWidth >> LOG2_BGD_OU_SIZE; | 334 | int32_t iPicWidthInOU = pBgdParam->iBgdWidth >> LOG2_BGD_OU_SIZE; |
| 335 | int32_t iPicHeightInOU = pBgdParam->iBgdHeight >> LOG2_BGD_OU_SIZE; | 335 | int32_t iPicHeightInOU = pBgdParam->iBgdHeight >> LOG2_BGD_OU_SIZE; |
| 336 | int32_t iOUStrideUV = iPicStrideUV << (LOG2_BGD_OU_SIZE - 1); | 336 | int32_t iOUStrideUV = iPicStrideUV << (LOG2_BGD_OU_SIZE - 1); |
| 337 | int32_t iPicWidthInMb = (15 + pBgdParam->iBgdWidth) >> 4; | 337 | int32_t iPicWidthInMb = (15 + pBgdParam->iBgdWidth) >> 4; |
| 338 | 338 | ||
| 339 | SBackgroundOU* pBackgroundOU = pBgdParam->pOU_array; | 339 | SBackgroundOU* pBackgroundOU = pBgdParam->pOU_array; |
| 340 | int8_t* pVaaBackgroundMbFlag = (int8_t*)pBgdParam->pBackgroundMbFlag; | 340 | int8_t* pVaaBackgroundMbFlag = (int8_t*)pBgdParam->pBackgroundMbFlag; |
| 341 | SBackgroundOU* pOUNeighbours[4];//0: left; 1: right; 2: top; 3: bottom | 341 | SBackgroundOU* pOUNeighbours[4];//0: left; 1: right; 2: top; 3: bottom |
| 342 | 342 | ||
| 343 | pOUNeighbours[2] = pBackgroundOU;//top OU | 343 | pOUNeighbours[2] = pBackgroundOU;//top OU |
| 344 | for (int32_t j = 0; j < iPicHeightInOU; j ++) { | 344 | for (int32_t j = 0; j < iPicHeightInOU; j ++) { |
| 345 | int8_t* pRowSkipFlag = pVaaBackgroundMbFlag; | 345 | int8_t* pRowSkipFlag = pVaaBackgroundMbFlag; |
| 346 | pOUNeighbours[0] = pBackgroundOU;//left OU | 346 | pOUNeighbours[0] = pBackgroundOU;//left OU |
| 347 | pOUNeighbours[3] = pBackgroundOU + (iPicWidthInOU & ((j == iPicHeightInOU - 1) - 1)); //bottom OU | 347 | pOUNeighbours[3] = pBackgroundOU + (iPicWidthInOU & ((j == iPicHeightInOU - 1) - 1)); //bottom OU |
| 348 | for (int32_t i = 0; i < iPicWidthInOU; i++) { | 348 | for (int32_t i = 0; i < iPicWidthInOU; i++) { |
| 349 | pOUNeighbours[1] = pBackgroundOU + (i < iPicWidthInOU - 1); //right OU | 349 | pOUNeighbours[1] = pBackgroundOU + (i < iPicWidthInOU - 1); //right OU |
| 350 | 350 | ||
| @@ -367,7 +367,7 @@ void CBackgroundDetection::ForegroundDilationAndBackgroundErosion (vBGDParam* pB · 16 unmodified lines | |||
| 367 | pOUNeighbours[3]++; | 367 | pOUNeighbours[3]++; |
| 368 | pBackgroundOU++; | 368 | pBackgroundOU++; |
| 369 | } | 369 | } |
| 370 | pOUNeighbours[2] = pBackgroundOU - iPicWidthInOU; | 370 | pOUNeighbours[2] = pBackgroundOU - iPicWidthInOU; |
| 371 | pVaaBackgroundMbFlag += OU_SIZE_IN_MB * iPicWidthInMb; | 371 | pVaaBackgroundMbFlag += OU_SIZE_IN_MB * iPicWidthInMb; |
| 372 | } | 372 | } |
| 373 | } | 373 | } |