Ticket #922: RDOQuant.patch

File RDOQuant.patch, 13.0 KB (added by lkerofsky, 9 years ago)
  • Lib/TLibCommon/TComRdCost.cpp

     
    449449}
    450450
    451451#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 )
     452UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, Bool bWeighted, TextType eText, DFunc eDFunc)
    453453#else
    454454UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc )
    455455#endif
     
    469469#if WEIGHTED_CHROMA_DISTORTION
    470470  if (bWeighted)
    471471  {
    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    }
    473480  }
    474481  else
    475482  {
  • Lib/TLibCommon/TComRdCost.h

     
    125125#endif 
    126126 
    127127#if WEIGHTED_CHROMA_DISTORTION
    128   Double                  m_chromaDistortionWeight;   
     128  Double                  m_cbDistortionWeight;
     129  Double                  m_crDistortionWeight;
    129130#endif
    130131  Double                  m_dLambda;
    131132  Double                  m_sqrtLambda;
     
    156157  Double  calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT );
    157158 
    158159#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; };
    160162#endif
    161163  Void    setLambda      ( Double dLambda );
    162164  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
     
    256258 
    257259public:
    258260#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 );
    260262#else
    261263  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
    262264#endif
  • Lib/TLibEncoder/TEncSearch.cpp

     
    13621362 
    13631363  //===== update distortion =====
    13641364#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 );
    13661366#else
    13671367  ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
    13681368#endif
     
    40114011  uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] );
    40124012#else
    40134013#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 );
    40154015#else
    40164016  uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD );
    40174017#endif
     
    44524452   
    44534453#if WEIGHTED_CHROMA_DISTORTION
    44544454    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 );
    44574457#else
    44584458    uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    44594459    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
     
    46444644 
    46454645  // update with clipped distortion and cost (qp estimation loop uses unclipped values)
    46464646#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 );
    46504650#else
    46514651  uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    46524652  + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
  • Lib/TLibEncoder/TEncSlice.cpp

     
    340340// for RDO
    341341  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    342342  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);
    348355#endif
    349356
    350357#if RDOQ_CHROMA_LAMBDA
     
    453460#if WEIGHTED_CHROMA_DISTORTION
    454461  // for RDO
    455462  // 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);
    458476#endif
    459477
    460478#if RDOQ_CHROMA_LAMBDA
     
    547565  // for RDO
    548566  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    549567  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);
    555580#endif
    556581
    557582#if RDOQ_CHROMA_LAMBDA
     
    651676    // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    652677    Int iQP = m_piRdPicQp    [uiQpIdx];
    653678    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);
    659691#endif
    660692
    661693#if RDOQ_CHROMA_LAMBDA
     
    700732  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    701733  Int iQP = m_piRdPicQp    [uiQpIdxBest];
    702734  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);
    708747#endif
    709748
    710749#if RDOQ_CHROMA_LAMBDA