From d90231479e557f0efedd8cebda0864098f7bc9a3 Mon Sep 17 00:00:00 2001
From: Shunsuke Iwamura <iwamura.s-gc@nhk.or.jp>
Date: Thu, 7 May 2020 08:31:35 +0900
Subject: [PATCH] JVET-R0130: Bugfix for tC derivation used in chroma
 deblocking filter.

---
 source/Lib/CommonLib/LoopFilter.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/source/Lib/CommonLib/LoopFilter.cpp b/source/Lib/CommonLib/LoopFilter.cpp
index 3fae400bb1..b501f2e3c9 100644
--- a/source/Lib/CommonLib/LoopFilter.cpp
+++ b/source/Lib/CommonLib/LoopFilter.cpp
@@ -1305,7 +1305,12 @@ void LoopFilter::xEdgeFilterChroma(const CodingUnit& cu, const DeblockEdgeDir ed
 
 
         const int iIndexTC = Clip3<int>(0, MAX_QP + DEFAULT_INTRA_TC_OFFSET, iQP + DEFAULT_INTRA_TC_OFFSET * (bS[chromaIdx] - 1) + (tcOffsetDiv2[chromaIdx] << 1));
+#if JVET_R0130_TC_DERIVATION_BUGFIX
+        const int roundOffset = 1 << (sps.getBitDepth(CHANNEL_TYPE_CHROMA) - 1);
+        const int iTc = sps.getBitDepth(CHANNEL_TYPE_CHROMA) < 10 ? ((sm_tcTable[iIndexTC] + roundOffset) >> (10 - sps.getBitDepth(CHANNEL_TYPE_CHROMA))) : ((sm_tcTable[iIndexTC]) << (sps.getBitDepth(CHANNEL_TYPE_CHROMA) - 10));
+#else
         const int iTc = sps.getBitDepth(CHANNEL_TYPE_CHROMA) < 10 ? ((sm_tcTable[iIndexTC] + 2) >> (10 - sps.getBitDepth(CHANNEL_TYPE_CHROMA))) : ((sm_tcTable[iIndexTC]) << (sps.getBitDepth(CHANNEL_TYPE_CHROMA) - 10));
+#endif
         bool useLongFilter = false;
         if (largeBoundary)
         {
-- 
GitLab