[x265] refine MC

Satoshi Nakagawa nakagawa424 at oki.com
Mon Feb 24 10:58:25 CET 2014


# HG changeset patch
# User Satoshi Nakagawa <nakagawa424 at oki.com>
# Date 1393235720 -32400
#      Mon Feb 24 18:55:20 2014 +0900
# Node ID 8b5df2e11af069ceae450f20b7a637e40be9b5db
# Parent  80caa9f00d7c24da67d6b24e7bf339fe74752ced
refine MC

diff -r 80caa9f00d7c -r 8b5df2e11af0 source/Lib/TLibCommon/TComPrediction.cpp
--- a/source/Lib/TLibCommon/TComPrediction.cpp	Sun Feb 23 21:25:22 2014 +0530
+++ b/source/Lib/TLibCommon/TComPrediction.cpp	Mon Feb 24 18:55:20 2014 +0900
@@ -246,12 +246,15 @@
  */
 bool TComPrediction::xCheckIdenticalMotion(TComDataCU* cu, uint32_t partAddr)
 {
-    if (cu->getSlice()->isInterB() && !cu->getSlice()->getPPS()->getWPBiPred())
+    assert(cu->getSlice()->isInterB());
+    if (!cu->getSlice()->getPPS()->getWPBiPred())
     {
-        if (cu->getCUMvField(REF_PIC_LIST_0)->getRefIdx(partAddr) >= 0 && cu->getCUMvField(REF_PIC_LIST_1)->getRefIdx(partAddr) >= 0)
+        int refIdxL0 = cu->getCUMvField(REF_PIC_LIST_0)->getRefIdx(partAddr);
+        int refIdxL1 = cu->getCUMvField(REF_PIC_LIST_1)->getRefIdx(partAddr);
+        if (refIdxL0 >= 0 && refIdxL1 >= 0)
         {
-            int refPOCL0 = cu->getSlice()->getRefPic(REF_PIC_LIST_0, cu->getCUMvField(REF_PIC_LIST_0)->getRefIdx(partAddr))->getPOC();
-            int refPOCL1 = cu->getSlice()->getRefPic(REF_PIC_LIST_1, cu->getCUMvField(REF_PIC_LIST_1)->getRefIdx(partAddr))->getPOC();
+            int refPOCL0 = cu->getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->getPOC();
+            int refPOCL1 = cu->getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->getPOC();
             if (refPOCL0 == refPOCL1 && cu->getCUMvField(REF_PIC_LIST_0)->getMv(partAddr) == cu->getCUMvField(REF_PIC_LIST_1)->getMv(partAddr))
             {
                 return true;
@@ -267,9 +270,11 @@
     int  height;
     uint32_t partAddr;
 
-    if (partIdx >= 0)
+    assert(partIdx >= 0);
     {
         cu->getPartIndexAndSize(partIdx, partAddr, width, height);
+        if (cu->getSlice()->isInterP())
+            list = REF_PIC_LIST_0;
         if (list != REF_PIC_LIST_X)
         {
             if (cu->getSlice()->getPPS()->getUseWP())
@@ -303,48 +308,6 @@
                 xPredInterBi(cu, partAddr, width, height, predYuv, bLuma, bChroma);
             }
         }
-        return;
-    }
-
-    for (partIdx = 0; partIdx < cu->getNumPartInter(); partIdx++)
-    {
-        cu->getPartIndexAndSize(partIdx, partAddr, width, height);
-
-        if (list != REF_PIC_LIST_X)
-        {
-            if (cu->getSlice()->getPPS()->getUseWP())
-            {
-                TShortYUV* shortYuv = &m_predShortYuv[0];
-
-                int refId = cu->getCUMvField(list)->getRefIdx(partAddr);
-                assert(refId >= 0);
-
-                MV mv = cu->getCUMvField(list)->getMv(partAddr);
-                cu->clipMv(mv);
-
-                if (bLuma)
-                    xPredInterLumaBlk(cu, cu->getSlice()->getRefPic(list, refId)->getPicYuvRec(), partAddr, &mv, width, height, shortYuv);
-                if (bChroma)
-                    xPredInterChromaBlk(cu, cu->getSlice()->getRefPic(list, refId)->getPicYuvRec(), partAddr, &mv, width, height, shortYuv);
-
-                xWeightedPredictionUni(cu, shortYuv, partAddr, width, height, list, predYuv, -1, bLuma, bChroma);
-            }
-            else
-            {
-                xPredInterUni(cu, partAddr, width, height, list, predYuv, bLuma, bChroma);
-            }
-        }
-        else
-        {
-            if (xCheckIdenticalMotion(cu, partAddr))
-            {
-                xPredInterUni(cu, partAddr, width, height, REF_PIC_LIST_0, predYuv, bLuma, bChroma);
-            }
-            else
-            {
-                xPredInterBi(cu, partAddr, width, height, predYuv, bLuma, bChroma);
-            }
-        }
     }
 }
 
@@ -379,22 +342,24 @@
         xPredInterChromaBlk(cu, cu->getSlice()->getRefPic(list, refIdx)->getPicYuvRec(), partAddr, &mv, width, height, outPredYuv);
 }
 
-void TComPrediction::xPredInterBi(TComDataCU* cu, uint32_t partAddr, int width, int height, TComYuv*& outPredYuv, bool bLuma, bool bChroma)
+void TComPrediction::xPredInterBi(TComDataCU* cu, uint32_t partAddr, int width, int height, TComYuv* outPredYuv, bool bLuma, bool bChroma)
 {
-    int refIdx[2] = { -1, -1 };
+    assert(cu->getSlice()->isInterB());
 
-    if (cu->getCUMvField(REF_PIC_LIST_0)->getRefIdx(partAddr) >= 0 && cu->getCUMvField(REF_PIC_LIST_1)->getRefIdx(partAddr) >= 0)
+    int refIdx[2];
+    refIdx[0] = cu->getCUMvField(REF_PIC_LIST_0)->getRefIdx(partAddr);
+    refIdx[1] = cu->getCUMvField(REF_PIC_LIST_1)->getRefIdx(partAddr);
+
+    if (refIdx[0] >= 0 && refIdx[1] >= 0)
     {
         for (int list = 0; list < 2; list++)
         {
-            refIdx[list] = cu->getCUMvField(list)->getRefIdx(partAddr);
-
             assert(refIdx[list] < cu->getSlice()->getNumRefIdx(list));
 
             xPredInterUni(cu, partAddr, width, height, list, &m_predShortYuv[list], bLuma, bChroma);
         }
 
-        if (cu->getSlice()->getPPS()->getWPBiPred() && cu->getSlice()->getSliceType() == B_SLICE)
+        if (cu->getSlice()->getPPS()->getWPBiPred())
         {
             xWeightedPredictionBi(cu, &m_predShortYuv[0], &m_predShortYuv[1], refIdx[0], refIdx[1], partAddr, width, height, outPredYuv, bLuma, bChroma);
         }
@@ -403,11 +368,10 @@
             outPredYuv->addAvg(&m_predShortYuv[0], &m_predShortYuv[1], partAddr, width, height, bLuma, bChroma);
         }
     }
-    else if (cu->getSlice()->getPPS()->getWPBiPred() && cu->getSlice()->getSliceType() == B_SLICE)
+    else if (cu->getSlice()->getPPS()->getWPBiPred())
     {
         for (int list = 0; list < 2; list++)
         {
-            refIdx[list] = cu->getCUMvField(list)->getRefIdx(partAddr);
             if (refIdx[list] < 0) continue;
 
             assert(refIdx[list] < cu->getSlice()->getNumRefIdx(list));
@@ -417,40 +381,23 @@
 
         xWeightedPredictionBi(cu, &m_predShortYuv[0], &m_predShortYuv[1], refIdx[0], refIdx[1], partAddr, width, height, outPredYuv, bLuma, bChroma);
     }
-    else if (cu->getSlice()->getPPS()->getUseWP() && cu->getSlice()->getSliceType() == P_SLICE)
+    else if (refIdx[0] >= 0)
     {
-        int list = REF_PIC_LIST_0;
-        refIdx[list] = cu->getCUMvField(list)->getRefIdx(partAddr);
+        const int list = 0;
 
-        if (!(refIdx[0] < 0))
-        {
-            assert(refIdx[0] < cu->getSlice()->getNumRefIdx(list));
-            int refId = cu->getCUMvField(list)->getRefIdx(partAddr);
-            assert(refId >= 0);
+        assert(refIdx[list] < cu->getSlice()->getNumRefIdx(list));
 
-            MV mv = cu->getCUMvField(list)->getMv(partAddr);
-            cu->clipMv(mv);
-            if (bLuma)
-                xPredInterLumaBlk(cu, cu->getSlice()->getRefPic(list, refId)->getPicYuvRec(), partAddr, &mv, width, height, &m_predShortYuv[0]);
-            if (bChroma)
-                xPredInterChromaBlk(cu, cu->getSlice()->getRefPic(list, refId)->getPicYuvRec(), partAddr, &mv, width, height, &m_predShortYuv[0]);
-
-            xWeightedPredictionUni(cu, &m_predShortYuv[0], partAddr, width, height, REF_PIC_LIST_0, outPredYuv, -1, bLuma, bChroma);
-        }
+        xPredInterUni(cu, partAddr, width, height, list, outPredYuv, bLuma, bChroma);
     }
     else
     {
-        for (int list = 0; list < 2; list++)
-        {
-            refIdx[list] = cu->getCUMvField(list)->getRefIdx(partAddr);
-            if (refIdx[list] < 0) continue;
+        assert(refIdx[1] >= 0);
 
-            assert(refIdx[list] < cu->getSlice()->getNumRefIdx(list));
+        const int list = 1;
 
-            xPredInterUni(cu, partAddr, width, height, list, &m_predYuv[list], bLuma, bChroma);
-        }
+        assert(refIdx[list] < cu->getSlice()->getNumRefIdx(list));
 
-        xWeightedAverage(&m_predYuv[0], &m_predYuv[1], refIdx[0], refIdx[1], partAddr, width, height, outPredYuv, bLuma, bChroma);
+        xPredInterUni(cu, partAddr, width, height, list, outPredYuv, bLuma, bChroma);
     }
 }
 
@@ -657,20 +604,4 @@
     }
 }
 
-void TComPrediction::xWeightedAverage(TComYuv* srcYuv0, TComYuv* srcYuv1, int refIdx0, int refIdx1, uint32_t partIdx, int width, int height, TComYuv* outDstYuv, bool bLuma, bool bChroma)
-{
-    if (refIdx0 >= 0 && refIdx1 >= 0)
-    {
-        outDstYuv->addAvg(srcYuv0, srcYuv1, partIdx, width, height, bLuma, bChroma);
-    }
-    else if (refIdx0 >= 0 && refIdx1 <  0)
-    {
-        srcYuv0->copyPartToPartYuv(outDstYuv, partIdx, width, height, bLuma, bChroma);
-    }
-    else if (refIdx0 <  0 && refIdx1 >= 0)
-    {
-        srcYuv1->copyPartToPartYuv(outDstYuv, partIdx, width, height, bLuma, bChroma);
-    }
-}
-
 //! \}
diff -r 80caa9f00d7c -r 8b5df2e11af0 source/Lib/TLibCommon/TComPrediction.h
--- a/source/Lib/TLibCommon/TComPrediction.h	Sun Feb 23 21:25:22 2014 +0530
+++ b/source/Lib/TLibCommon/TComPrediction.h	Mon Feb 24 18:55:20 2014 +0900
@@ -80,8 +80,7 @@
     void xPredInterChromaBlk(TComDataCU *cu, TComPicYuv *refPic, uint32_t partAddr, MV *mv, int width, int height, TComYuv *dstPic);
     void xPredInterChromaBlk(TComDataCU *cu, TComPicYuv *refPic, uint32_t partAddr, MV *mv, int width, int height, TShortYUV *dstPic);
 
-    void xPredInterBi(TComDataCU* cu, uint32_t partAddr, int width, int height, TComYuv*& outPredYuv, bool bLuma, bool bChroma);
-    void xWeightedAverage(TComYuv* srcYuv0, TComYuv* srcYuv1, int refIdx0, int refIdx1, uint32_t partAddr, int width, int height, TComYuv* outDstYuv, bool bLuma, bool bChroma);
+    void xPredInterBi(TComDataCU* cu, uint32_t partAddr, int width, int height, TComYuv* outPredYuv, bool bLuma, bool bChroma);
 
     void xGetLLSPrediction(TComPattern* pcPattern, int* src0, int srcstride, pixel* dst0, int dststride, uint32_t width, uint32_t height, uint32_t ext0);
 
diff -r 80caa9f00d7c -r 8b5df2e11af0 source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Sun Feb 23 21:25:22 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Mon Feb 24 18:55:20 2014 +0900
@@ -1260,7 +1260,7 @@
                     outTempCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField(mvFieldNeighbours[1 + 2 * mergeCand], SIZE_2Nx2N, 0, 0); // interprets depth relative to outTempCU level
 
                     // do MC
-                    m_search->motionCompensation(outTempCU, m_tmpPredYuv[depth]);
+                    m_search->motionCompensation(outTempCU, m_tmpPredYuv[depth], REF_PIC_LIST_X, 0);
                     // estimate residual and encode everything
                     m_search->encodeResAndCalcRdInterCU(outTempCU,
                                                         m_origYuv[depth],
diff -r 80caa9f00d7c -r 8b5df2e11af0 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Sun Feb 23 21:25:22 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Mon Feb 24 18:55:20 2014 +0900
@@ -2893,8 +2893,6 @@
 
     bestMv = amvpInfo->m_mvCand[0];
 
-    m_predTempYuv.clear();
-
     //-- Check Minimum Cost.
     for (i = 0; i < AMVP_MAX_NUM_CANDS; i++)
     {
@@ -2908,8 +2906,6 @@
         }
     }
 
-    m_predTempYuv.clear();
-
     // Setting Best MVP
     mvPred = bestMv;
     cu->setMVPIdxSubParts(bestIdx, list, partAddr, partIdx, cu->getDepth(partAddr));
diff -r 80caa9f00d7c -r 8b5df2e11af0 source/encoder/compress.cpp
--- a/source/encoder/compress.cpp	Sun Feb 23 21:25:22 2014 +0530
+++ b/source/encoder/compress.cpp	Mon Feb 24 18:55:20 2014 +0900
@@ -251,7 +251,7 @@
             outTempCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField(mvFieldNeighbours[1 + 2 * mergeCand], SIZE_2Nx2N, 0, 0); // interprets depth relative to rpcTempCU level
 
             // do MC only for Luma part
-            m_search->motionCompensation(outTempCU, m_tmpPredYuv[depth], REF_PIC_LIST_X, -1, true, false);
+            m_search->motionCompensation(outTempCU, m_tmpPredYuv[depth], REF_PIC_LIST_X, 0, true, false);
             bitsCand = mergeCand + 1;
             if (mergeCand == (int)m_cfg->param.maxNumMergeCand - 1)
             {


More information about the x265-devel mailing list