From 75fd26f97f11dd0e105eb53bfae09c217c8b5c36 Mon Sep 17 00:00:00 2001
From: zhangkai <zhangkai.video@bytedance.com>
Date: Thu, 25 Oct 2018 17:10:30 -0700
Subject: [PATCH] Change static variables to member variables

---
 source/Lib/CommonLib/InterPrediction.cpp | 92 ++++++++++++------------
 source/Lib/CommonLib/InterPrediction.h   |  9 ++-
 source/Lib/CommonLib/TypeDef.h           |  3 +-
 3 files changed, 50 insertions(+), 54 deletions(-)

diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp
index 889080da..92bdd9af 100644
--- a/source/Lib/CommonLib/InterPrediction.cpp
+++ b/source/Lib/CommonLib/InterPrediction.cpp
@@ -55,6 +55,9 @@ InterPrediction::InterPrediction()
   m_currChromaFormat( NUM_CHROMA_FORMAT )
 , m_maxCompIDToPred ( MAX_NUM_COMPONENT )
 , m_pcRdCost        ( nullptr )
+#if JVET_L0265_AFF_MINIMUM4X4
+, m_storedMv        ( nullptr )
+#endif
 {
   for( uint32_t ch = 0; ch < MAX_NUM_COMPONENT; ch++ )
   {
@@ -109,6 +112,13 @@ void InterPrediction::destroy()
       m_filteredBlockTmp[i][c] = nullptr;
     }
   }
+
+#if JVET_L0265_AFF_MINIMUM4X4
+  if (m_storedMv != nullptr)
+  {
+    delete[]m_storedMv;
+  }
+#endif
 }
 
 void InterPrediction::init( RdCost* pcRdCost, ChromaFormat chromaFormatIDC )
@@ -154,6 +164,11 @@ void InterPrediction::init( RdCost* pcRdCost, ChromaFormat chromaFormatIDC )
 #if !JVET_J0090_MEMORY_BANDWITH_MEASURE
   m_if.initInterpolationFilter( true );
 #endif
+
+#if JVET_L0265_AFF_MINIMUM4X4
+  const int MVBUFFER_SIZE = MAX_CU_SIZE / MIN_PU_SIZE;
+  m_storedMv = new Mv [MVBUFFER_SIZE*MVBUFFER_SIZE];
+#endif
 }
 
 bool checkIdenticalMotion( const PredictionUnit &pu, bool checkAffine )
@@ -327,21 +342,12 @@ void InterPrediction::xPredInterUni(const PredictionUnit& pu, const RefPicList&
   clipMv(mv[0], pu.cu->lumaPos(), sps);
 
 
-#if JVET_L0265_AFF_MINIMUM4X4
-  const int MVBUFFER_SIZE = MAX_CU_SIZE / MIN_PU_SIZE;
-  Mv storedMv[MVBUFFER_SIZE*MVBUFFER_SIZE];
-#endif
-
   for( uint32_t comp = COMPONENT_Y; comp < pcYuvPred.bufs.size() && comp <= m_maxCompIDToPred; comp++ )
   {
     const ComponentID compID = ComponentID( comp );
     if ( pu.cu->affine )
     {
-      xPredAffineBlk( compID, pu, pu.cu->slice->getRefPic( eRefPicList, iRefIdx ), mv, pcYuvPred, bi, pu.cu->slice->clpRng( compID ) 
-#if JVET_L0265_AFF_MINIMUM4X4
-      ,storedMv
-#endif
-      );
+      xPredAffineBlk( compID, pu, pu.cu->slice->getRefPic( eRefPicList, iRefIdx ), mv, pcYuvPred, bi, pu.cu->slice->clpRng( compID ) );
     }
     else
     {
@@ -475,11 +481,7 @@ void InterPrediction::xPredInterBlk ( const ComponentID& compID, const Predictio
   }
 }
 
-void InterPrediction::xPredAffineBlk( const ComponentID& compID, const PredictionUnit& pu, const Picture* refPic, const Mv* _mv, PelUnitBuf& dstPic, const bool& bi, const ClpRng& clpRng 
-#if JVET_L0265_AFF_MINIMUM4X4
-  , Mv* storedMv
-#endif
-)
+void InterPrediction::xPredAffineBlk( const ComponentID& compID, const PredictionUnit& pu, const Picture* refPic, const Mv* _mv, PelUnitBuf& dstPic, const bool& bi, const ClpRng& clpRng )
 {
   if ( (pu.cu->affineType == AFFINEMODEL_6PARAM && _mv[0] == _mv[1] && _mv[0] == _mv[2])
     || (pu.cu->affineType == AFFINEMODEL_4PARAM && _mv[0] == _mv[1])
@@ -521,8 +523,7 @@ void InterPrediction::xPredAffineBlk( const ComponentID& compID, const Predictio
 
   CHECK(blockWidth  > (width >> iScaleX ), "Sub Block width  > Block width");
   CHECK(blockHeight > (height >> iScaleX), "Sub Block height > Block height");
-
-  const int MVBUFFER_SIZE= MAX_CU_SIZE / MIN_PU_SIZE;
+  const int MVBUFFER_SIZE = MAX_CU_SIZE / MIN_PU_SIZE;
 #endif
 
   const int cxWidth  = width  >> iScaleX;
@@ -567,37 +568,32 @@ void InterPrediction::xPredAffineBlk( const ComponentID& compID, const Predictio
     {
 
 #if JVET_L0265_AFF_MINIMUM4X4
-       int iMvScaleTmpHor, iMvScaleTmpVer;
-       if(compID == COMPONENT_Y || storedMv == nullptr)
-       {
-          iMvScaleTmpHor = iMvScaleHor + iDMvHorX * (iHalfBW + w) + iDMvVerX * (iHalfBH + h);
-          iMvScaleTmpVer = iMvScaleVer + iDMvHorY * (iHalfBW + w) + iDMvVerY * (iHalfBH + h);
-          roundAffineMv(iMvScaleTmpHor, iMvScaleTmpVer, shift);
-
-          // clip and scale
-          iMvScaleTmpHor = std::min<int>(iHorMax, std::max<int>(iHorMin, iMvScaleTmpHor));
-          iMvScaleTmpVer = std::min<int>(iVerMax, std::max<int>(iVerMin, iMvScaleTmpVer));
-
-          if (storedMv != nullptr)
-          {
-            storedMv[h / AFFINE_MIN_BLOCK_SIZE * MVBUFFER_SIZE + w / AFFINE_MIN_BLOCK_SIZE].set(iMvScaleTmpHor, iMvScaleTmpVer);
-          }
-       }
-       else if(compID != COMPONENT_Y && storedMv != nullptr)
-       {
-          Mv curMv = (storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE) * MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE)] +
-              storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE + 1)* MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE)] +
-              storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE)* MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE + 1)] +
-              storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE + 1)* MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE + 1)] +
-              Mv(2, 2));
-          curMv.set(curMv.getHor() >> 2, curMv.getVer() >> 2);     
-          iMvScaleTmpHor = curMv.hor;
-          iMvScaleTmpVer = curMv.ver;
-       }
-       else
-       {
-          CHECK(1, "Impossible condition in affine motion compensation");
-       }
+        int iMvScaleTmpHor, iMvScaleTmpVer;
+        if(compID == COMPONENT_Y)
+        {
+
+            iMvScaleTmpHor = iMvScaleHor + iDMvHorX * (iHalfBW + w) + iDMvVerX * (iHalfBH + h);
+            iMvScaleTmpVer = iMvScaleVer + iDMvHorY * (iHalfBW + w) + iDMvVerY * (iHalfBH + h);
+            roundAffineMv(iMvScaleTmpHor, iMvScaleTmpVer, shift);
+
+            // clip and scale
+            iMvScaleTmpHor = std::min<int>(iHorMax, std::max<int>(iHorMin, iMvScaleTmpHor));
+            iMvScaleTmpVer = std::min<int>(iVerMax, std::max<int>(iVerMin, iMvScaleTmpVer));
+
+            m_storedMv[h / AFFINE_MIN_BLOCK_SIZE * MVBUFFER_SIZE + w / AFFINE_MIN_BLOCK_SIZE].set(iMvScaleTmpHor, iMvScaleTmpVer);
+        }
+        else
+        {
+
+           Mv curMv = (m_storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE) * MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE)] +
+             m_storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE + 1)* MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE)] +
+             m_storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE)* MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE + 1)] +
+             m_storedMv[((h << iScaleY) / AFFINE_MIN_BLOCK_SIZE + 1)* MVBUFFER_SIZE + ((w << iScaleX) / AFFINE_MIN_BLOCK_SIZE + 1)] +
+             Mv(2, 2));
+            curMv.set(curMv.getHor() >> 2, curMv.getVer() >> 2);     
+            iMvScaleTmpHor = curMv.hor;
+            iMvScaleTmpVer = curMv.ver;
+        }
 #else
       int iMvScaleTmpHor = iMvScaleHor + iDMvHorX * (iHalfBW + w) + iDMvVerX * (iHalfBH + h);
       int iMvScaleTmpVer = iMvScaleVer + iDMvHorY * (iHalfBW + w) + iDMvVerY * (iHalfBH + h);
diff --git a/source/Lib/CommonLib/InterPrediction.h b/source/Lib/CommonLib/InterPrediction.h
index 51901eea..b5ad68ab 100644
--- a/source/Lib/CommonLib/InterPrediction.h
+++ b/source/Lib/CommonLib/InterPrediction.h
@@ -81,6 +81,9 @@ protected:
 
   int                  m_iRefListIdx;
   
+#if JVET_L0265_AFF_MINIMUM4X4
+  Mv*                  m_storedMv;
+#endif
 
   void xPredInterUni            ( const PredictionUnit& pu, const RefPicList& eRefPicList, PelUnitBuf& pcYuvPred, const bool& bi 
   );
@@ -89,11 +92,7 @@ protected:
                                  );
   
   void xWeightedAverage         ( const PredictionUnit& pu, const CPelUnitBuf& pcYuvSrc0, const CPelUnitBuf& pcYuvSrc1, PelUnitBuf& pcYuvDst, const BitDepths& clipBitDepths, const ClpRngs& clpRngs );
-  void xPredAffineBlk( const ComponentID& compID, const PredictionUnit& pu, const Picture* refPic, const Mv* _mv, PelUnitBuf& dstPic, const bool& bi, const ClpRng& clpRng 
-#if JVET_L0265_AFF_MINIMUM4X4
-    , Mv* storedMv = nullptr
-#endif
-  );
+  void xPredAffineBlk( const ComponentID& compID, const PredictionUnit& pu, const Picture* refPic, const Mv* _mv, PelUnitBuf& dstPic, const bool& bi, const ClpRng& clpRng );
 
   static bool xCheckIdenticalMotion( const PredictionUnit& pu );
 
diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h
index 286abbd2..448972e0 100644
--- a/source/Lib/CommonLib/TypeDef.h
+++ b/source/Lib/CommonLib/TypeDef.h
@@ -50,13 +50,14 @@
 #include <assert.h>
 #include <cassert>
 
-
 #define JVET_L0104_NO_4x4BI_INTER_CU                      1 // Prohibit 4x4 bi-prediction for inter CU
 
 #define JVET_L0265_AFF_MINIMUM4X4                         1 //Affine 4x4 chroma subblock 
 
 #define JVET_L0553_FIX_INITQP                             1
 
+#define JVET_L0265_AFF_MINIMUM4X4                         1 //Affine 4x4 chroma subblock 
+
 #define JVET_L0147_ALF_SUBSAMPLED_LAPLACIAN               1 // Subsampled Laplacian calculation
 
 #define JVET_L0191_LM_WO_LMS                              1 // NO LMS regression. min/max are used instead
-- 
GitLab