From 5c4026e2e184f1d422f95fe52d9bfd95dd1b4f91 Mon Sep 17 00:00:00 2001
From: Antti Hallapuro <antti.hallapuro@nokia.com>
Date: Wed, 31 May 2023 14:16:31 +0300
Subject: [PATCH] JVET-AD0056-Item_4: picture width and height constraints

---
 source/Lib/CommonLib/TypeDef.h       |  3 +++
 source/Lib/EncoderLib/SEIEncoder.cpp | 27 +++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 4af8cbcab..96205a71e 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -70,6 +70,9 @@
 #define JVET_AD0054_NNPFC_ABSENT_INPUT_PIC_ZERO_FLAG      1
 
 #define JVET_AD0141_NNPFA_NONOUTPUTPIC                    1 //Check that NNPFA is present in pic that is not a non-output picture
+
+#define JVET_AD0056_PIC_WIDTH_HEIGHT_CONTRAINTS           1
+
 //########### place macros to be be kept below this line ###############
 
 #define GDR_ENABLED   1
diff --git a/source/Lib/EncoderLib/SEIEncoder.cpp b/source/Lib/EncoderLib/SEIEncoder.cpp
index 5e86e449c..6b7c80a88 100644
--- a/source/Lib/EncoderLib/SEIEncoder.cpp
+++ b/source/Lib/EncoderLib/SEIEncoder.cpp
@@ -1386,6 +1386,33 @@ void SEIEncoder::initSEINeuralNetworkPostFilterCharacteristics(SEINeuralNetworkP
       CHECK(!(sei->m_picWidthInLumaSamples >= croppedWidth && sei->m_picWidthInLumaSamples <= croppedWidth * 16 - 1), "m_picWidthInLumaSamples shall be in the range of croppedWidth to croppedWidth * 16 - 1");
       CHECK(!(sei->m_picHeightInLumaSamples >= croppedHeight && sei->m_picHeightInLumaSamples <= croppedHeight * 16 - 1), "m_picHeightInLumaSamples shall be in the range of croppedHeight to croppedHeight * 16 - 1");
 #endif
+
+#if JVET_AD0056_PIC_WIDTH_HEIGHT_CONTRAINTS
+      uint8_t      outSubWidthC  = subWidthC;
+      uint8_t      outSubHeightC = subHeightC;
+      if ((sei->m_purpose & NNPC_PurposeType::CHROMA_UPSAMPLING) != 0)
+      {
+        if (sei->m_outSubCFlag)
+        {
+          outSubWidthC  = 1;
+          outSubHeightC = 1;
+        }
+        else
+        {
+          outSubWidthC  = 2;
+          outSubHeightC = 1;
+        }
+      }
+      else if ((sei->m_purpose & NNPC_PurposeType::COLOURIZATION) != 0)
+      {
+        CHECK(sei->m_outColourFormatIdc == ChromaFormat::_400, "The value of nnpfc_out_colour_format_idc shall not be equal to 0");
+        outSubWidthC  = SPS::getWinUnitX(sei->m_outColourFormatIdc);
+        outSubHeightC = SPS::getWinUnitY(sei->m_outColourFormatIdc);
+      }
+
+      CHECK((outputPicWidth  % outSubWidthC)  != 0, "The value of nnpfcOutputPicWidth % outSubWidthC shall be equal to 0");
+      CHECK((outputPicHeight % outSubHeightC) != 0, "The value of nnpfcOutputPicHeight % outSubHeightC shall be equal to 0");
+#endif
     }
     if((sei->m_purpose & NNPC_PurposeType::FRAME_RATE_UPSAMPLING) != 0)
     {
-- 
GitLab