From 12e14165989d74bd7c6ccff403e2dc4360fb20a9 Mon Sep 17 00:00:00 2001
From: Karsten Suehring <karsten.suehring@hhi.fraunhofer.de>
Date: Wed, 2 Oct 2019 11:40:39 +0200
Subject: [PATCH] only activate luma/chroma ALF APS, when the corresponding
 component is active

---
 source/Lib/DecoderLib/DecLib.cpp | 45 ++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp
index 95d176e636..8d39c2367c 100644
--- a/source/Lib/DecoderLib/DecLib.cpp
+++ b/source/Lib/DecoderLib/DecLib.cpp
@@ -813,11 +813,33 @@ void activateAPS(Slice* pSlice, ParameterSetManager& parameterSetManager, APS**
 #endif
 {
   //luma APSs
-  for (int i = 0; i < pSlice->getTileGroupApsIdLuma().size(); i++)
+  if (pSlice->getTileGroupAlfEnabledFlag(COMPONENT_Y))
   {
-    int apsId = pSlice->getTileGroupApsIdLuma()[i];
-    APS* aps = parameterSetManager.getAPS(apsId, ALF_APS);
+    for (int i = 0; i < pSlice->getTileGroupApsIdLuma().size(); i++)
+    {
+      int apsId = pSlice->getTileGroupApsIdLuma()[i];
+      APS* aps = parameterSetManager.getAPS(apsId, ALF_APS);
 
+      if (aps)
+      {
+        apss[apsId] = aps;
+        if (false == parameterSetManager.activateAPS(apsId, ALF_APS))
+        {
+          THROW("APS activation failed!");
+        }
+
+#if JVET_O0245_VPS_DPS_APS
+        CHECK( aps->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" );
+        //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it.
+#endif
+      }
+    }
+  }
+  if (pSlice->getTileGroupAlfEnabledFlag(COMPONENT_Cb)||pSlice->getTileGroupAlfEnabledFlag(COMPONENT_Cr) )
+  {
+    //chroma APS
+    int apsId = pSlice->getTileGroupApsIdChroma();
+    APS* aps = parameterSetManager.getAPS(apsId, ALF_APS);
     if (aps)
     {
       apss[apsId] = aps;
@@ -833,23 +855,6 @@ void activateAPS(Slice* pSlice, ParameterSetManager& parameterSetManager, APS**
     }
   }
 
-  //chroma APS
-  int apsId = pSlice->getTileGroupApsIdChroma();
-  APS* aps = parameterSetManager.getAPS(apsId, ALF_APS);
-  if (aps)
-  {
-    apss[apsId] = aps;
-    if (false == parameterSetManager.activateAPS(apsId, ALF_APS))
-    {
-      THROW("APS activation failed!");
-    }
-
-#if JVET_O0245_VPS_DPS_APS
-    CHECK( aps->getTemporalId() > pSlice->getTLayer(), "TemporalId shall be less than or equal to the TemporalId of the coded slice NAL unit" );
-    //ToDO: APS NAL unit containing the APS RBSP shall have nuh_layer_id either equal to the nuh_layer_id of a coded slice NAL unit that referrs it, or equal to the nuh_layer_id of a direct dependent layer of the layer containing a coded slice NAL unit that referrs it.
-#endif
-  }
-
   if (pSlice->getLmcsEnabledFlag() && lmcsAPS == nullptr)
   {
     lmcsAPS = parameterSetManager.getAPS(pSlice->getLmcsAPSId(), LMCS_APS);
-- 
GitLab