diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp index 6a349d48b132099084984e469885f21312fc58b3..596d92de2c190b4e775ca92ea01ca51ac58c6c64 100644 --- a/source/Lib/CommonLib/InterPrediction.cpp +++ b/source/Lib/CommonLib/InterPrediction.cpp @@ -530,16 +530,15 @@ void InterPrediction::xPredInterBi(PredictionUnit &pu, PelUnitBuf &pcYuvPred, co { const PPS &pps = *pu.cs->pps; const Slice &slice = *pu.cs->slice; - CHECK( !pu.cu->affine && pu.refIdx[0] >= 0 && pu.refIdx[1] >= 0 && ( pu.lwidth() + pu.lheight() == 12 ), "invalid 4x8/8x4 bi-predicted blocks" ); - int refIdx0 = pu.refIdx[REF_PIC_LIST_0]; - int refIdx1 = pu.refIdx[REF_PIC_LIST_1]; + const int refIdx0 = pu.refIdx[REF_PIC_LIST_0]; + const int refIdx1 = pu.refIdx[REF_PIC_LIST_1]; - const WPScalingParam *wp0 = pu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0); - const WPScalingParam *wp1 = pu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1); + CHECK(!pu.cu->affine && refIdx0 >= 0 && refIdx1 >= 0 && pu.lwidth() + pu.lheight() == 12, + "invalid 4x8/8x4 bi-predicted blocks"); bool bioApplied = false; - if (pu.cs->sps->getBDOFEnabledFlag() && (!pu.cs->picHeader->getBdofDisabledFlag())) + if (pu.cs->sps->getBDOFEnabledFlag() && !pu.cs->picHeader->getBdofDisabledFlag()) { if (pu.cu->affine || m_subPuMC) { @@ -547,42 +546,15 @@ void InterPrediction::xPredInterBi(PredictionUnit &pu, PelUnitBuf &pcYuvPred, co } else { - const bool biocheck0 = - !((WPScalingParam::isWeighted(wp0) || WPScalingParam::isWeighted(wp1)) && slice.getSliceType() == B_SLICE); - const bool biocheck1 = !(pps.getUseWP() && slice.getSliceType() == P_SLICE); - if (biocheck0 - && biocheck1 - && PU::isBiPredFromDifferentDirEqDistPoc(pu) - && (pu.Y().height >= 8) - && (pu.Y().width >= 8) - && ((pu.Y().height * pu.Y().width) >= 128) - ) - { - bioApplied = true; - } - } - - if (bioApplied && pu.ciipFlag) - { - bioApplied = false; - } - - if (bioApplied && pu.cu->smvdMode) - { - bioApplied = false; - } - - if (pu.cu->cs->sps->getUseBcw() && bioApplied && pu.cu->bcwIdx != BCW_DEFAULT) - { - bioApplied = false; + bioApplied = PU::isSimpleSymmetricBiPred(pu) && PU::dmvrBdofSizeCheck(pu) && !pu.ciipFlag && !pu.cu->smvdMode; } } if (pu.mmvdEncOptMode == 2 && pu.mmvdMergeFlag) { bioApplied = false; } - bool dmvrApplied = false; - dmvrApplied = (pu.mvRefine) && PU::checkDMVRCondition(pu); + + bool dmvrApplied = (pu.mvRefine) && PU::checkDMVRCondition(pu); bool refIsScaled = ( refIdx0 < 0 ? false : pu.cu->slice->getRefPic( REF_PIC_LIST_0, refIdx0 )->isRefScaled( pu.cs->pps ) ) || ( refIdx1 < 0 ? false : pu.cu->slice->getRefPic( REF_PIC_LIST_1, refIdx1 )->isRefScaled( pu.cs->pps ) ); @@ -1479,16 +1451,13 @@ void InterPrediction::motionCompensation(PredictionUnit &pu, PelUnitBuf &predBuf } else { - CHECK( !pu.cu->affine && pu.refIdx[0] >= 0 && pu.refIdx[1] >= 0 && ( pu.lwidth() + pu.lheight() == 12 ), "invalid 4x8/8x4 bi-predicted blocks" ); - int refIdx0 = pu.refIdx[REF_PIC_LIST_0]; - int refIdx1 = pu.refIdx[REF_PIC_LIST_1]; - - const WPScalingParam *wp0 = pu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0); - const WPScalingParam *wp1 = pu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1); + const int refIdx0 = pu.refIdx[REF_PIC_LIST_0]; + const int refIdx1 = pu.refIdx[REF_PIC_LIST_1]; + CHECK(!pu.cu->affine && refIdx0 >= 0 && refIdx1 >= 0 && pu.lwidth() + pu.lheight() == 12, + "invalid 4x8/8x4 bi-predicted blocks"); bool bioApplied = false; - const Slice &slice = *pu.cs->slice; - if (pu.cs->sps->getBDOFEnabledFlag() && (!pu.cs->picHeader->getBdofDisabledFlag())) + if (pu.cs->sps->getBDOFEnabledFlag() && !pu.cs->picHeader->getBdofDisabledFlag()) { if (pu.cu->affine || m_subPuMC) { @@ -1496,34 +1465,9 @@ void InterPrediction::motionCompensation(PredictionUnit &pu, PelUnitBuf &predBuf } else { - const bool biocheck0 = - !((WPScalingParam::isWeighted(wp0) || WPScalingParam::isWeighted(wp1)) && slice.getSliceType() == B_SLICE); - const bool biocheck1 = !(pps.getUseWP() && slice.getSliceType() == P_SLICE); - if (biocheck0 - && biocheck1 - && PU::isBiPredFromDifferentDirEqDistPoc(pu) - && (pu.Y().height >= 8) - && (pu.Y().width >= 8) - && ((pu.Y().height * pu.Y().width) >= 128) - ) - { - bioApplied = true; - } - } - - if (bioApplied && pu.ciipFlag) - { - bioApplied = false; + bioApplied = PU::isSimpleSymmetricBiPred(pu) && PU::dmvrBdofSizeCheck(pu) && !pu.ciipFlag && !pu.cu->smvdMode; } - if (bioApplied && pu.cu->smvdMode) - { - bioApplied = false; - } - if (pu.cu->cs->sps->getUseBcw() && bioApplied && pu.cu->bcwIdx != BCW_DEFAULT) - { - bioApplied = false; - } if (pu.mmvdEncOptMode == 2 && pu.mmvdMergeFlag) { bioApplied = false; @@ -1533,8 +1477,7 @@ void InterPrediction::motionCompensation(PredictionUnit &pu, PelUnitBuf &predBuf bool refIsScaled = ( refIdx0 < 0 ? false : pu.cu->slice->getRefPic( REF_PIC_LIST_0, refIdx0 )->isRefScaled( pu.cs->pps ) ) || ( refIdx1 < 0 ? false : pu.cu->slice->getRefPic( REF_PIC_LIST_1, refIdx1 )->isRefScaled( pu.cs->pps ) ); bioApplied = refIsScaled ? false : bioApplied; - bool dmvrApplied = false; - dmvrApplied = (pu.mvRefine) && PU::checkDMVRCondition(pu); + bool dmvrApplied = (pu.mvRefine) && PU::checkDMVRCondition(pu); if ((pu.lumaSize().width > MAX_BDOF_APPLICATION_REGION || pu.lumaSize().height > MAX_BDOF_APPLICATION_REGION) && pu.mergeType != MRG_TYPE_SUBPU_ATMVP && (bioApplied && !dmvrApplied)) { xSubPuBio(pu, predBuf, eRefPicList, predBufWOBIO); diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp index d2ee5c5600b2e255cb83477935580ec3e47cf9d8..4f13e73f7d87015e965b0bffc1080ba2b191d3b1 100644 --- a/source/Lib/CommonLib/UnitTools.cpp +++ b/source/Lib/CommonLib/UnitTools.cpp @@ -1679,9 +1679,6 @@ bool PU::checkDMVRCondition(const PredictionUnit& pu) const int refIdx0 = pu.refIdx[REF_PIC_LIST_0]; const int refIdx1 = pu.refIdx[REF_PIC_LIST_1]; - const WPScalingParam *wp0 = pu.cu->slice->getWpScaling(REF_PIC_LIST_0, refIdx0); - const WPScalingParam *wp1 = pu.cu->slice->getWpScaling(REF_PIC_LIST_1, refIdx1); - const bool ref0IsScaled = refIdx0 < 0 || refIdx0 >= MAX_NUM_REF ? false : pu.cu->slice->getRefPic(REF_PIC_LIST_0, refIdx0)->isRefScaled(pu.cs->pps); @@ -1690,9 +1687,8 @@ bool PU::checkDMVRCondition(const PredictionUnit& pu) : pu.cu->slice->getRefPic(REF_PIC_LIST_1, refIdx1)->isRefScaled(pu.cs->pps); return pu.mergeFlag && pu.mergeType == MRG_TYPE_DEFAULT_N && !pu.ciipFlag && !pu.cu->affine && !pu.mmvdMergeFlag - && !pu.cu->mmvdSkip && PU::isBiPredFromDifferentDirEqDistPoc(pu) && (pu.lheight() >= 8) && (pu.lwidth() >= 8) - && ((pu.lheight() * pu.lwidth()) >= 128) && (pu.cu->bcwIdx == BCW_DEFAULT) - && !WPScalingParam::isWeighted(wp0) && !WPScalingParam::isWeighted(wp1) && !ref0IsScaled && !ref1IsScaled; + && !pu.cu->mmvdSkip && PU::isSimpleSymmetricBiPred(pu) && PU::dmvrBdofSizeCheck(pu) && !ref0IsScaled + && !ref1IsScaled; } else { @@ -4159,27 +4155,38 @@ void PU::applyImv( PredictionUnit& pu, MergeCtx &mrgCtx, InterPrediction *interP PU::spanMotionInfo( pu, mrgCtx ); } - -bool PU::isBiPredFromDifferentDirEqDistPoc(const PredictionUnit& pu) +bool PU::isSimpleSymmetricBiPred(const PredictionUnit &pu) { - if (pu.refIdx[0] >= 0 && pu.refIdx[1] >= 0) + const int refIdx0 = pu.refIdx[REF_PIC_LIST_0]; + const int refIdx1 = pu.refIdx[REF_PIC_LIST_1]; + + if (refIdx0 >= 0 && refIdx1 >= 0) { - if (pu.cu->slice->getRefPic(REF_PIC_LIST_0, pu.refIdx[0])->longTerm - || pu.cu->slice->getRefPic(REF_PIC_LIST_1, pu.refIdx[1])->longTerm) + const Slice *slice = pu.cu->slice; + + if (slice->getRefPic(REF_PIC_LIST_0, refIdx0)->longTerm || slice->getRefPic(REF_PIC_LIST_1, refIdx1)->longTerm) { return false; } - const int poc0 = pu.cu->slice->getRefPOC(REF_PIC_LIST_0, pu.refIdx[0]); - const int poc1 = pu.cu->slice->getRefPOC(REF_PIC_LIST_1, pu.refIdx[1]); - const int poc = pu.cu->slice->getPOC(); - if ((poc - poc0)*(poc - poc1) < 0) + + if (pu.cu->bcwIdx != BCW_DEFAULT) { - if (abs(poc - poc0) == abs(poc - poc1)) - { - return true; - } + return false; + } + + if (WPScalingParam::isWeighted(slice->getWpScaling(REF_PIC_LIST_0, refIdx0)) + || WPScalingParam::isWeighted(slice->getWpScaling(REF_PIC_LIST_1, refIdx1))) + { + return false; } + + const int poc0 = slice->getRefPOC(REF_PIC_LIST_0, refIdx0); + const int poc1 = slice->getRefPOC(REF_PIC_LIST_1, refIdx1); + const int poc = slice->getPOC(); + + return poc - poc0 == poc1 - poc; } + return false; } diff --git a/source/Lib/CommonLib/UnitTools.h b/source/Lib/CommonLib/UnitTools.h index 94a64b01747b3af1740ffcb62d5b062e918a47ff..fe3cd6b140db1268f5c2ab67a072154253b8682b 100644 --- a/source/Lib/CommonLib/UnitTools.h +++ b/source/Lib/CommonLib/UnitTools.h @@ -188,7 +188,7 @@ namespace PU void setAllAffineMv ( PredictionUnit &pu, Mv affLT, Mv affRT, Mv affLB, RefPicList eRefList, bool clipCPMVs = false ); bool getInterMergeSubPuMvpCand(const PredictionUnit &pu, MergeCtx &mrgCtx, const int count, int mmvdList); bool getInterMergeSubPuRecurCand(const PredictionUnit &pu, MergeCtx &mrgCtx, const int count); - bool isBiPredFromDifferentDirEqDistPoc(const PredictionUnit &pu); + bool isSimpleSymmetricBiPred(const PredictionUnit &pu); void restrictBiPredMergeCandsOne (PredictionUnit &pu); bool isLMCMode ( unsigned mode); @@ -203,6 +203,10 @@ namespace PU bool checkDMVRCondition(const PredictionUnit& pu); void getNeighborAffineInfo(const PredictionUnit& pu, int& numNeighborAvai, int& numNeighborAffine); + static inline bool dmvrBdofSizeCheck(const PredictionUnit &pu) + { + return pu.lheight() >= 8 && pu.lwidth() >= 8 && pu.lheight() * pu.lwidth() >= 128; + } } // TU tools