From 9238b6b98f5418a56e8892867819faacddc9cc07 Mon Sep 17 00:00:00 2001
From: Philippe Hanhart <philippe.hanhart@interdigital.com>
Date: Mon, 10 Dec 2018 16:06:22 -0800
Subject: [PATCH] Moved SPS parameters from SPSNext to SPS

---
 source/App/EncoderApp/EncAppCfg.cpp      | 17 +++++++----------
 source/Lib/CommonLib/InterPrediction.cpp |  6 +++---
 source/Lib/CommonLib/Mv.cpp              |  2 +-
 source/Lib/CommonLib/Picture.cpp         |  4 ++--
 source/Lib/CommonLib/Slice.cpp           |  8 ++++----
 source/Lib/CommonLib/Slice.h             | 23 ++++++++++++-----------
 source/Lib/DecoderLib/VLCReader.cpp      | 16 ++++++++--------
 source/Lib/EncoderLib/EncLib.cpp         |  4 ++--
 source/Lib/EncoderLib/VLCWriter.cpp      | 16 ++++++++--------
 9 files changed, 47 insertions(+), 49 deletions(-)

diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index 509fd0269..bf8b61851 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -1964,9 +1964,6 @@ bool EncAppCfg::xCheckParameter()
 #endif
 #if JVET_L0124_L0208_TRIANGLE
     xConfirmPara( m_Triangle, "Triangle is only allowed with NEXT profile" );
-#endif
-#if JVET_L0231_WRAPAROUND
-    xConfirmPara( m_wrapAround, "Horizontal wrap-around motion compensation for inter prediction is only allowed with NEXT profile" );
 #endif
     // ADD_NEW_TOOL : (parameter check) add a check for next tools here
   }
@@ -1990,16 +1987,16 @@ bool EncAppCfg::xCheckParameter()
 #if !REMOVE_MV_ADAPT_PREC 
     xConfirmPara(m_Affine && !m_highPrecisionMv, "Affine is not yet implemented for HighPrecMv off.");
 #endif
+  }
 
 #if JVET_L0231_WRAPAROUND
-    if( m_wrapAround )
-    {
-      xConfirmPara(m_wrapAroundOffset == 0, "Wrap-around offset must be greater than 0");
-      xConfirmPara(m_wrapAroundOffset > m_iSourceWidth, "Wrap-around offset must not be greater than the source picture width");
-      xConfirmPara(m_wrapAroundOffset % SPS::getWinUnitX(m_chromaFormatIDC) != 0, "Wrap-around offset must be an integer multiple of the specified chroma subsampling");
-    }
-#endif
+  if( m_wrapAround )
+  {
+    xConfirmPara( m_wrapAroundOffset == 0, "Wrap-around offset must be greater than 0" );
+    xConfirmPara( m_wrapAroundOffset > m_iSourceWidth, "Wrap-around offset must not be greater than the source picture width" );
+    xConfirmPara( m_wrapAroundOffset % SPS::getWinUnitX(m_chromaFormatIDC) != 0, "Wrap-around offset must be an integer multiple of the specified chroma subsampling" );
   }
+#endif
 
 #if ENABLE_SPLIT_PARALLELISM
   xConfirmPara( m_numSplitThreads < 1, "Number of used threads cannot be smaller than 1" );
diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp
index 90add37c8..f52278b9b 100644
--- a/source/Lib/CommonLib/InterPrediction.cpp
+++ b/source/Lib/CommonLib/InterPrediction.cpp
@@ -831,7 +831,7 @@ void InterPrediction::xPredAffineBlk( const ComponentID& compID, const Predictio
 
         // clip and scale
 #if JVET_L0231_WRAPAROUND
-        if (sps.getSpsNext().getUseWrapAround())
+        if (sps.getUseWrapAround())
         {
           m_storedMv[h / AFFINE_MIN_BLOCK_SIZE * MVBUFFER_SIZE + w / AFFINE_MIN_BLOCK_SIZE].set(iMvScaleTmpHor, iMvScaleTmpVer);
           Mv tmpMv(iMvScaleTmpHor, iMvScaleTmpVer);
@@ -859,7 +859,7 @@ void InterPrediction::xPredAffineBlk( const ComponentID& compID, const Predictio
           Mv(2, 2));
         curMv.set(curMv.getHor() >> 2, curMv.getVer() >> 2);     
 #if JVET_L0231_WRAPAROUND
-        if (sps.getSpsNext().getUseWrapAround())
+        if (sps.getUseWrapAround())
         {
           clipMv(curMv, Position(pu.Y().x + (w << iScaleX), pu.Y().y + (h << iScaleY)), Size(blockWidth << iScaleX, blockHeight << iScaleY), sps);
         }
@@ -874,7 +874,7 @@ void InterPrediction::xPredAffineBlk( const ComponentID& compID, const Predictio
 
       // clip and scale
 #if JVET_L0231_WRAPAROUND
-      if (sps.getSpsNext().getUseWrapAround())
+      if (sps.getUseWrapAround())
       {
         Mv tmpMv(iMvScaleTmpHor, iMvScaleTmpVer);
         clipMv(tmpMv, Position(pu.Y().x + (w << iScaleX), pu.Y().y + (h << iScaleY)), Size(blockWidth << iScaleX, blockHeight << iScaleY), sps);
diff --git a/source/Lib/CommonLib/Mv.cpp b/source/Lib/CommonLib/Mv.cpp
index d035d61a4..81e262407 100644
--- a/source/Lib/CommonLib/Mv.cpp
+++ b/source/Lib/CommonLib/Mv.cpp
@@ -85,7 +85,7 @@ void clipMv( Mv& rcMv, const Position& pos,
   int iVerMin = ( -( int ) sps.getMaxCUHeight()   - iOffset - ( int ) pos.y + 1 ) << iMvShift;
 
 #if JVET_L0231_WRAPAROUND
-  if( sps.getSpsNext().getUseWrapAround() )
+  if( sps.getUseWrapAround() )
   {
     int iHorMax = ( sps.getPicWidthInLumaSamples() + sps.getMaxCUWidth() - size.width + iOffset - ( int ) pos.x - 1 ) << iMvShift;
     int iHorMin = ( -( int ) sps.getMaxCUWidth()                                      - iOffset - ( int ) pos.x + 1 ) << iMvShift;
diff --git a/source/Lib/CommonLib/Picture.cpp b/source/Lib/CommonLib/Picture.cpp
index 1ffa0272c..db251d409 100644
--- a/source/Lib/CommonLib/Picture.cpp
+++ b/source/Lib/CommonLib/Picture.cpp
@@ -1005,9 +1005,9 @@ void Picture::extendPicBorder()
     Pel*  pi = piTxt;
     // do left and right margins
 #if JVET_L0231_WRAPAROUND
-    if (cs->sps->getSpsNext().getUseWrapAround())
+    if (cs->sps->getUseWrapAround())
     {
-      int xoffset = cs->sps->getSpsNext().getWrapAroundOffset() >> getComponentScaleX( compID, cs->area.chromaFormat );
+      int xoffset = cs->sps->getWrapAroundOffset() >> getComponentScaleX( compID, cs->area.chromaFormat );
       for (int y = 0; y < p.height; y++)
       {
         for (int x = 0; x < xmargin; x++ )
diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp
index 75e0a1c10..a96d6a39a 100644
--- a/source/Lib/CommonLib/Slice.cpp
+++ b/source/Lib/CommonLib/Slice.cpp
@@ -1829,10 +1829,6 @@ SPSNext::SPSNext( SPS& sps )
     , m_compositeRefEnabled     ( false )
 #if JVET_L0293_CPR
   , m_CPRMode                   ( 0 )
-#endif
-#if JVET_L0231_WRAPAROUND
-  , m_wrapAround                ( false )
-  , m_wrapAroundOffset          ( 0 )
 #endif
   // ADD_NEW_TOOL : (sps extension) add tool enabling flags here (with "false" as default values)
 {
@@ -1878,6 +1874,10 @@ SPS::SPS()
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
 , m_spsNextExtension          (*this)
+#if JVET_L0231_WRAPAROUND
+, m_useWrapAround             (false)
+, m_wrapAroundOffset          (  0)
+#endif
 {
   for(int ch=0; ch<MAX_NUM_CHANNEL_TYPE; ch++)
   {
diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h
index 142a4273a..b9d15e7c1 100644
--- a/source/Lib/CommonLib/Slice.h
+++ b/source/Lib/CommonLib/Slice.h
@@ -868,11 +868,6 @@ private:
   unsigned    m_CPRMode;
 #endif
 
-#if JVET_L0231_WRAPAROUND
-  bool        m_wrapAround;
-  unsigned    m_wrapAroundOffset;
-#endif
-
   // ADD_NEW_TOOL : (sps extension) add tool enabling flags and associated parameters here
 
 public:
@@ -994,12 +989,6 @@ public:
 #if JVET_L0293_CPR
   void      setCPRMode            (unsigned CPRMode)                                { m_CPRMode = CPRMode; }
   unsigned  getCPRMode            ()                                      const     { return m_CPRMode; }
-#endif
-#if JVET_L0231_WRAPAROUND
-  void      setUseWrapAround      ( bool b )                                        { m_wrapAround = b; }
-  bool      getUseWrapAround      ()                                      const     { return m_wrapAround; }
-  void      setWrapAroundOffset   ( unsigned offset )                               { m_wrapAroundOffset = offset; }
-  unsigned  getWrapAroundOffset   ()                                      const     { return m_wrapAroundOffset; }
 #endif
   // ADD_NEW_TOOL : (sps extension) add access functions for tool enabling flags and associated parameters here
 
@@ -1086,6 +1075,11 @@ private:
 
   bool              m_useALF;
 
+#if JVET_L0231_WRAPAROUND
+  bool              m_useWrapAround;
+  unsigned          m_wrapAroundOffset;
+#endif
+
 public:
 
   SPS();
@@ -1220,6 +1214,13 @@ public:
 
   bool                    getUseALF() const { return m_useALF; }
   void                    setUseALF( bool b ) { m_useALF = b; }
+
+#if JVET_L0231_WRAPAROUND
+  void                    setUseWrapAround(bool b)                                                        { m_useWrapAround = b;                                                 }
+  bool                    getUseWrapAround() const                                                        { return m_useWrapAround;                                              }
+  void                    setWrapAroundOffset(unsigned offset)                                            { m_wrapAroundOffset = offset;                                         }
+  unsigned                getWrapAroundOffset() const                                                     { return m_wrapAroundOffset;                                           }
+#endif
 };
 
 
diff --git a/source/Lib/DecoderLib/VLCReader.cpp b/source/Lib/DecoderLib/VLCReader.cpp
index 067dafb26..9a478a0a2 100644
--- a/source/Lib/DecoderLib/VLCReader.cpp
+++ b/source/Lib/DecoderLib/VLCReader.cpp
@@ -930,14 +930,6 @@ void HLSyntaxReader::parseSPSNext( SPSNext& spsNext, const bool usePCM )
     }
   }
 #endif
-
-#if JVET_L0231_WRAPAROUND
-  READ_FLAG( symbol, "ref_wraparound_enabled_flag" );               spsNext.setUseWrapAround( symbol != 0 );
-  if( spsNext.getUseWrapAround() )
-  {
-    READ_UVLC( symbol, "ref_wraparound_offset" );                   spsNext.setWrapAroundOffset( symbol );
-  }
-#endif
   // ADD_NEW_TOOL : (sps extension parser) read tool enabling flags and associated parameters here
 }
 
@@ -1085,6 +1077,14 @@ void HLSyntaxReader::parseSPS(SPS* pcSPS)
     READ_FLAG( uiCode, "pcm_loop_filter_disable_flag" );                 pcSPS->setPCMFilterDisableFlag ( uiCode ? true : false );
   }
 
+#if JVET_L0231_WRAPAROUND
+  READ_FLAG(uiCode, "ref_wraparound_enabled_flag");                 pcSPS->setUseWrapAround( uiCode ? true : false );
+  if (pcSPS->getUseWrapAround())
+  {
+    READ_UVLC(uiCode, "ref_wraparound_offset");                     pcSPS->setWrapAroundOffset( uiCode );
+  }
+#endif
+
   READ_UVLC( uiCode, "num_short_term_ref_pic_sets" );
   CHECK(uiCode > 64, "Invalid code");
   pcSPS->createRPSList(uiCode);
diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp
index a368c7992..ae3bb7b24 100644
--- a/source/Lib/EncoderLib/EncLib.cpp
+++ b/source/Lib/EncoderLib/EncLib.cpp
@@ -884,8 +884,8 @@ void EncLib::xInitSPS(SPS &sps)
 #endif 
 
 #if JVET_L0231_WRAPAROUND
-  sps.getSpsNext().setUseWrapAround         ( m_wrapAround );
-  sps.getSpsNext().setWrapAroundOffset      ( m_wrapAroundOffset );
+  sps.setUseWrapAround                      ( m_wrapAround );
+  sps.setWrapAroundOffset                   ( m_wrapAroundOffset );
 #endif
   // ADD_NEW_TOOL : (encoder lib) set tool enabling flags and associated parameters here
 
diff --git a/source/Lib/EncoderLib/VLCWriter.cpp b/source/Lib/EncoderLib/VLCWriter.cpp
index 6edd3181f..3b7762af3 100644
--- a/source/Lib/EncoderLib/VLCWriter.cpp
+++ b/source/Lib/EncoderLib/VLCWriter.cpp
@@ -640,14 +640,6 @@ void HLSWriter::codeSPSNext( const SPSNext& spsNext, const bool usePCM )
     }
   }
 #endif
-
-#if JVET_L0231_WRAPAROUND
-  WRITE_FLAG( spsNext.getUseWrapAround() ? 1 : 0,                                               "ref_wraparound_enabled_flag" );
-  if( spsNext.getUseWrapAround() )
-  {
-    WRITE_UVLC( spsNext.getWrapAroundOffset(),                                                  "ref_wraparound_offset" );
-  }
-#endif
   // ADD_NEW_TOOL : (sps extension writer) write tool enabling flags and associated parameters here
 }
 
@@ -740,6 +732,14 @@ void HLSWriter::codeSPS( const SPS* pcSPS )
     WRITE_FLAG( pcSPS->getPCMFilterDisableFlag()?1 : 0,                              "pcm_loop_filter_disable_flag");
   }
 
+#if JVET_L0231_WRAPAROUND
+  WRITE_FLAG( pcSPS->getUseWrapAround() ? 1 : 0,                                     "ref_wraparound_enabled_flag" );
+  if( pcSPS->getUseWrapAround() )
+  {
+    WRITE_UVLC( pcSPS->getWrapAroundOffset(),                                        "ref_wraparound_offset" );
+  }
+#endif
+
   CHECK( pcSPS->getMaxTLayers() == 0, "Maximum number of T-layers is '0'" );
 
   const RPSList* rpsList = pcSPS->getRPSList();
-- 
GitLab