diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp index f50a64c3002f4e6ac38cf805275b501d0073ab63..91561e4328571cafba8c4d9631bb14e47b576977 100644 --- a/source/Lib/CommonLib/InterPrediction.cpp +++ b/source/Lib/CommonLib/InterPrediction.cpp @@ -77,7 +77,7 @@ InterPrediction::InterPrediction() #if INTER_LIC || (TM_AMVP || TM_MRG) // note: already refactor m_pcReshape ( nullptr ), #endif -#if INTER_LIC +#if INTER_LIC || JVET_Y0067_ENHANCED_MMVD_MVD_SIGN_PRED m_pcLICRefLeftTemplate ( nullptr ), m_pcLICRefAboveTemplate( nullptr ), m_pcLICRecLeftTemplate ( nullptr ), @@ -360,7 +360,7 @@ void InterPrediction::destroy() xFree(m_pcRefTplLeft ); m_pcRefTplLeft = nullptr; xFree(m_pcRefTplAbove); m_pcRefTplAbove = nullptr; #endif -#if INTER_LIC +#if INTER_LIC || JVET_Y0067_ENHANCED_MMVD_MVD_SIGN_PRED xFree(m_pcLICRefLeftTemplate); m_pcLICRefLeftTemplate = nullptr; xFree(m_pcLICRefAboveTemplate); m_pcLICRefAboveTemplate = nullptr; xFree(m_pcLICRecLeftTemplate); m_pcLICRecLeftTemplate = nullptr; @@ -542,7 +542,7 @@ void InterPrediction::init( RdCost* pcRdCost, ChromaFormat chromaFormatIDC, cons m_pcRefTplAbove = (Pel*)xMalloc(Pel, TM_TPL_SIZE * MAX_CU_SIZE); } #endif -#if INTER_LIC +#if INTER_LIC || JVET_Y0067_ENHANCED_MMVD_MVD_SIGN_PRED if (m_pcLICRefLeftTemplate == nullptr) { m_pcLICRefLeftTemplate = (Pel*)xMalloc(Pel, MAX_CU_SIZE); @@ -5788,8 +5788,10 @@ void InterPrediction::sortAffineMergeCandidates(PredictionUnit pu, AffineMergeC pu.afMmvdStep = (uint8_t)stepIdx; pu.mergeIdx = (uint8_t)(baseIdxToMergeIdxOffset + baseIdx); pu.mergeType = affMrgCtx.mergeType[pu.mergeIdx]; +#if INTER_LIC pu.cu->LICFlag = affMrgCtx.LICFlags[pu.mergeIdx]; pu.cu->LICFlag = false; +#endif pu.interDir = affMrgCtx.interDirNeighbours[pu.mergeIdx]; pu.cu->affineType = affMrgCtx.affineType[pu.mergeIdx]; pu.cu->BcwIdx = affMrgCtx.BcwIdx[pu.mergeIdx]; @@ -12603,17 +12605,20 @@ void InterPrediction::deriveMVDcandAffine(const PredictionUnit& pu, RefPicList e } #endif } + + void InterPrediction::deriveMvdSignAffine(const Mv& cMvPred, const Mv& cMvPred2, const Mv& cMvPred3, #if JVET_Z0054_BLK_REF_PIC_REORDER - void InterPrediction::deriveMvdSignAffine(const Mv& cMvPred, const Mv& cMvPred2, const Mv& cMvPred3, const Mv cMvdKnownAtDecoder[3], - PredictionUnit& pu, RefPicList eRefList, int refIdx, std::vector<Mv>& cMvdDerived, std::vector<Mv>& cMvdDerived2, std::vector<Mv>& cMvdDerived3) + const Mv cMvdKnownAtDecoder[3], +#else + const Mv& cMvdKnownAtDecoder, const Mv& cMvdKnownAtDecoder2, const Mv& cMvdKnownAtDecoder3, +#endif + PredictionUnit& pu, RefPicList eRefList, int refIdx, std::vector<Mv>& cMvdDerived, std::vector<Mv>& cMvdDerived2, std::vector<Mv>& cMvdDerived3) { +#if JVET_Z0054_BLK_REF_PIC_REORDER std::vector<Mv> MvdCand[3]; deriveMVDcandAffine(pu, eRefList, MvdCand); size_t patternsNum = MvdCand[0].size(); #else - void InterPrediction::deriveMvdSignAffine(const Mv& cMvPred, const Mv& cMvPred2, const Mv& cMvPred3, const Mv& cMvdKnownAtDecoder, const Mv& cMvdKnownAtDecoder2, const Mv& cMvdKnownAtDecoder3, - PredictionUnit& pu, RefPicList eRefList, int refIdx, std::vector<Mv>& cMvdDerived, std::vector<Mv>& cMvdDerived2, std::vector<Mv>& cMvdDerived3) - { int patterns2[2][1] = { { +1 }, diff --git a/source/Lib/CommonLib/InterPrediction.h b/source/Lib/CommonLib/InterPrediction.h index 51463ee26f3b0a837006bb08fc2b4b7708df926a..02dcd8e736f4d037d7156adb1adc6b0f8a43f49c 100644 --- a/source/Lib/CommonLib/InterPrediction.h +++ b/source/Lib/CommonLib/InterPrediction.h @@ -87,7 +87,9 @@ private: static const int m_LICRegShift = 7; static const int m_LICShiftDiff = 12; int m_LICMultApprox[64]; +#endif +#if INTER_LIC || JVET_Y0067_ENHANCED_MMVD_MVD_SIGN_PRED // buffer size for left/above current templates and left/above reference templates Pel* m_pcLICRefLeftTemplate; Pel* m_pcLICRefAboveTemplate; @@ -509,12 +511,13 @@ public: int deriveMVSDIdxFromMVDTrans(Mv cMvd, std::vector<Mv>& cMvdDerived); Mv deriveMVDFromMVSDIdxTrans(int mvsdIdx, std::vector<Mv>& cMvdDerived); void deriveMvdSignSMVD(const Mv& cMvPred, const Mv& cMvPred2, const Mv& cMvdKnownAtDecoder, PredictionUnit& pu, std::vector<Mv>& cMvdDerived); + void deriveMvdSignAffine(const Mv& cMvPred, const Mv& cMvPred2, const Mv& cMvPred3, #if JVET_Z0054_BLK_REF_PIC_REORDER - void deriveMvdSignAffine(const Mv& cMvPred, const Mv& cMvPred2, const Mv& cMvPred3, const Mv cMvdKnownAtDecoder[3], + const Mv cMvdKnownAtDecoder[3], #else - void deriveMvdSignAffine(const Mv& cMvPred, const Mv& cMvPred2, const Mv& cMvPred3, const Mv& cMvdKnownAtDecoder, const Mv& cMvdKnownAtDecoder2, const Mv& cMvdKnownAtDecoder3, + const Mv& cMvdKnownAtDecoder, const Mv& cMvdKnownAtDecoder2, const Mv& cMvdKnownAtDecoder3, #endif - PredictionUnit& pu, RefPicList eRefList, int refIdx, std::vector<Mv>& cMvdDerived, std::vector<Mv>& cMvdDerived2, std::vector<Mv>& cMvdDerived3); + PredictionUnit& pu, RefPicList eRefList, int refIdx, std::vector<Mv>& cMvdDerived, std::vector<Mv>& cMvdDerived2, std::vector<Mv>& cMvdDerived3); Distortion xGetSublkTemplateCost(const CodingUnit& cu, const ComponentID compID, const Picture& refPic, const Mv& mv, const int sublkWidth, const int sublkHeight, const int posW, const int posH, int* numTemplate, Pel* refLeftTemplate, Pel* refAboveTemplate, Pel* recLeftTemplate, Pel* recAboveTemplate); int deriveMVSDIdxFromMVDAffine(PredictionUnit& pu, RefPicList eRefList, std::vector<Mv>& cMvdDerived, std::vector<Mv>& cMvdDerived2, std::vector<Mv>& cMvdDerived3); diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp index 9653b0c9d20b3f9ab2a3c418fa0a499fba4ee181..2802a051731accaaf5a3b9724823e40f4bf4c3ef 100644 --- a/source/Lib/CommonLib/UnitTools.cpp +++ b/source/Lib/CommonLib/UnitTools.cpp @@ -6737,7 +6737,7 @@ void PU::xGetAffineMvFromLUT(short affineParameters[4], int rParameters[4]) } -// Add afffine candidates from LUT +// Add affine candidates from LUT // return true to early terminate bool PU::checkLastAffineMergeCandRedundancy(const PredictionUnit& pu, AffineMergeCtx& affMrgCtx) @@ -6776,10 +6776,12 @@ bool PU::checkLastAffineMergeCandRedundancy(const PredictionUnit& pu, AffineMerg { continue; } +#if INTER_LIC if (affMrgCtx.interDirNeighbours[idx] != 3 && affMrgCtx.LICFlags[idx] != affMrgCtx.LICFlags[lastIdx]) { continue; } +#endif if ((affMrgCtx.interDirNeighbours[lastIdx] & 1) != 0) { @@ -6980,7 +6982,9 @@ bool PU::addMergeHMVPCandFromAffModel(const PredictionUnit& pu, MergeCtx& mrgCtx mrgCtx.mvFieldNeighbours[(cnt << 1) + 0].setMvField(Mv(), -1); mrgCtx.mvFieldNeighbours[(cnt << 1) + 1].setMvField(Mv(), -1); mrgCtx.BcwIdx[cnt] = BCW_DEFAULT; +#if INTER_LIC mrgCtx.LICFlags[cnt] = false; +#endif continue; } #endif @@ -7032,7 +7036,9 @@ bool PU::addMergeHMVPCandFromAffModel(const PredictionUnit& pu, MergeCtx& mrgCtx mrgCtx.mvFieldNeighbours[(cnt << 1) + 0].setMvField(Mv(), -1); mrgCtx.mvFieldNeighbours[(cnt << 1) + 1].setMvField(Mv(), -1); mrgCtx.BcwIdx[cnt] = BCW_DEFAULT; +#if INTER_LIC mrgCtx.LICFlags[cnt] = false; +#endif continue; } #endif @@ -7072,7 +7078,9 @@ bool PU::addOneMergeHMVPCandFromAffModel(const PredictionUnit& pu, MergeCtx& mrg int HistParameters[2][4]; mrgCtx.interDirNeighbours[cnt] = 0; mrgCtx.BcwIdx[cnt] = BCW_DEFAULT; +#if INTER_LIC mrgCtx.LICFlags[cnt] = false; +#endif mrgCtx.mvFieldNeighbours[(cnt << 1) + 0].setMvField(Mv(), -1); mrgCtx.mvFieldNeighbours[(cnt << 1) + 1].setMvField(Mv(), -1); @@ -7116,7 +7124,9 @@ bool PU::addOneMergeHMVPCandFromAffModel(const PredictionUnit& pu, MergeCtx& mrg if (mrgCtx.interDirNeighbours[cnt] == 0) { mrgCtx.BcwIdx [cnt] = BCW_DEFAULT; +#if INTER_LIC mrgCtx.LICFlags[cnt] = false; +#endif mrgCtx.mvFieldNeighbours[(cnt << 1) + 0].setMvField(Mv(), -1); mrgCtx.mvFieldNeighbours[(cnt << 1) + 1].setMvField(Mv(), -1); return false; @@ -7137,7 +7147,9 @@ bool PU::addOneMergeHMVPCandFromAffModel(const PredictionUnit& pu, MergeCtx& mrg { mrgCtx.interDirNeighbours[cnt] = 0; mrgCtx.BcwIdx[cnt] = BCW_DEFAULT; +#if INTER_LIC mrgCtx.LICFlags[cnt] = false; +#endif mrgCtx.mvFieldNeighbours[(cnt << 1) + 0].setMvField(Mv(), -1); mrgCtx.mvFieldNeighbours[(cnt << 1) + 1].setMvField(Mv(), -1); return false; @@ -7146,7 +7158,11 @@ bool PU::addOneMergeHMVPCandFromAffModel(const PredictionUnit& pu, MergeCtx& mrg return true; } -bool PU::addOneAffineMergeHMVPCand(const PredictionUnit & pu, AffineMergeCtx & affMrgCtx, static_vector<AffineMotionInfo, MAX_NUM_AFF_HMVP_CANDS>* lutAff, int listIdx, const MotionInfo & mvInfo, Position neiPosition, int iGBiIdx, bool bICflag) +bool PU::addOneAffineMergeHMVPCand(const PredictionUnit & pu, AffineMergeCtx & affMrgCtx, static_vector<AffineMotionInfo, MAX_NUM_AFF_HMVP_CANDS>* lutAff, int listIdx, const MotionInfo & mvInfo, Position neiPosition, int iGBiIdx +#if INTER_LIC + , bool bICflag +#endif +) { Mv cMv[2][3]; int aiHistParameters[2][4]; @@ -7297,7 +7313,11 @@ bool PU::addSpatialAffineMergeHMVPCand(const PredictionUnit& pu, AffineMergeCtx& { continue; } - if (addOneAffineMergeHMVPCand(pu, affMrgCtx, lutAff, affHMVPIdx, mvInfo, neiPositions[nei], puNei->interDir == 3? puNei->cu->BcwIdx : BCW_DEFAULT, puNei->cu->LICFlag)) + if (addOneAffineMergeHMVPCand(pu, affMrgCtx, lutAff, affHMVPIdx, mvInfo, neiPositions[nei], puNei->interDir == 3? puNei->cu->BcwIdx : BCW_DEFAULT +#if INTER_LIC + , puNei->cu->LICFlag +#endif + )) { if (affMrgCtx.numValidMergeCand == mrgCandIdx) // for decoder { @@ -9383,11 +9403,17 @@ void PU::getAffineMergeCand( const PredictionUnit &pu, AffineMergeCtx& affMrgCtx if (isTmvpAvailable) { Position posRB = pu.Y().bottomRight().offset(3, 3); + if (addOneAffineMergeHMVPCand(pu, affMrgCtx #if JVET_Z0118_GDR - if (addOneAffineMergeHMVPCand(pu, affMrgCtx, (isClean) ? pu.cs->motionLut.lutAff1 : pu.cs->motionLut.lutAff0, 0, tmvpInfo, posRB, BCW_DEFAULT, false)) + , (isClean) ? pu.cs->motionLut.lutAff1 : pu.cs->motionLut.lutAff0 #else - if (addOneAffineMergeHMVPCand(pu, affMrgCtx, pu.cs->motionLut.lutAff, 0, tmvpInfo, posRB, BCW_DEFAULT, false)) + , pu.cs->motionLut.lutAff #endif + , 0, tmvpInfo, posRB, BCW_DEFAULT +#if INTER_LIC + , false +#endif + )) { if (affMrgCtx.numValidMergeCand == mrgCandIdx) // for decoder { @@ -9417,11 +9443,17 @@ void PU::getAffineMergeCand( const PredictionUnit &pu, AffineMergeCtx& affMrgCtx if (isTmvpAvailable) { Position posRB = pu.Y().bottomRight().offset(3, 3); + if (addOneAffineMergeHMVPCand(pu, affMrgCtx #if JVET_Z0118_GDR - if (addOneAffineMergeHMVPCand(pu, affMrgCtx, (isClean) ? pu.cs->motionLut.lutAff1 : pu.cs->motionLut.lutAff0, iAffListIdx, tmvpInfo, posRB, BCW_DEFAULT, false)) + , (isClean) ? pu.cs->motionLut.lutAff1 : pu.cs->motionLut.lutAff0 #else - if (addOneAffineMergeHMVPCand(pu, affMrgCtx, pu.cs->motionLut.lutAff, iAffListIdx, tmvpInfo, posRB, BCW_DEFAULT, false)) + , pu.cs->motionLut.lutAff #endif + , iAffListIdx, tmvpInfo, posRB, BCW_DEFAULT +#if INTER_LIC + , false +#endif + )) { if (affMrgCtx.numValidMergeCand == mrgCandIdx) // for decoder { diff --git a/source/Lib/CommonLib/UnitTools.h b/source/Lib/CommonLib/UnitTools.h index 8d312422768af296b97fcb39abdeba4a23129473..aff0bd881fe830d8874ea583bb671087995a1afe 100644 --- a/source/Lib/CommonLib/UnitTools.h +++ b/source/Lib/CommonLib/UnitTools.h @@ -258,7 +258,11 @@ namespace PU void xGetAffineMvFromLUT(AffineMotionInfo* affHistInfo, int rParameters[4]); bool checkLastAffineMergeCandRedundancy(const PredictionUnit& pu, AffineMergeCtx& affMrgCtx); - bool addOneAffineMergeHMVPCand(const PredictionUnit& pu, AffineMergeCtx& affMrgCtx, static_vector<AffineMotionInfo, MAX_NUM_AFF_HMVP_CANDS>* lutAff, int affHMVPIdx, const MotionInfo& mvInfo, Position neiPosition, int iGBiIdx, bool bICflag); + bool addOneAffineMergeHMVPCand(const PredictionUnit& pu, AffineMergeCtx& affMrgCtx, static_vector<AffineMotionInfo, MAX_NUM_AFF_HMVP_CANDS>* lutAff, int affHMVPIdx, const MotionInfo& mvInfo, Position neiPosition, int iGBiIdx +#if INTER_LIC + , bool bICflag +#endif + ); bool addSpatialAffineMergeHMVPCand(const PredictionUnit& pu, AffineMergeCtx& affMrgCtx, static_vector<AffineMotionInfo, MAX_NUM_AFF_HMVP_CANDS>* lutAff, int affHMVPIdx, const PredictionUnit* neiPUs[], Position neiPositions[], int iNeiNum, const int mrgCandIdx = -1); bool addSpatialAffineAMVPHMVPCand(PredictionUnit& pu, const RefPicList& eRefPicList, const int& refIdx, AffineAMVPInfo& affiAMVPInfo, static_vector<AffineMotionInfo, MAX_NUM_AFF_HMVP_CANDS>* lutAff, int iHMVPlistIdx, int neiIdx[], int iNeiNum, int aiNeibeInherited[], bool bFoundOne);