From 90f3f5f6f16c19dcd690f06ca5f4b7f792391a5f Mon Sep 17 00:00:00 2001
From: Remy Foray <remy.foray@allegrodvt.com>
Date: Fri, 24 May 2019 10:41:16 +0200
Subject: [PATCH] Fix alf_ctb_flag parsing for chroma
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

According to specification, alf_ctb_flag is parsed for Cb when (slice_alf_chroma_idc = 1 or slice_alf_chroma_idc = 3), and for Cr when (slice_alf_chroma_idc = 2 or slice_alf_chroma_idc = 3).
---
 source/Lib/DecoderLib/VLCReader.cpp | 4 ++--
 source/Lib/EncoderLib/VLCWriter.cpp | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 49953a9df8..081f4c851e 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -1954,8 +1954,8 @@ void HLSyntaxReader::parseSliceHeader (Slice* pcSlice, ParameterSetManager *para
       {
         pcSlice->setTileGroupNumAps(0);
       }
-      pcSlice->setTileGroupAlfEnabledFlag(COMPONENT_Cb, alfChromaIdc >> 1);
-      pcSlice->setTileGroupAlfEnabledFlag(COMPONENT_Cr, alfChromaIdc & 1);
+      pcSlice->setTileGroupAlfEnabledFlag(COMPONENT_Cb, alfChromaIdc & 1);
+      pcSlice->setTileGroupAlfEnabledFlag(COMPONENT_Cr, alfChromaIdc >> 1);
 #else
       if (uiCode)
       {
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index c24d0d43ba..90d880ba22 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -1415,7 +1415,7 @@ void HLSWriter::codeSliceHeader         ( Slice* pcSlice )
           WRITE_CODE(apsId[i], 5, "tile_group_aps_id");
         }
 
-        const int alfChromaIdc = pcSlice->getTileGroupAlfEnabledFlag(COMPONENT_Cb) * 2 + pcSlice->getTileGroupAlfEnabledFlag(COMPONENT_Cr);
+        const int alfChromaIdc = pcSlice->getTileGroupAlfEnabledFlag(COMPONENT_Cb) + pcSlice->getTileGroupAlfEnabledFlag(COMPONENT_Cr) * 2 ;
         truncatedUnaryEqProb(alfChromaIdc, 3);   // alf_chroma_idc
         if (alfChromaIdc)
         {
-- 
GitLab