From 97eb9abdf80c852f39f04ca3879b1e2ee3db13f0 Mon Sep 17 00:00:00 2001
From: Ahmed Sidiya <sidiyaa@sharplabs.com>
Date: Wed, 26 Jul 2023 14:36:58 -0400
Subject: [PATCH] JVET_AE0060_COND_SIG_INF: Signal
 nnpfc_chroma_loc_info_present_flag only when nnpfc_out_order_idc is not equal
 to 0 and infer nnpfc_chroma_loc_info_present_flag to be equal to 0 when not
 present.

---
 source/Lib/CommonLib/TypeDef.h       |  2 ++
 source/Lib/DecoderLib/SEIread.cpp    | 16 +++++++++++++++-
 source/Lib/EncoderLib/SEIEncoder.cpp | 13 ++++++++++++-
 source/Lib/EncoderLib/SEIwrite.cpp   |  7 +++++++
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 9c7b28305..5db939d53 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -79,6 +79,8 @@
 
 #define JVET_AD0067_INCLUDE_SYNTAX                        1 // include nnpfc_full_range_flag syntax element in the nnpfc sei message when nnpfc_separate_colour_description_present_flag is equal to 1 and when nnpfc_out_format_idc is equal to 1.
 
+#define JVET_AE0060_COND_SIG_INF                          1 // signal nnpfc_chroma_loc_info_present_flag only when nnpfc_out_order_idc is not equal to 0 and infer nnpfc_chroma_loc_info_present_flag to be equal to 0 when not present.
+
 #define REUSE_CU_RESULTS                                  1
 #if REUSE_CU_RESULTS
 #define REUSE_CU_RESULTS_WITH_MULTIPLE_TUS                1
diff --git a/source/Lib/DecoderLib/SEIread.cpp b/source/Lib/DecoderLib/SEIread.cpp
index ab384e7e2..a783386a6 100644
--- a/source/Lib/DecoderLib/SEIread.cpp
+++ b/source/Lib/DecoderLib/SEIread.cpp
@@ -3046,7 +3046,21 @@ void SEIReader::xParseSEINNPostFilterCharacteristics(SEINeuralNetworkPostFilterC
     }
 #endif
 
-    sei_read_flag(pDecodedMessageOutputStream,val,"nnpfc_chroma_loc_info_present_flag");
+#if JVET_AE0060_COND_SIG_INF
+    if (sei.m_outOrderIdc != 0)
+    {
+      sei_read_flag(pDecodedMessageOutputStream,val,"nnpfc_chroma_loc_info_present_flag");
+      sei.m_chromaLocInfoPresentFlag = val;
+    }
+    else
+    {
+      sei.m_chromaLocInfoPresentFlag = 0;
+    }
+#else
+      sei_read_flag(pDecodedMessageOutputStream,val,"nnpfc_chroma_loc_info_present_flag");
+      sei.m_chromaLocInfoPresentFlag = val;
+#endif
+
     sei.m_chromaLocInfoPresentFlag = val;
     CHECK((sei.m_outColourFormatIdc != ChromaFormat::_420) && sei.m_chromaLocInfoPresentFlag, "When nnpfc_out_colour_format_idc is not equal to 1, the value of nnpfc_chroma_loc_info_present_flag shall be equal to 0");
     CHECK((sei.m_purpose & NNPC_PurposeType::COLOURIZATION) && sei.m_chromaLocInfoPresentFlag,"When colourizationFlag is equal to 0, the value of nnpfc_chroma_loc_info_present_flag shall be equal to 0")
diff --git a/source/Lib/EncoderLib/SEIEncoder.cpp b/source/Lib/EncoderLib/SEIEncoder.cpp
index 9c641a2ee..7af3e3dc6 100644
--- a/source/Lib/EncoderLib/SEIEncoder.cpp
+++ b/source/Lib/EncoderLib/SEIEncoder.cpp
@@ -1445,7 +1445,18 @@ void SEIEncoder::initSEINeuralNetworkPostFilterCharacteristics(SEINeuralNetworkP
     sei->m_outOrderIdc = m_pcCfg->getNNPostFilterSEICharacteristicsOutOrderIdc(filterIdx);
     CHECK((sei->m_purpose & NNPC_PurposeType::CHROMA_UPSAMPLING) != 0 && (sei->m_outOrderIdc == 0 || sei->m_outOrderIdc == 3), "When nnpfc_purpose & 0x02 is not equal to 0, nnpfc_out_order_idc shall not be equal to 0 or 3");
     CHECK((sei->m_purpose & NNPC_PurposeType::COLOURIZATION) != 0 && sei->m_outOrderIdc == 0, "When nnpfc_purpose & 0x20 is not equal to 0, nnpfc_out_order_idc shall not be equal to 0");
-      sei->m_chromaLocInfoPresentFlag = m_pcCfg->getNNPostFilterSEICharacteristicsChromaLocInfoPresentFlag(filterIdx);
+#if JVET_AE0060_COND_SIG_INF
+      if(sei->m_outOrderIdc != 0)
+      {
+        sei->m_chromaLocInfoPresentFlag = m_pcCfg->getNNPostFilterSEICharacteristicsChromaLocInfoPresentFlag(filterIdx);
+      }
+      else
+      {
+        sei->m_chromaLocInfoPresentFlag = 0;
+      }
+#else
+        sei->m_chromaLocInfoPresentFlag = m_pcCfg->getNNPostFilterSEICharacteristicsChromaLocInfoPresentFlag(filterIdx);
+#endif
       if(sei->m_chromaLocInfoPresentFlag)
       {
         sei->m_chromaSampleLocTypeFrame = m_pcCfg->getNNPostFilterSEICharacteristicsChromaSampleLocTypeFrame(filterIdx);;
diff --git a/source/Lib/EncoderLib/SEIwrite.cpp b/source/Lib/EncoderLib/SEIwrite.cpp
index 5d3f4c4fa..6c50bc3dc 100644
--- a/source/Lib/EncoderLib/SEIwrite.cpp
+++ b/source/Lib/EncoderLib/SEIwrite.cpp
@@ -1779,7 +1779,14 @@ void SEIWriter::xWriteSEINeuralNetworkPostFilterCharacteristics(const SEINeuralN
     }
 #endif
     
+#if JVET_AE0060_COND_SIG_INF 
+    if (sei.m_outOrderIdc != 0)
+    {   
+      xWriteFlag(sei.m_chromaLocInfoPresentFlag, "nnpfc_chroma_loc_info_present_flag");
+    }
+#else
     xWriteFlag(sei.m_chromaLocInfoPresentFlag, "nnpfc_chroma_loc_info_present_flag");
+#endif
 
     if(sei.m_chromaLocInfoPresentFlag)
     {
-- 
GitLab