From 3b6edd8314d4894a7a093806837a5c106bff853d Mon Sep 17 00:00:00 2001
From: Yan Zhang <yzh@qti.qualcomm.com>
Date: Mon, 29 Oct 2018 21:58:51 +0100
Subject: [PATCH] JVET-L0377 AMVR Rounding Align

---
 source/Lib/CommonLib/Mv.cpp    | 6 +++++-
 source/Lib/CommonLib/TypeDef.h | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/source/Lib/CommonLib/Mv.cpp b/source/Lib/CommonLib/Mv.cpp
index 17d677d8..6e91ad38 100644
--- a/source/Lib/CommonLib/Mv.cpp
+++ b/source/Lib/CommonLib/Mv.cpp
@@ -47,9 +47,13 @@ void roundMV( Mv & rMV, unsigned imvShift )
   if (rMV.highPrec) imvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
 #endif
   int offset = 1 << ( imvShift - 1 );
-
+#if JVET_L0377_AMVR_ROUNDING_ALIGN
+  rMV.setHor(rMV.getHor() >= 0 ? ((rMV.getHor() + offset) >> imvShift) << imvShift : -(((-rMV.getHor() + offset) >> imvShift)) << imvShift);
+  rMV.setVer(rMV.getVer() >= 0 ? ((rMV.getVer() + offset) >> imvShift) << imvShift : -(((-rMV.getVer() + offset) >> imvShift)) << imvShift);
+#else
   rMV.setHor( ( ( rMV.getHor() + offset ) >> imvShift ) << imvShift );
   rMV.setVer( ( ( rMV.getVer() + offset ) >> imvShift ) << imvShift );
+#endif
 }
 
 void roundAffineMv( int& mvx, int& mvy, int nShift )
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 472b3428..bc7565f6 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -50,6 +50,8 @@
 #include <assert.h>
 #include <cassert>
 
+#define JVET_L0377_AMVR_ROUNDING_ALIGN                    1 // Align AMVR rounding for AMVP candidate
+
 #define JVET_L0285_8BIT_TRANSFORM_CORE                    1 // Primary transform using 8-bit cores
 
 #define JVET_L0081_VPDU_SPLIT_CONSTRAINTS                 1 // VPDU constraints for binary and ternary partitions
-- 
GitLab