From a0df5f619e5edaa6115bf1c805b3d6601c8696c5 Mon Sep 17 00:00:00 2001
From: Moonmo Koo <moonmo.koo@lge.com>
Date: Tue, 30 Apr 2024 15:46:10 +0000
Subject: [PATCH] JVET-AH0101 (EE2-4.2: Fix on LFNST/NSPT index signalling for
 inter coding)

---
 source/Lib/DecoderLib/CABACReader.cpp | 7 +++----
 source/Lib/EncoderLib/CABACWriter.cpp | 7 +++----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/source/Lib/DecoderLib/CABACReader.cpp b/source/Lib/DecoderLib/CABACReader.cpp
index c394fb3f0..330d73b10 100644
--- a/source/Lib/DecoderLib/CABACReader.cpp
+++ b/source/Lib/DecoderLib/CABACReader.cpp
@@ -8532,13 +8532,12 @@ void CABACReader::residual_coding( TransformUnit& tu, ComponentID compID, CUCtx&
   if( tu.mtsIdx[compID] != MTS_SKIP && tu.blocks[compID].height >= 4 && tu.blocks[compID].width >= 4 )
   {
 #if JVET_AG0061_INTER_LFNST_NSPT
-    const int lfnstLastScanPosTh = CU::isIntra(*(tu.cu))
-                                     ? (isLuma(compID) ? LFNST_LAST_SIG_LUMA : LFNST_LAST_SIG_CHROMA)
-                                     : (isLuma(compID) ? LFNST_LAST_SIG_LUMA_INTER : LFNST_LAST_SIG_CHROMA_INTER);
+    const int lfnstLastScanPosTh = isLuma( compID ) ? ( CU::isIntra( *( tu.cu ) ) ? LFNST_LAST_SIG_LUMA : LFNST_LAST_SIG_LUMA_INTER ) : LFNST_LAST_SIG_CHROMA;
+    cuCtx.lfnstLastScanPos |= ( CU::isIntra( *( tu.cu ) ) || isLuma( compID ) ) ? ( cctx.scanPosLast() >= lfnstLastScanPosTh ) : false;
 #else
     const int lfnstLastScanPosTh = isLuma( compID ) ? LFNST_LAST_SIG_LUMA : LFNST_LAST_SIG_CHROMA;
-#endif
     cuCtx.lfnstLastScanPos |= cctx.scanPosLast() >= lfnstLastScanPosTh;
+#endif
   }
   if (isLuma(compID) && tu.mtsIdx[compID] != MTS_SKIP)
   {
diff --git a/source/Lib/EncoderLib/CABACWriter.cpp b/source/Lib/EncoderLib/CABACWriter.cpp
index f29cb4a1f..edace2007 100644
--- a/source/Lib/EncoderLib/CABACWriter.cpp
+++ b/source/Lib/EncoderLib/CABACWriter.cpp
@@ -8204,13 +8204,12 @@ void CABACWriter::residual_coding( const TransformUnit& tu, ComponentID compID,
     if (cuCtx && tu.mtsIdx[compID] != MTS_SKIP && tu.blocks[compID].height >= 4 && tu.blocks[compID].width >= 4)
     {
 #if JVET_AG0061_INTER_LFNST_NSPT
-      const int lfnstLastScanPosTh = CU::isIntra(*(tu.cu))
-                                       ? (isLuma(compID) ? LFNST_LAST_SIG_LUMA : LFNST_LAST_SIG_CHROMA)
-                                       : (isLuma(compID) ? LFNST_LAST_SIG_LUMA_INTER : LFNST_LAST_SIG_CHROMA_INTER);
+      const int lfnstLastScanPosTh = isLuma( compID ) ? ( CU::isIntra( *( tu.cu ) ) ? LFNST_LAST_SIG_LUMA : LFNST_LAST_SIG_LUMA_INTER ) : LFNST_LAST_SIG_CHROMA;
+      cuCtx->lfnstLastScanPos |= ( CU::isIntra( *( tu.cu ) ) || isLuma( compID ) ) ? ( cctx.scanPosLast() >= lfnstLastScanPosTh ) : false;
 #else
       const int lfnstLastScanPosTh = isLuma(compID) ? LFNST_LAST_SIG_LUMA : LFNST_LAST_SIG_CHROMA;
-#endif
       cuCtx->lfnstLastScanPos |= cctx.scanPosLast() >= lfnstLastScanPosTh;
+#endif
     }
     if (cuCtx && isLuma(compID) && tu.mtsIdx[compID] != MTS_SKIP)
     {
-- 
GitLab