From a834c605be26a2131e1cb28869fab28ba4a0b623 Mon Sep 17 00:00:00 2001
From: Takeshi Chujoh <chujoh.takeshi@sharp.co.jp>
Date: Thu, 11 Aug 2022 19:46:41 +0900
Subject: [PATCH] JVET-AA0067_NNPFC_SEI_FIX

---
 source/App/EncoderApp/EncAppCfg.cpp | 4 ++++
 source/Lib/CommonLib/TypeDef.h      | 1 +
 source/Lib/DecoderLib/SEIread.cpp   | 4 ++++
 source/Lib/EncoderLib/SEIwrite.cpp  | 4 ++++
 4 files changed, 13 insertions(+)

diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index fe9b25c03..3d4be3f39 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -4651,7 +4651,11 @@ bool EncAppCfg::xCheckParameter()
       xConfirmPara(m_nnPostFilterSEICharacteristicsPaddingType[i] > (1 << 4) - 1, "SEINNPostFilterPaddingType must be in the range of 0 to 2^4-1");
       xConfirmPara(m_nnPostFilterSEICharacteristicsComplexityIdc[i] > 255, "SEINNPostFilterCharacteristicsComplexityIdc must be in the range of 0 to 255");
       xConfirmPara(m_nnPostFilterSEICharacteristicsLog2ParameterBitLengthMinus3[i] > 3, "SEINNPostFilterCharacteristicsLog2ParameterBitLengthMinus3 must be in the range of 0 to 3");
+#if JVET_AA0067_NNPFC_SEI_FIX
+      xConfirmPara(m_nnPostFilterSEICharacteristicsNumParametersIdc[i] > 52, "SEINNPostFilterCharacteristicsNumParametersIdc must be in the range of 0 to 52");
+#else
       xConfirmPara(m_nnPostFilterSEICharacteristicsNumParametersIdc[i] > 255, "SEINNPostFilterCharacteristicsNumParametersIdc must be in the range of 0 to 255");
+#endif
     }
   }
 
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 76bc9c3cf..f391d1276 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -56,6 +56,7 @@
 //########### place macros to be removed in next cycle below this line ###############
 #define JVET_AA0056_GATING_FILTER_CHARACTERISTICS         1 // JVET-AA0056 AHG9: on syntax gating in the neural-network post-filter characteristics SEI message
 #define JVET_AA0100_SEPERATE_COLOR_CHARACTERISTICS        1 // JVET-AA0100 AHG9: On auxiliary input and separate colour description in the neural-network post-filter characteristics SEI message
+#define JVET_AA0067_NNPFC_SEI_FIX                         1 // JVET-AA0067 AHG9: Some specification improvements for neural-network post-filter characteristics SEI message	
 
 //########### place macros to be be kept below this line ###############
 #define JVET_X0143_ALF_APS_ID_OFFSET                      0 // A value between 0 to 7 inclusive. This macro should be kept, or to be defined as a configuration parameter if possible.
diff --git a/source/Lib/DecoderLib/SEIread.cpp b/source/Lib/DecoderLib/SEIread.cpp
index 52b142fda..da8ad658c 100644
--- a/source/Lib/DecoderLib/SEIread.cpp
+++ b/source/Lib/DecoderLib/SEIread.cpp
@@ -2576,7 +2576,11 @@ void SEIReader::xParseSEINNPostFilterCharacteristics(SEINeuralNetworkPostFilterC
         sei_read_code(pDecodedMessageOutputStream, 2, val, "nnpfc_log2_parameter_bit_length_minus3");
         sei.m_log2ParameterBitLengthMinus3 = val;
 
+#if JVET_AA0067_NNPFC_SEI_FIX
+        sei_read_code(pDecodedMessageOutputStream, 6, val, "nnpfc_num_parameters_idc");
+#else
         sei_read_code(pDecodedMessageOutputStream, 8, val, "nnpfc_num_parameters_idc");
+#endif
         sei.m_numParametersIdc = val;
 
         sei_read_uvlc(pDecodedMessageOutputStream, val, "nnpfc_num_kmac_operations_idc");
diff --git a/source/Lib/EncoderLib/SEIwrite.cpp b/source/Lib/EncoderLib/SEIwrite.cpp
index c185535d0..d2d300ffd 100644
--- a/source/Lib/EncoderLib/SEIwrite.cpp
+++ b/source/Lib/EncoderLib/SEIwrite.cpp
@@ -1475,7 +1475,11 @@ void SEIWriter::xWriteNNPFCComplexityElement(const SEINeuralNetworkPostFilterCha
   {
     WRITE_FLAG(sei.m_parameterTypeFlag, "nnpfc_parameter_type_flag");
     WRITE_CODE(sei.m_log2ParameterBitLengthMinus3, 2, "nnpfc_log2_parameter_bit_length_minus3");
+#if JVET_AA0067_NNPFC_SEI_FIX
+    WRITE_CODE(sei.m_numParametersIdc, 6, "nnpfc_num_parameters_idc");
+#else
     WRITE_CODE(sei.m_numParametersIdc, 8, "nnpfc_num_parameters_idc");
+#endif
     WRITE_UVLC(sei.m_numKmacOperationsIdc, "nnpfc_num_kmac_operations_idc");
   }
 }
-- 
GitLab