From 4f03f1e6eb88766f47a77521a33b7877783264c0 Mon Sep 17 00:00:00 2001
From: Huanbang Chen <chenhuanbang@huawei.com>
Date: Wed, 31 Oct 2018 10:32:01 +0800
Subject: [PATCH] clean up for affine

---
 source/Lib/CommonLib/CommonDef.h   |  4 --
 source/Lib/CommonLib/UnitTools.cpp | 72 ++++++------------------------
 source/Lib/CommonLib/UnitTools.h   |  4 +-
 3 files changed, 15 insertions(+), 65 deletions(-)

diff --git a/source/Lib/CommonLib/CommonDef.h b/source/Lib/CommonLib/CommonDef.h
index 591d9b18f..59fa2e336 100644
--- a/source/Lib/CommonLib/CommonDef.h
+++ b/source/Lib/CommonLib/CommonDef.h
@@ -305,10 +305,6 @@ static const int CONTEXT_STATE_BITS =                               6;
 static const int LAST_SIGNIFICANT_GROUPS =                         14;
 static const int MAX_GR_ORDER_RESIDUAL =                           10;
 
-static const int AFFINE_MAX_NUM_V0 =                                3; ///< max number of motion candidates in top-left corner
-static const int AFFINE_MAX_NUM_V1 =                                2; ///< max number of motion candidates in top-right corner
-static const int AFFINE_MAX_NUM_V2 =                                2; ///< max number of motion candidates in left-bottom corner
-static const int AFFINE_MAX_NUM_COMB =                             12; ///< max number of combined motion candidates
 static const int AFFINE_MIN_BLOCK_SIZE =                            4; ///< Minimum affine MC block size
 
 
diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp
index b93551e10..1bb4fd77c 100644
--- a/source/Lib/CommonLib/UnitTools.cpp
+++ b/source/Lib/CommonLib/UnitTools.cpp
@@ -2052,14 +2052,14 @@ void PU::fillAffineMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, co
   amvpInfo0.numCand = 0;
 
   // A->C: Above Left, Above, Left
-  addMVPCandUnscaled( pu, eRefPicList, refIdx, posLT, MD_ABOVE_LEFT, amvpInfo0, true );
+  addMVPCandUnscaled( pu, eRefPicList, refIdx, posLT, MD_ABOVE_LEFT, amvpInfo0 );
   if ( amvpInfo0.numCand < 1 )
   {
-    addMVPCandUnscaled( pu, eRefPicList, refIdx, posLT, MD_ABOVE, amvpInfo0, true );
+    addMVPCandUnscaled( pu, eRefPicList, refIdx, posLT, MD_ABOVE, amvpInfo0 );
   }
   if ( amvpInfo0.numCand < 1 )
   {
-    addMVPCandUnscaled( pu, eRefPicList, refIdx, posLT, MD_LEFT, amvpInfo0, true );
+    addMVPCandUnscaled( pu, eRefPicList, refIdx, posLT, MD_LEFT, amvpInfo0 );
   }
   cornerMVPattern = cornerMVPattern | amvpInfo0.numCand;
 
@@ -2068,10 +2068,10 @@ void PU::fillAffineMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, co
   amvpInfo1.numCand = 0;
 
   // D->E: Above, Above Right
-  addMVPCandUnscaled( pu, eRefPicList, refIdx, posRT, MD_ABOVE, amvpInfo1, true );
+  addMVPCandUnscaled( pu, eRefPicList, refIdx, posRT, MD_ABOVE, amvpInfo1 );
   if ( amvpInfo1.numCand < 1 )
   {
-    addMVPCandUnscaled( pu, eRefPicList, refIdx, posRT, MD_ABOVE_RIGHT, amvpInfo1, true );
+    addMVPCandUnscaled( pu, eRefPicList, refIdx, posRT, MD_ABOVE_RIGHT, amvpInfo1 );
   }
   cornerMVPattern = cornerMVPattern | (amvpInfo1.numCand << 1);
 
@@ -2080,10 +2080,10 @@ void PU::fillAffineMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, co
   amvpInfo2.numCand = 0;
 
   // F->G: Left, Below Left
-  addMVPCandUnscaled( pu, eRefPicList, refIdx, posLB, MD_LEFT, amvpInfo2, true );
+  addMVPCandUnscaled( pu, eRefPicList, refIdx, posLB, MD_LEFT, amvpInfo2 );
   if ( amvpInfo2.numCand < 1 )
   {
-    addMVPCandUnscaled( pu, eRefPicList, refIdx, posLB, MD_BELOW_LEFT, amvpInfo2, true );
+    addMVPCandUnscaled( pu, eRefPicList, refIdx, posLB, MD_BELOW_LEFT, amvpInfo2 );
   }
   cornerMVPattern = cornerMVPattern | (amvpInfo2.numCand << 2);
 
@@ -2268,7 +2268,7 @@ void PU::fillAffineMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, co
 #endif
 }
 
-bool PU::addMVPCandUnscaled( const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &info, bool affine )
+bool PU::addMVPCandUnscaled( const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &info )
 {
         CodingStructure &cs    = *pu.cs;
   const PredictionUnit *neibPU = NULL;
@@ -2314,36 +2314,11 @@ bool PU::addMVPCandUnscaled( const PredictionUnit &pu, const RefPicList &eRefPic
 
     if( neibRefIdx >= 0 && currRefPOC == cs.slice->getRefPOC( eRefPicListIndex, neibRefIdx ) )
     {
-      if( affine )
-      {
-        int i = 0;
-        for( i = 0; i < info.numCand; i++ )
-        {
-          if( info.mvCand[i] == neibMi.mv[eRefPicListIndex] )
-          {
-            break;
-          }
-        }
-        if( i == info.numCand )
-        {
-          info.mvCand[info.numCand++] = neibMi.mv[eRefPicListIndex];
-#if !REMOVE_MV_ADAPT_PREC
-          Mv cMvHigh = neibMi.mv[eRefPicListIndex];
-          cMvHigh.setHighPrec();
-#endif
-//          CHECK( !neibMi.mv[eRefPicListIndex].highPrec, "Unexpected low precision mv.");
-          return true;
-        }
-      }
-      else
-      {
-        info.mvCand[info.numCand++] = neibMi.mv[eRefPicListIndex];
-        return true;
-      }
+      info.mvCand[info.numCand++] = neibMi.mv[eRefPicListIndex];
+      return true;
     }
   }
 
-
   return false;
 }
 
@@ -2355,7 +2330,7 @@ bool PU::addMVPCandUnscaled( const PredictionUnit &pu, const RefPicList &eRefPic
 * \param eDir
 * \returns bool
 */
-bool PU::addMVPCandWithScaling( const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &info, bool affine )
+bool PU::addMVPCandWithScaling( const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &info )
 {
         CodingStructure &cs    = *pu.cs;
   const Slice &slice           = *cs.slice;
@@ -2428,33 +2403,12 @@ bool PU::addMVPCandWithScaling( const PredictionUnit &pu, const RefPicList &eRef
           }
         }
 
-        if( affine )
-        {
-          int i;
-          for( i = 0; i < info.numCand; i++ )
-          {
-            if( info.mvCand[i] == cMv )
-            {
-              break;
-            }
-          }
-          if( i == info.numCand )
-          {
-            info.mvCand[info.numCand++] = cMv;
-//            CHECK( !cMv.highPrec, "Unexpected low precision mv.");
-            return true;
-          }
-        }
-        else
-        {
-          info.mvCand[info.numCand++] = cMv;
-          return true;
-        }
+        info.mvCand[info.numCand++] = cMv;
+        return true;
       }
     }
   }
 
-
   return false;
 }
 
diff --git a/source/Lib/CommonLib/UnitTools.h b/source/Lib/CommonLib/UnitTools.h
index 90beeaf85..18a9810e7 100644
--- a/source/Lib/CommonLib/UnitTools.h
+++ b/source/Lib/CommonLib/UnitTools.h
@@ -122,8 +122,8 @@ namespace PU
   bool getColocatedMVP                (const PredictionUnit &pu, const RefPicList &eRefPicList, const Position &pos, Mv& rcMv, const int &refIdx);
   void fillMvpCand                    (      PredictionUnit &pu, const RefPicList &eRefPicList, const int &refIdx, AMVPInfo &amvpInfo );
   void fillAffineMvpCand              (      PredictionUnit &pu, const RefPicList &eRefPicList, const int &refIdx, AffineAMVPInfo &affiAMVPInfo);
-  bool addMVPCandUnscaled             (const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &amvpInfo, bool affine = false);
-  bool addMVPCandWithScaling          (const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &amvpInfo, bool affine = false);
+  bool addMVPCandUnscaled             (const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &amvpInfo);
+  bool addMVPCandWithScaling          (const PredictionUnit &pu, const RefPicList &eRefPicList, const int &iRefIdx, const Position &pos, const MvpDir &eDir, AMVPInfo &amvpInfo);
   void xInheritedAffineMv             ( const PredictionUnit &pu, const PredictionUnit* puNeighbour, RefPicList eRefPicList, Mv rcMv[3] );
 #if JVET_L0266_HMVP
   bool xCheckSimilarMotion(const int mergeCandIndex, const int prevCnt, const MergeCtx mergeCandList, bool hasPruned[MRG_MAX_NUM_CANDS]);
-- 
GitLab