Ticket #922: RDOQuant.patch
File RDOQuant.patch, 13.0 KB (added by lkerofsky, 11 years ago) |
---|
-
Lib/TLibCommon/TComRdCost.cpp
449 449 } 450 450 451 451 #if WEIGHTED_CHROMA_DISTORTION 452 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bWeighted, DFunc eDFunc)452 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bWeighted, TextType eText, DFunc eDFunc) 453 453 #else 454 454 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc ) 455 455 #endif … … 469 469 #if WEIGHTED_CHROMA_DISTORTION 470 470 if (bWeighted) 471 471 { 472 return ((Int) (m_chromaDistortionWeight * cDtParam.DistFunc( &cDtParam ))); 472 if(eText==TEXT_CHROMA_U) 473 { 474 return ((int) (m_cbDistortionWeight * cDtParam.DistFunc( &cDtParam ))); 475 } 476 else 477 { 478 return ((int) (m_crDistortionWeight * cDtParam.DistFunc( &cDtParam ))); 479 } 473 480 } 474 481 else 475 482 { -
Lib/TLibCommon/TComRdCost.h
125 125 #endif 126 126 127 127 #if WEIGHTED_CHROMA_DISTORTION 128 Double m_chromaDistortionWeight; 128 Double m_cbDistortionWeight; 129 Double m_crDistortionWeight; 129 130 #endif 130 131 Double m_dLambda; 131 132 Double m_sqrtLambda; … … 156 157 Double calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT ); 157 158 158 159 #if WEIGHTED_CHROMA_DISTORTION 159 Void setChromaDistortionWeight ( Double chromaDistortionWeight) { m_chromaDistortionWeight = chromaDistortionWeight; }; 160 Void setCbDistortionWeight ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; }; 161 Void setCrDistortionWeight ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; }; 160 162 #endif 161 163 Void setLambda ( Double dLambda ); 162 164 Void setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; } … … 256 258 257 259 public: 258 260 #if WEIGHTED_CHROMA_DISTORTION 259 UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bWeighted = false, DFunc eDFunc = DF_SSE );261 UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bWeighted = false, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE ); 260 262 #else 261 263 UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE ); 262 264 #endif -
Lib/TLibEncoder/TEncSearch.cpp
1362 1362 1363 1363 //===== update distortion ===== 1364 1364 #if WEIGHTED_CHROMA_DISTORTION 1365 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, true );1365 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, true, eText ); 1366 1366 #else 1367 1367 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight ); 1368 1368 #endif … … 4011 4011 uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] ); 4012 4012 #else 4013 4013 #if WEIGHTED_CHROMA_DISTORTION 4014 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, false, DF_SAD );4014 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, false, TEXT_LUMA, DF_SAD ); 4015 4015 #else 4016 4016 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD ); 4017 4017 #endif … … 4452 4452 4453 4453 #if WEIGHTED_CHROMA_DISTORTION 4454 4454 uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 4455 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true )4456 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true );4455 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true, TEXT_CHROMA_U ) 4456 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true, TEXT_CHROMA_V ); 4457 4457 #else 4458 4458 uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 4459 4459 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 ) … … 4644 4644 4645 4645 // update with clipped distortion and cost (qp estimation loop uses unclipped values) 4646 4646 #if WEIGHTED_CHROMA_DISTORTION 4647 uiDistortionBest= m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight )4648 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true)4649 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true);4647 uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 4648 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true, TEXT_CHROMA_U ) 4649 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, true, TEXT_CHROMA_V ); 4650 4650 #else 4651 4651 uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 4652 4652 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 ) -
Lib/TLibEncoder/TEncSlice.cpp
340 340 // for RDO 341 341 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 342 342 Double weight = 1.0; 343 if(iQP >= 0) 344 { 345 weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 ); // takes into account of the chroma qp mapping without chroma qp Offset 346 } 347 m_pcRdCost ->setChromaDistortionWeight( weight ); 343 Int iQPC; 344 Int iChromaQPOffset; 345 346 iChromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb(); 347 iQPC = Clip3( 0, 57, iQP + iChromaQPOffset); 348 weight = pow( 2.0, (iQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 349 m_pcRdCost->setCbDistortionWeight(weight); 350 351 iChromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr(); 352 iQPC = Clip3( 0, 57, iQP + iChromaQPOffset); 353 weight = pow( 2.0, (iQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 354 m_pcRdCost->setCrDistortionWeight(weight); 348 355 #endif 349 356 350 357 #if RDOQ_CHROMA_LAMBDA … … 453 460 #if WEIGHTED_CHROMA_DISTORTION 454 461 // for RDO 455 462 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 456 double weight = pow( 2.0, (sliceQP-g_aucChromaScale[sliceQP])/3.0 ); // takes into account of the chroma qp mapping without chroma qp Offset 457 m_pcRdCost ->setChromaDistortionWeight( weight ); 463 Double weight; 464 Int iQPC; 465 Int iChromaQPOffset; 466 467 iChromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb(); 468 iQPC = Clip3( 0, 57, sliceQP + iChromaQPOffset); 469 weight = pow( 2.0, (sliceQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 470 m_pcRdCost->setCbDistortionWeight(weight); 471 472 iChromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr(); 473 iQPC = Clip3( 0, 57, sliceQP + iChromaQPOffset); 474 weight = pow( 2.0, (sliceQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 475 m_pcRdCost->setCrDistortionWeight(weight); 458 476 #endif 459 477 460 478 #if RDOQ_CHROMA_LAMBDA … … 547 565 // for RDO 548 566 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 549 567 Double weight = 1.0; 550 if(qp >= 0) 551 { 552 weight = pow( 2.0, (qp-g_aucChromaScale[qp])/3.0 ); // takes into account of the chroma qp mapping without chroma qp Offset 553 } 554 m_pcRdCost ->setChromaDistortionWeight( weight ); 568 Int iQPC; 569 Int iChromaQPOffset; 570 571 iChromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 572 iQPC = Clip3( 0, 57, qp + iChromaQPOffset); 573 weight = pow( 2.0, (qp-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 574 m_pcRdCost->setCbDistortionWeight(weight); 575 576 iChromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 577 iQPC = Clip3( 0, 57, qp + iChromaQPOffset); 578 weight = pow( 2.0, (qp-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 579 m_pcRdCost->setCrDistortionWeight(weight); 555 580 #endif 556 581 557 582 #if RDOQ_CHROMA_LAMBDA … … 651 676 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 652 677 Int iQP = m_piRdPicQp [uiQpIdx]; 653 678 Double weight = 1.0; 654 if(iQP >= 0) 655 { 656 weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 ); // takes into account of the chroma qp mapping without chroma qp Offset 657 } 658 m_pcRdCost ->setChromaDistortionWeight( weight ); 679 Int iQPC; 680 Int iChromaQPOffset; 681 682 iChromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 683 iQPC = Clip3( 0, 57, iQP + iChromaQPOffset); 684 weight = pow( 2.0, (iQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 685 m_pcRdCost->setCbDistortionWeight(weight); 686 687 iChromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 688 iQPC = Clip3( 0, 57, iQP + iChromaQPOffset); 689 weight = pow( 2.0, (iQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 690 m_pcRdCost->setCrDistortionWeight(weight); 659 691 #endif 660 692 661 693 #if RDOQ_CHROMA_LAMBDA … … 700 732 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 701 733 Int iQP = m_piRdPicQp [uiQpIdxBest]; 702 734 Double weight = 1.0; 703 if(iQP >= 0) 704 { 705 weight = pow( 2.0, (iQP-g_aucChromaScale[iQP])/3.0 ); // takes into account of the chroma qp mapping without chroma qp Offset 706 } 707 m_pcRdCost ->setChromaDistortionWeight( weight ); 735 Int iQPC; 736 Int iChromaQPOffset; 737 738 iChromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 739 iQPC = Clip3( 0, 57, iQP + iChromaQPOffset); 740 weight = pow( 2.0, (iQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 741 m_pcRdCost->setCbDistortionWeight(weight); 742 743 iChromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 744 iQPC = Clip3( 0, 57, iQP + iChromaQPOffset); 745 weight = pow( 2.0, (iQP-g_aucChromaScale[iQPC])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 746 m_pcRdCost->setCrDistortionWeight(weight); 708 747 #endif 709 748 710 749 #if RDOQ_CHROMA_LAMBDA