From 988f9d1ebc0a2c12c4b60d0439362efd7d42ba0b Mon Sep 17 00:00:00 2001
From: Brian Heng <brian.heng@broadcom.com>
Date: Fri, 13 Dec 2019 18:13:00 -0800
Subject: [PATCH] Fix for previous fix of Ticket #536 - Wraparound failed due
 to clipMv

- Prevent use of clipMv( ) on decoder side when wraparound is enabled.
---
 source/Lib/CommonLib/InterPrediction.cpp | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp
index 1cf774200..a5a8257f9 100644
--- a/source/Lib/CommonLib/InterPrediction.cpp
+++ b/source/Lib/CommonLib/InterPrediction.cpp
@@ -493,7 +493,10 @@ void InterPrediction::xPredInterUni(const PredictionUnit& pu, const RefPicList&
   {
     if( pu.cu->slice->getScalingRatio( eRefPicList, iRefIdx ) == SCALE_1X )
     {
-      clipMv( mv[0], pu.cu->lumaPos(), pu.cu->lumaSize(), sps, *pu.cs->pps );
+      if( !sps.getWrapAroundEnabledFlag() )
+      {
+        clipMv( mv[0], pu.cu->lumaPos(), pu.cu->lumaSize(), sps, *pu.cs->pps );
+      }
     }
   }
 
@@ -2271,7 +2274,10 @@ void InterPrediction::xFinalPaddedMCForDMVR(PredictionUnit& pu, PelUnitBuf &pcYu
     m_iRefListIdx = refId;
     const Picture* refPic = pu.cu->slice->getRefPic( refId, pu.refIdx[refId] )->unscaledPic;
     Mv cMvClipped = cMv;
-    clipMv( cMvClipped, pu.lumaPos(), pu.lumaSize(), *pu.cs->sps, *pu.cs->pps );
+    if( !pu.cs->sps->getWrapAroundEnabledFlag() ) 
+    {
+      clipMv( cMvClipped, pu.lumaPos(), pu.lumaSize(), *pu.cs->sps, *pu.cs->pps );
+    }
 
     Mv startMv = mergeMV[refId];
 
@@ -2362,8 +2368,11 @@ void InterPrediction::xinitMC(PredictionUnit& pu, const ClpRngs &clpRngs)
   Mv mergeMVL1(pu.mv[REF_PIC_LIST_1]);
 
   /*Clip the starting MVs*/
-  clipMv( mergeMVL0, pu.lumaPos(), pu.lumaSize(), *pu.cs->sps, *pu.cs->pps );
-  clipMv( mergeMVL1, pu.lumaPos(), pu.lumaSize(), *pu.cs->sps, *pu.cs->pps );
+  if( !pu.cs->sps->getWrapAroundEnabledFlag() )
+  {
+    clipMv( mergeMVL0, pu.lumaPos(), pu.lumaSize(), *pu.cs->sps, *pu.cs->pps );
+    clipMv( mergeMVL1, pu.lumaPos(), pu.lumaSize(), *pu.cs->sps, *pu.cs->pps );
+  }
 
   /*L0 MC for refinement*/
   {
-- 
GitLab