From 099c47e44697fb7af34a67f8566abc4d5253121b Mon Sep 17 00:00:00 2001
From: Yu Han <yuhan@qti.qualcomm.com>
Date: Wed, 20 Feb 2019 16:26:03 -0800
Subject: [PATCH] Ticket 193 fix, consider HMVP for IBC mode sharing list

---
 source/Lib/CommonLib/Slice.h       |  3 +++
 source/Lib/CommonLib/UnitTools.cpp | 12 ++++++++----
 source/Lib/DecoderLib/DecCu.cpp    |  2 +-
 source/Lib/EncoderLib/EncCu.cpp    |  4 ++++
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h
index b7a8084d0..d5fbebce5 100644
--- a/source/Lib/CommonLib/Slice.h
+++ b/source/Lib/CommonLib/Slice.h
@@ -2029,6 +2029,9 @@ public:
 #if JVET_M0170_MRG_SHARELIST
   int                         getAvailableLUTBkupMrgNum() const  { return m_MotionCandLuTsBkup->currCnt; }
   MotionInfo                  getMotionInfoFromLUTBkup(int MotCandIdx) const;
+#if JVET_M0483_IBC
+  int                         getAvailableLUTBkupIBCMrgNum() const { return m_MotionCandLuTsBkup->currCntIBC; }
+#endif
 #endif
   MotionInfo                  getMotionInfoFromLUTs(int MotCandIdx) const;
   LutMotionCand*              getMotionLUTs() { return m_MotionCandLut; }
diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp
index 163ea9a6d..2960320ce 100644
--- a/source/Lib/CommonLib/UnitTools.cpp
+++ b/source/Lib/CommonLib/UnitTools.cpp
@@ -1042,7 +1042,7 @@ bool PU::addMergeHMVPCand(const Slice &slice, MergeCtx& mrgCtx, bool isCandInter
   }
 #if JVET_M0170_MRG_SHARELIST
 #if JVET_M0483_IBC
-  int num_avai_candInLUT = ibcFlag ? slice.getAvailableLUTIBCMrgNum() : (isShared ? slice.getAvailableLUTBkupMrgNum() : slice.getAvailableLUTMrgNum());
+  int num_avai_candInLUT = ibcFlag ? (isShared ? slice.getAvailableLUTBkupIBCMrgNum() : slice.getAvailableLUTIBCMrgNum()) : (isShared ? slice.getAvailableLUTBkupMrgNum() : slice.getAvailableLUTMrgNum());
   int offset = ibcFlag ? MAX_NUM_HMVP_CANDS : 0;
 #else
   int num_avai_candInLUT = (isShared ? slice.getAvailableLUTBkupMrgNum() : slice.getAvailableLUTMrgNum());
@@ -1060,8 +1060,8 @@ bool PU::addMergeHMVPCand(const Slice &slice, MergeCtx& mrgCtx, bool isCandInter
   {
 #if JVET_M0170_MRG_SHARELIST
 #if JVET_M0483_IBC
-    miNeighbor = ibcFlag ? slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx + offset)
-                          : (isShared ? slice.getMotionInfoFromLUTBkup(num_avai_candInLUT - mrgIdx) : slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx));
+    miNeighbor = ibcFlag ? (isShared ? slice.getMotionInfoFromLUTBkup(num_avai_candInLUT - mrgIdx + offset) : slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx + offset))
+      : (isShared ? slice.getMotionInfoFromLUTBkup(num_avai_candInLUT - mrgIdx) : slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx));
 #else
     miNeighbor = isShared ? slice.getMotionInfoFromLUTBkup(num_avai_candInLUT - mrgIdx) : slice.getMotionInfoFromLUTs(num_avai_candInLUT - mrgIdx);
 #endif
@@ -1306,6 +1306,10 @@ void PU::getIBCMergeCandidates(const PredictionUnit &pu, MergeCtx& mrgCtx, const
     bool isAvailableSubPu = false;
     unsigned subPuMvpPos = 0;
 
+#if JVET_M0170_MRG_SHARELIST
+    bool  isShared = ((pu.Y().lumaSize().width != pu.shareParentSize.width) || (pu.Y().lumaSize().height != pu.shareParentSize.height));
+#endif
+
 #if JVET_L0090_PAIR_AVG
     bool bFound = addMergeHMVPCand(slice, mrgCtx, canFastExit
       , mrgCandIdx
@@ -1320,7 +1324,7 @@ void PU::getIBCMergeCandidates(const PredictionUnit &pu, MergeCtx& mrgCtx, const
       , true
 #endif
 #if JVET_M0170_MRG_SHARELIST
-      , false
+      , isShared
 #endif
     );
 #else
diff --git a/source/Lib/DecoderLib/DecCu.cpp b/source/Lib/DecoderLib/DecCu.cpp
index dadcae512..cd3f1cc8a 100644
--- a/source/Lib/DecoderLib/DecCu.cpp
+++ b/source/Lib/DecoderLib/DecCu.cpp
@@ -112,7 +112,7 @@ void DecCu::decompressCtu( CodingStructure& cs, const UnitArea& ctuArea )
   {
     m_shareStateDec = NO_SHARE;
   }
-  bool sharePrepareCondition = ((!cs.pcv->isEncoder) && (!(cs.slice->isIntra())));
+  bool sharePrepareCondition = ((!cs.pcv->isEncoder) && (!(cs.slice->isIntra()) || cs.slice->getSPS()->getIBCFlag()));
 #endif
 
   for( int ch = 0; ch < maxNumChannelType; ch++ )
diff --git a/source/Lib/EncoderLib/EncCu.cpp b/source/Lib/EncoderLib/EncCu.cpp
index 6f461e435..59a1477a4 100644
--- a/source/Lib/EncoderLib/EncCu.cpp
+++ b/source/Lib/EncoderLib/EncCu.cpp
@@ -1267,7 +1267,11 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
   }
 
 #if JVET_M0170_MRG_SHARELIST
+#if JVET_M0483_IBC
+  if ((!slice.isIntra() || slice.getSPS()->getIBCFlag())
+#else
   if (!slice.isIntra()
+#endif
     && tempCS->chType == CHANNEL_TYPE_LUMA
     )
   {
-- 
GitLab