From 5e717dab5e0e47c9d9d003b847d5fd9227899eee Mon Sep 17 00:00:00 2001
From: zhangkai <zhangkai.video@bytedance.com>
Date: Tue, 15 Oct 2019 17:36:20 -0700
Subject: [PATCH] JVET-P0385 Unified MV rounding

---
 source/Lib/CommonLib/TypeDef.h     | 2 ++
 source/Lib/CommonLib/UnitTools.cpp | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 56871e4b7..7c9bfb7f9 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -50,6 +50,8 @@
 #include <assert.h>
 #include <cassert>
 
+#define JVET_P0385_UNIFIED_MV_ROUNDING                    1
+
 #define JVET_O0145_ENTRYPOINT_SIGNALLING                  0 // JVET-O0145: Not signalling num_entry_point_offsets but derive it at decoder
 
 #define JVET_O0625_ALF_PADDING                            1 // JVET-O0625/O0654/O0662: Unified padding method in ALF
diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp
index c62d8b7bd..237a2c34b 100755
--- a/source/Lib/CommonLib/UnitTools.cpp
+++ b/source/Lib/CommonLib/UnitTools.cpp
@@ -2843,7 +2843,9 @@ bool PU::getInterMergeSubPuMvpCand(const PredictionUnit &pu, MergeCtx& mrgCtx, b
   ///////////////////////////////////////////////////////////////////////
   ////////          GET Initial Temporal Vector                  ////////
   ///////////////////////////////////////////////////////////////////////
+#if !JVET_P0385_UNIFIED_MV_ROUNDING
   int mvPrec = MV_FRACTIONAL_BITS_INTERNAL;
+#endif
 
   Mv cTempVector = cTMv;
   bool  tempLICFlag = false;
@@ -2865,8 +2867,15 @@ bool PU::getInterMergeSubPuMvpCand(const PredictionUnit &pu, MergeCtx& mrgCtx, b
 
   bool found = false;
   cTempVector = cTMv;
+
+#if JVET_P0385_UNIFIED_MV_ROUNDING
+  cTempVector.changePrecision(MV_PRECISION_SIXTEENTH, MV_PRECISION_INT);
+  int tempX = cTempVector.getHor();
+  int tempY = cTempVector.getVer();
+#else
   int tempX = cTempVector.getHor() >> mvPrec;
   int tempY = cTempVector.getVer() >> mvPrec;
+#endif
 
   centerPos.x = puPos.x + (puSize.width >> 1) + tempX;
   centerPos.y = puPos.y + (puSize.height >> 1) + tempY;
-- 
GitLab