From 94e6eeb3a02d90d18dc632e886a672dc15c906fe Mon Sep 17 00:00:00 2001
From: Ya-Hsuan Lee <Louise.Lee@mediatek.com>
Date: Thu, 5 Mar 2020 17:14:24 +0800
Subject: [PATCH] JVET-Q0343: add guard band type in GCMP SEI message

---
 cfg/sei_vui/generalized_cubemap_projection.cfg |  3 ++-
 doc/software-manual.tex                        |  6 +++++-
 source/App/EncoderApp/EncApp.cpp               |  5 +++++
 source/App/EncoderApp/EncAppCfg.cpp            |  5 +++++
 source/App/EncoderApp/EncAppCfg.h              |  5 +++++
 source/Lib/CommonLib/SEI.h                     |  5 +++++
 source/Lib/CommonLib/TypeDef.h                 |  2 ++
 source/Lib/DecoderLib/SEIread.cpp              |  6 ++++++
 source/Lib/EncoderLib/EncCfg.h                 | 12 ++++++++++++
 source/Lib/EncoderLib/SEIEncoder.cpp           |  6 ++++++
 source/Lib/EncoderLib/SEIwrite.cpp             |  5 +++++
 11 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/cfg/sei_vui/generalized_cubemap_projection.cfg b/cfg/sei_vui/generalized_cubemap_projection.cfg
index 82cd6d8a4..7ec5b8587 100644
--- a/cfg/sei_vui/generalized_cubemap_projection.cfg
+++ b/cfg/sei_vui/generalized_cubemap_projection.cfg
@@ -11,6 +11,7 @@ SEIGcmpFunctionUAffectedByVFlag          : 0 0 0 0 0 0
 SEIGcmpFunctionCoeffV                    : 0.4 0.4 0.4 0.28 0.4 0.28
 SEIGcmpFunctionVAffectedByUFlag          : 1 1 1 0 1 0
 SEIGcmpGuardBandFlag                     : 1
-SEIGcmpGuardBandBoundaryType             : 1
+SEIGcmpGuardBandType                     : 2
+SEIGcmpGuardBandBoundaryExteriorFlag     : 1
 SEIGcmpGuardBandSamplesMinus1            : 15
 
diff --git a/doc/software-manual.tex b/doc/software-manual.tex
index 4981a7431..f1e46393b 100644
--- a/doc/software-manual.tex
+++ b/doc/software-manual.tex
@@ -3703,7 +3703,11 @@ An array that specifies whether the cubemap mapping function of the v-axis refer
 \Default{false} &
 Indicates the existence of guard band areas in the picture.
 \\
-\Option{SEIGcmpGuardBandBoundaryType} &
+\Option{SEIGcmpGuardBandType} &
+\Default{0} &
+Indicates the type of the guard bands.
+\\
+\Option{SEIGcmpGuardBandBoundaryExteriorFlag} &
 \Default{false} &
 Enables (true) or disables (false) the boundary guard bands.
 \\
diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp
index 8e2aef234..61b9c4bcf 100644
--- a/source/App/EncoderApp/EncApp.cpp
+++ b/source/App/EncoderApp/EncApp.cpp
@@ -741,7 +741,12 @@ void EncApp::xInitLibCfg()
   m_cEncLib.setGcmpSEIFunctionCoeffV                             ( m_gcmpSEIFunctionCoeffV );
   m_cEncLib.setGcmpSEIFunctionVAffectedByUFlag                   ( m_gcmpSEIFunctionVAffectedByUFlag );                                                              
   m_cEncLib.setGcmpSEIGuardBandFlag                              ( m_gcmpSEIGuardBandFlag );
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+  m_cEncLib.setGcmpSEIGuardBandType                              ( m_gcmpSEIGuardBandType );
+  m_cEncLib.setGcmpSEIGuardBandBoundaryExteriorFlag              ( m_gcmpSEIGuardBandBoundaryExteriorFlag );
+#else
   m_cEncLib.setGcmpSEIGuardBandBoundaryType                      ( m_gcmpSEIGuardBandBoundaryType );
+#endif
   m_cEncLib.setGcmpSEIGuardBandSamplesMinus1                     ( (uint8_t)m_gcmpSEIGuardBandSamplesMinus1 );
   m_cEncLib.setSubpicureLevelInfoSEIEnabled                      (m_subpicureLevelInfoSEIEnabled);
   m_cEncLib.setSampleAspectRatioInfoSEIEnabled                   (m_sampleAspectRatioInfoSEIEnabled);
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index fecbcd9ea..1054d70a0 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -1345,7 +1345,12 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
   ("SEIGcmpFunctionCoeffV",                           cfg_gcmpSEIFunctionCoeffV,                cfg_gcmpSEIFunctionCoeffV,                "Specifies the coefficient used in the cubemap mapping function of the v-axis of the i-th face")
   ("SEIGcmpFunctionVAffectedByUFlag",                 cfg_gcmpSEIFunctionVAffectedByUFlag,      cfg_gcmpSEIFunctionVAffectedByUFlag,      "Specifies whether the cubemap mapping function of the v-axis refers to the u position of the sample location")
   ("SEIGcmpGuardBandFlag",                            m_gcmpSEIGuardBandFlag,                   false,                                    "Indicate the existence of guard band areas in the picture")
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+  ("SEIGcmpGuardBandType",                            m_gcmpSEIGuardBandType,                   0u,                                       "Indicate the type of the guard bands")
+  ("SEIGcmpGuardBandBoundaryExteriorFlag",            m_gcmpSEIGuardBandBoundaryExteriorFlag,   false,                                    "Indicate whether face boundaries contain guard bands")
+#else
   ("SEIGcmpGuardBandBoundaryType",                    m_gcmpSEIGuardBandBoundaryType,           false,                                    "Indicate which face boundaries contain guard bands")
+#endif
   ("SEIGcmpGuardBandSamplesMinus1",                   m_gcmpSEIGuardBandSamplesMinus1,          0u,                                       "Specifies the number of guard band samples minus1 used in the cubemap projected picture")
   ("SEISubpicureLevelInfo",                           m_subpicureLevelInfoSEIEnabled,           false, "Control generation of Subpicture Level Information SEI messages")
   ("SEISampleAspectRatioInfo",                        m_sampleAspectRatioInfoSEIEnabled,        false, "Control generation of Sample Aspect Ratio Information SEI messages")
diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h
index e78b8887f..801af9b46 100644
--- a/source/App/EncoderApp/EncAppCfg.h
+++ b/source/App/EncoderApp/EncAppCfg.h
@@ -621,7 +621,12 @@ protected:
   std::vector<double>  m_gcmpSEIFunctionCoeffV;
   std::vector<bool>    m_gcmpSEIFunctionVAffectedByUFlag;
   bool                 m_gcmpSEIGuardBandFlag;
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+  uint32_t             m_gcmpSEIGuardBandType;
+  bool                 m_gcmpSEIGuardBandBoundaryExteriorFlag;
+#else
   bool                 m_gcmpSEIGuardBandBoundaryType;
+#endif
   uint32_t             m_gcmpSEIGuardBandSamplesMinus1;
 
   bool m_subpicureLevelInfoSEIEnabled;
diff --git a/source/Lib/CommonLib/SEI.h b/source/Lib/CommonLib/SEI.h
index d3023f409..47ba6d465 100644
--- a/source/Lib/CommonLib/SEI.h
+++ b/source/Lib/CommonLib/SEI.h
@@ -197,7 +197,12 @@ public:
   std::vector<uint8_t> m_gcmpFunctionCoeffV;
   std::vector<bool>    m_gcmpFunctionVAffectedByUFlag;
   bool                 m_gcmpGuardBandFlag;
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+  uint8_t              m_gcmpGuardBandType;
+  bool                 m_gcmpGuardBandBoundaryExteriorFlag;
+#else
   bool                 m_gcmpGuardBandBoundaryType;
+#endif
   uint8_t              m_gcmpGuardBandSamplesMinus1;
 };
 
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 68197ea53..6c7bad775 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -146,6 +146,8 @@
 
 #define JVET_Q0818_PT_SEI                                 1 // JVET-Q0818: add display_elemental_periods_minus1 to picture timing SEI message
 
+#define JVET_Q0343_GCMP_GUARD_BAND_TYPE                   1 // JVET-Q0343: Add gcmp_guard_band_type to generalized cubemap projection SEI message and rename boundary guard band
+
 #define JVET_Q0110_Q0785_CHROMA_BDPCM_420                 1 // JVET-Q0110/Q0785: Enable chroma BDPCM for 420, separate contexts for chroma BDPCM and bug-fixes.
 
 #define JVET_Q0042_VUI                                    1 // Modifications to VUI syntax
diff --git a/source/Lib/DecoderLib/SEIread.cpp b/source/Lib/DecoderLib/SEIread.cpp
index 08233e03b..c369738fa 100644
--- a/source/Lib/DecoderLib/SEIread.cpp
+++ b/source/Lib/DecoderLib/SEIread.cpp
@@ -1183,8 +1183,14 @@ void SEIReader::xParseSEIGeneralizedCubemapProjection(SEIGeneralizedCubemapProje
     sei_read_flag( pDecodedMessageOutputStream,        val,    "gcmp_guard_band_flag" );                  sei.m_gcmpGuardBandFlag = val;
     if (sei.m_gcmpGuardBandFlag)
     {
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+      sei_read_code( pDecodedMessageOutputStream,   3, val,    "gcmp_guard_band_type" );                   sei.m_gcmpGuardBandType = val;
+      sei_read_flag( pDecodedMessageOutputStream,      val,    "gcmp_guard_band_boundary_exterior_flag" ); sei.m_gcmpGuardBandBoundaryExteriorFlag = val;
+      sei_read_code( pDecodedMessageOutputStream,   4, val,    "gcmp_guard_band_samples_minus1" );         sei.m_gcmpGuardBandSamplesMinus1 = val;
+#else
       sei_read_flag( pDecodedMessageOutputStream,      val,    "gcmp_guard_band_boundary_type" );         sei.m_gcmpGuardBandBoundaryType  = val;
       sei_read_code( pDecodedMessageOutputStream,   4, val,    "gcmp_guard_band_samples_minus1" );        sei.m_gcmpGuardBandSamplesMinus1 = val;
+#endif
     }
   }
 }
diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h
index bcc61b490..de2d4103f 100644
--- a/source/Lib/EncoderLib/EncCfg.h
+++ b/source/Lib/EncoderLib/EncCfg.h
@@ -614,7 +614,12 @@ protected:
   std::vector<double>  m_gcmpSEIFunctionCoeffV;
   std::vector<bool>    m_gcmpSEIFunctionVAffectedByUFlag;
   bool                 m_gcmpSEIGuardBandFlag;
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+  uint8_t              m_gcmpSEIGuardBandType;
+  bool                 m_gcmpSEIGuardBandBoundaryExteriorFlag;
+#else
   bool                 m_gcmpSEIGuardBandBoundaryType;
+#endif
   uint8_t              m_gcmpSEIGuardBandSamplesMinus1;
   bool m_subpicureLevelInfoSEIEnabled;
   bool                  m_sampleAspectRatioInfoSEIEnabled;
@@ -1656,8 +1661,15 @@ public:
   bool    getGcmpSEIFunctionVAffectedByUFlag(int idx) const                                         { return m_gcmpSEIFunctionVAffectedByUFlag[idx]; }
   void    setGcmpSEIGuardBandFlag(bool b)                                                           { m_gcmpSEIGuardBandFlag = b; }
   bool    getGcmpSEIGuardBandFlag()                                                                 { return m_gcmpSEIGuardBandFlag; }
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+  void    setGcmpSEIGuardBandType(uint8_t u)                                                        { m_gcmpSEIGuardBandType = u; }
+  uint8_t getGcmpSEIGuardBandType()                                                                 { return m_gcmpSEIGuardBandType; }
+  void    setGcmpSEIGuardBandBoundaryExteriorFlag(bool b)                                           { m_gcmpSEIGuardBandBoundaryExteriorFlag = b; }
+  bool    getGcmpSEIGuardBandBoundaryExteriorFlag()                                                 { return m_gcmpSEIGuardBandBoundaryExteriorFlag; }
+#else
   void    setGcmpSEIGuardBandBoundaryType(bool b)                                                   { m_gcmpSEIGuardBandBoundaryType = b; }
   bool    getGcmpSEIGuardBandBoundaryType()                                                         { return m_gcmpSEIGuardBandBoundaryType; }
+#endif
   void    setGcmpSEIGuardBandSamplesMinus1( uint8_t u )                                             { m_gcmpSEIGuardBandSamplesMinus1 = u; }
   uint8_t getGcmpSEIGuardBandSamplesMinus1()                                                        { return m_gcmpSEIGuardBandSamplesMinus1; }
   bool    getSubpicureLevelInfoSEIEnabled() const { return m_subpicureLevelInfoSEIEnabled; }
diff --git a/source/Lib/EncoderLib/SEIEncoder.cpp b/source/Lib/EncoderLib/SEIEncoder.cpp
index 776294e21..330d8a070 100644
--- a/source/Lib/EncoderLib/SEIEncoder.cpp
+++ b/source/Lib/EncoderLib/SEIEncoder.cpp
@@ -341,8 +341,14 @@ void SEIEncoder::initSEIGcmp(SEIGeneralizedCubemapProjection* seiGeneralizedCube
     seiGeneralizedCubemapProjection->m_gcmpGuardBandFlag                 = m_pcCfg->getGcmpSEIGuardBandFlag();
     if (seiGeneralizedCubemapProjection->m_gcmpGuardBandFlag)
     {
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+      seiGeneralizedCubemapProjection->m_gcmpGuardBandType                 = m_pcCfg->getGcmpSEIGuardBandType();
+      seiGeneralizedCubemapProjection->m_gcmpGuardBandBoundaryExteriorFlag = m_pcCfg->getGcmpSEIGuardBandBoundaryExteriorFlag();
+      seiGeneralizedCubemapProjection->m_gcmpGuardBandSamplesMinus1        = m_pcCfg->getGcmpSEIGuardBandSamplesMinus1();
+#else
       seiGeneralizedCubemapProjection->m_gcmpGuardBandBoundaryType       = m_pcCfg->getGcmpSEIGuardBandBoundaryType();
       seiGeneralizedCubemapProjection->m_gcmpGuardBandSamplesMinus1      = m_pcCfg->getGcmpSEIGuardBandSamplesMinus1();
+#endif
     }
   }
 }
diff --git a/source/Lib/EncoderLib/SEIwrite.cpp b/source/Lib/EncoderLib/SEIwrite.cpp
index 3673ecea4..e27040644 100644
--- a/source/Lib/EncoderLib/SEIwrite.cpp
+++ b/source/Lib/EncoderLib/SEIwrite.cpp
@@ -667,7 +667,12 @@ void SEIWriter::xWriteSEIGeneralizedCubemapProjection(const SEIGeneralizedCubema
     WRITE_FLAG( sei.m_gcmpGuardBandFlag,                      "gcmp_guard_band_flag" );
     if (sei.m_gcmpGuardBandFlag)
     {
+#if JVET_Q0343_GCMP_GUARD_BAND_TYPE
+      WRITE_CODE( sei.m_gcmpGuardBandType,                 3, "gcmp_guard_band_type" );
+      WRITE_FLAG( sei.m_gcmpGuardBandBoundaryExteriorFlag,    "gcmp_guard_band_boundary_exterior_flag" );
+#else
       WRITE_FLAG( sei.m_gcmpGuardBandBoundaryType,            "gcmp_guard_band_boundary_type" );  
+#endif
       WRITE_CODE( sei.m_gcmpGuardBandSamplesMinus1,        4, "gcmp_guard_band_samples_minus1" );  
     }
   }
-- 
GitLab