Changeset 296 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
 Timestamp:
 20 Feb 2013, 22:07:43 (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
r56 r296 100 100 * \param *psQTPart, iPartIdx, dLambda 101 101 */ 102 #if SAO_UNIT_INTERLEAVING103 102 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda) 104 103 { … … 340 339 } 341 340 342 #else343 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda)344 {345 Int iTypeIdx;346 Int iNumTotalType = MAX_NUM_SAO_TYPE;347 SAOQTPart* pOnePart = &(psQTPart[iPartIdx]);348 349 Int64 iEstDist;350 Int64 iOffsetOrg;351 Int64 iOffset;352 Int64 iCount;353 Int iClassIdx;354 Int uiShift = g_uiBitIncrement << 1;355 356 UInt uiDepth = pOnePart>PartLevel;357 358 m_iDistOrg [iPartIdx] = 0;359 360 for (iTypeIdx=1; iTypeIdx<iNumTotalType; iTypeIdx++)361 {362 if( m_bUseSBACRD )363 {364 m_pcRDGoOnSbacCoder>load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);365 m_pcRDGoOnSbacCoder>resetBits();366 }367 else368 {369 m_pcEntropyCoder>resetEntropy();370 m_pcEntropyCoder>resetBits();371 }372 373 iEstDist = 0;374 375 m_pcEntropyCoder>m_pcEntropyCoderIf>codeSaoUvlc(iTypeIdx+1);376 377 if (iTypeIdx>=0)378 {379 380 for(iClassIdx=1; iClassIdx < m_iNumClass[iTypeIdx]+1; iClassIdx++)381 {382 if(m_iCount [iPartIdx][iTypeIdx][iClassIdx])383 {384 #if FULL_NBIT385 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitDepth8) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));386 #else387 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = (Int64) xRoundIbdi((Double)(m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]<<g_uiBitIncrement) / (Double)(m_iCount [iPartIdx][iTypeIdx][iClassIdx]<<m_uiSaoBitIncrease));388 #endif389 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = Clip3(m_iOffsetTh, m_iOffsetTh1, (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);390 {391 Int64 iterOffset, tempOffset;392 Int64 tempDist, tempRate;393 Double tempCost, tempMinCost;394 UInt codeLength, tempValue;395 396 iterOffset = m_iOffset[iPartIdx][iTypeIdx][iClassIdx];397 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;398 tempMinCost = dLambda; // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here.399 400 while (iterOffset != 0)401 {402 // Calculate the bits required for signalling the offset403 codeLength = 1;404 tempValue = (UInt)((iterOffset <= 0) ? ( (iterOffset<<1) + 1 ) : (iterOffset<<1));405 while( 1 != tempValue )406 {407 tempValue >>= 1;408 codeLength += 2;409 }410 tempRate = (codeLength >> 1) + ((codeLength+1) >> 1);411 412 // Do the dequntization before distorion calculation413 tempOffset = iterOffset << m_uiSaoBitIncrease;414 tempDist = (( m_iCount [iPartIdx][iTypeIdx][iClassIdx]*tempOffset*tempOffsetm_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx]*tempOffset*2 ) >> uiShift);415 416 tempCost = ((Double)tempDist + dLambda * (Double) tempRate);417 if(tempCost < tempMinCost)418 {419 tempMinCost = tempCost;420 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = iterOffset;421 }422 iterOffset = (iterOffset > 0) ? (iterOffset1):(iterOffset+1);423 }424 }425 }426 else427 {428 m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] = 0;429 m_iOffset[iPartIdx][iTypeIdx][iClassIdx] = 0;430 }431 432 iCount = m_iCount [iPartIdx][iTypeIdx][iClassIdx];433 iOffset = m_iOffset[iPartIdx][iTypeIdx][iClassIdx] << m_uiSaoBitIncrease;434 iOffsetOrg = m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx];435 iEstDist += (( iCount*iOffset*iOffsetiOffsetOrg*iOffset*2 ) >> uiShift);436 m_pcEntropyCoder>m_pcEntropyCoderIf>codeSaoSvlc((Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx]);437 }438 m_iDist[iPartIdx][iTypeIdx] = iEstDist;439 m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder>getNumberOfWrittenBits();440 441 m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);442 443 if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])444 {445 m_iDistOrg [iPartIdx] = 0;446 m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];447 m_iTypePartBest[iPartIdx] = iTypeIdx;448 if( m_bUseSBACRD )449 m_pcRDGoOnSbacCoder>store( m_pppcRDSbacCoder[pOnePart>PartLevel][CI_TEMP_BEST] );450 }451 }452 else453 {454 if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )455 {456 m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder>getNumberOfWrittenBits()*dLambda ;457 m_iTypePartBest[iPartIdx] = 1;458 if( m_bUseSBACRD )459 m_pcRDGoOnSbacCoder>store( m_pppcRDSbacCoder[pOnePart>PartLevel][CI_TEMP_BEST] );460 }461 }462 }463 464 pOnePart>bProcessed = true;465 pOnePart>bSplit = false;466 pOnePart>iMinDist = m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];467 pOnePart>iMinRate = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);468 pOnePart>dMinCost = pOnePart>iMinDist + dLambda * pOnePart>iMinRate;469 pOnePart>iBestType = m_iTypePartBest[iPartIdx];470 if (pOnePart>iBestType != 1)471 {472 pOnePart>bEnableFlag = 1;473 pOnePart>iLength = m_iNumClass[pOnePart>iBestType];474 for (Int i=0; i<pOnePart>iLength ; i++)475 pOnePart>iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart>iBestType][i+1];476 }477 else478 {479 pOnePart>bEnableFlag = 0;480 pOnePart>iLength = 0;481 }482 }483 484 #endif485 341 /** Run partition tree disable 486 342 */ … … 488 344 { 489 345 SAOQTPart* pOnePart= &(psQTPart[iPartIdx]); 490 #if !SAO_UNIT_INTERLEAVING491 pOnePart>bEnableFlag = false;492 #endif493 346 pOnePart>bSplit = false; 494 347 pOnePart>iLength = 0; … … 556 409 dCostFinal = dCostSplit; 557 410 pOnePart>bSplit = true; 558 #if !SAO_UNIT_INTERLEAVING559 pOnePart>bEnableFlag = false;560 #endif561 411 pOnePart>iLength = 0; 562 412 pOnePart>iBestType = 1; … … 810 660 Int x, y; 811 661 812 #if SAO_UNIT_INTERLEAVING813 662 // Band offset// 814 663 stats = ppStats[SAO_BO]; … … 830 679 pRec += stride; 831 680 } 832 #else833 // Band offset 0//834 stats = ppStats[SAO_BO_0];835 count = ppCount[SAO_BO_0];836 pOrg = pOrgStart;837 pRec = pRecStart;838 for (y=0; y< height; y++)839 {840 for (x=0; x< width; x++)841 {842 classIdx = m_ppLumaTableBo0[pRec[x]];843 if (classIdx)844 {845 stats[classIdx] += (pOrg[x]  pRec[x]);846 count[classIdx] ++;847 }848 }849 pOrg += stride;850 pRec += stride;851 }852 853 // Band offset 1//854 stats = ppStats[SAO_BO_1];855 count = ppCount[SAO_BO_1];856 pOrg = pOrgStart;857 pRec = pRecStart;858 859 for (y=0; y< height; y++)860 {861 for (x=0; x< width; x++)862 {863 classIdx = m_ppLumaTableBo1[pRec[x]];864 if (classIdx)865 {866 stats[classIdx] += (pOrg[x]  pRec[x]);867 count[classIdx] ++;868 }869 }870 pOrg += stride;871 pRec += stride;872 }873 #endif874 681 // Edge offset 0// 875 682 stats = ppStats[SAO_EO_0]; … … 1166 973 1167 974 Int iIsChroma = (iYCbCr!=0)? 1:0; 1168 #if SAO_UNIT_INTERLEAVING1169 975 Int numSkipLine = iIsChroma? 2:4; 1170 976 if (m_saoInterleavingFlag == 0) … … 1172 978 numSkipLine = 0; 1173 979 } 1174 #endif1175 980 1176 981 iPicWidthTmp = m_iPicWidth >> iIsChroma; … … 1194 999 #endif 1195 1000 { 1196 #if SAO_UNIT_INTERLEAVING1197 1001 iStats = m_iOffsetOrg[iPartIdx][SAO_BO]; 1198 1002 iCount = m_iCount [iPartIdx][SAO_BO]; 1199 #else1200 iStats = m_iOffsetOrg[iPartIdx][SAO_BO_0];1201 iCount = m_iCount [iPartIdx][SAO_BO_0];1202 #endif1203 1003 1204 1004 pOrg = getPicYuvAddr(m_pcPic>getPicYuvOrg(), iYCbCr, iAddr); 1205 1005 pRec = getPicYuvAddr(m_pcPic>getPicYuvRec(), iYCbCr, iAddr); 1206 1006 1207 #if SAO_UNIT_INTERLEAVING1208 1007 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight : iLcuHeightnumSkipLine; 1209 1008 for (y=0; y<iEndY; y++) 1210 #else1211 for (y=0; y<iLcuHeight; y++)1212 #endif1213 1009 { 1214 1010 for (x=0; x<iLcuWidth; x++) 1215 1011 { 1216 #if SAO_UNIT_INTERLEAVING1217 1012 iClassIdx = m_lumaTableBo[pRec[x]]; 1218 #else1219 iClassIdx = m_ppLumaTableBo0[pRec[x]];1220 #endif1221 1013 if (iClassIdx) 1222 1014 { … … 1229 1021 } 1230 1022 1231 #if !SAO_UNIT_INTERLEAVING1232 iStats = m_iOffsetOrg[iPartIdx][SAO_BO_1];1233 iCount = m_iCount [iPartIdx][SAO_BO_1];1234 1235 pOrg = getPicYuvAddr(m_pcPic>getPicYuvOrg(), iYCbCr, iAddr);1236 pRec = getPicYuvAddr(m_pcPic>getPicYuvRec(), iYCbCr, iAddr);1237 1238 for (y=0; y<iLcuHeight; y++)1239 {1240 for (x=0; x<iLcuWidth; x++)1241 {1242 iClassIdx = m_ppLumaTableBo1[pRec[x]];1243 if (iClassIdx)1244 {1245 iStats[iClassIdx] += (pOrg[x]  pRec[x]);1246 iCount[iClassIdx] ++;1247 }1248 }1249 pOrg += iStride;1250 pRec += iStride;1251 }1252 #endif1253 1023 } 1254 1024 Int iSignLeft; … … 1275 1045 iStartX = (uiLPelX == 0) ? 1 : 0; 1276 1046 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth1 : iLcuWidth; 1277 #if SAO_UNIT_INTERLEAVING1278 1047 for (y=0; y<iLcuHeightnumSkipLine; y++) 1279 #else1280 for (y=0; y<iLcuHeight; y++)1281 #endif1282 1048 { 1283 1049 iSignLeft = xSign(pRec[iStartX]  pRec[iStartX1]); … … 1305 1071 1306 1072 iStartY = (uiTPelY == 0) ? 1 : 0; 1307 #if SAO_UNIT_INTERLEAVING1308 1073 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight1 : iLcuHeightnumSkipLine; 1309 #else1310 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight1 : iLcuHeight;1311 #endif1312 1074 if (uiTPelY == 0) 1313 1075 { … … 1347 1109 1348 1110 iStartY = (uiTPelY == 0) ? 1 : 0; 1349 #if SAO_UNIT_INTERLEAVING1350 1111 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight1 : iLcuHeightnumSkipLine; 1351 #else1352 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight1 : iLcuHeight;1353 #endif1354 1112 if (uiTPelY == 0) 1355 1113 { … … 1394 1152 1395 1153 iStartY = (uiTPelY == 0) ? 1 : 0; 1396 #if SAO_UNIT_INTERLEAVING1397 1154 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight1 : iLcuHeightnumSkipLine; 1398 #else1399 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight1 : iLcuHeight;1400 #endif1401 1155 if (iStartY == 1) 1402 1156 { … … 1486 1240 for (iTypeIdx=0; iTypeIdx<iNumTotalType; iTypeIdx++) 1487 1241 { 1488 #if SAO_UNIT_INTERLEAVING1489 1242 for (iClassIdx=0; iClassIdx< (iTypeIdx < SAO_BO ? m_iNumClass[iTypeIdx] : SAO_MAX_BO_CLASSES) +1; iClassIdx++) 1490 #else1491 for (iClassIdx=0; iClassIdx<m_iNumClass[iTypeIdx]+1; iClassIdx++)1492 #endif1493 1243 { 1494 1244 m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] += m_iOffsetOrg[iDownPartIdx][iTypeIdx][iClassIdx]; … … 1574 1324 Double dCostFinal = 0; 1575 1325 1576 #if !SAO_UNIT_INTERLEAVING 1577 Int iCb = 1; 1578 Int iCr = 2; 1579 Double dCostFinalCb = 0; 1580 Double dCostFinalCr = 0; 1581 #endif 1582 1583 #if SAO_UNIT_INTERLEAVING 1326 1584 1327 if ( m_saoInterleavingFlag) 1585 1328 { … … 1616 1359 } 1617 1360 } 1618 #else 1619 getSaoStats(pcSaoParam>psSaoPart[iY], iY); 1620 runQuadTreeDecision(pcSaoParam>psSaoPart[iY], 0, dCostFinal, m_uiMaxSplitLevel, m_dLambdaLuma); 1621 pcSaoParam>bSaoFlag[iY] = dCostFinal < m_iDistOrg[0] ? 1:0; 1622 if(pcSaoParam>bSaoFlag[iY]) 1623 { 1624 processSaoQuadTree(pcSaoParam>psSaoPart[iY], 0, 0); 1625 1626 resetStats(); 1627 getSaoStats(pcSaoParam>psSaoPart[iCb], iCb); 1628 runQuadTreeDecision(pcSaoParam>psSaoPart[iCb], 0, dCostFinalCb, m_uiMaxSplitLevel, m_dLambdaChroma); 1629 pcSaoParam>bSaoFlag[iCb] = dCostFinalCb < 0 ? 1:0; 1630 if (pcSaoParam>bSaoFlag[iCb]) 1631 { 1632 processSaoQuadTree(pcSaoParam>psSaoPart[iCb], 0, iCb); 1633 } 1634 1635 resetStats(); 1636 getSaoStats(pcSaoParam>psSaoPart[iCr], iCr); 1637 runQuadTreeDecision(pcSaoParam>psSaoPart[iCr], 0, dCostFinalCr, m_uiMaxSplitLevel, m_dLambdaChroma); 1638 pcSaoParam>bSaoFlag[iCr] = dCostFinalCr < 0 ? 1:0; 1639 if (pcSaoParam>bSaoFlag[iCr]) 1640 { 1641 processSaoQuadTree(pcSaoParam>psSaoPart[iCr], 0, iCr); 1642 } 1643 } 1644 #endif 1645 } 1646 #if SAO_UNIT_INTERLEAVING 1361 } 1647 1362 /** Check merge SAO unit 1648 1363 * \param saoUnitCurr current SAO unit … … 2260 1975 } 2261 1976 2262 #endif2263 1977 2264 1978 //! \}
Note: See TracChangeset for help on using the changeset viewer.