[x265] [PATCH 2 of 2] improvement: replace compressMV by index mapping

Min Chen chenm003 at 163.com
Thu Sep 5 14:17:19 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1378383419 -28800
# Node ID d6df26c90ee5d1bb665502539e6e02b2dbaa6e7a
# Parent  b121e96290e2aff38a0e757e10d1f443a4d3202a
improvement: replace compressMV by index mapping

diff -r b121e96290e2 -r d6df26c90ee5 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Thu Sep 05 20:16:41 2013 +0800
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Thu Sep 05 20:16:59 2013 +0800
@@ -66,7 +66,6 @@
     m_skipFlag = NULL;
     m_partSizes = NULL;
     m_predModes = NULL;
-    m_cmv_predModes = NULL;
     m_cuTransquantBypass = NULL;
     m_width = NULL;
     m_height = NULL;
@@ -113,6 +112,12 @@
     m_numPartitions = numPartition;
     m_unitSize = unitSize;
 
+    UInt tmp = 4 * AMVP_DECIMATION_FACTOR / unitSize;
+    tmp = tmp * tmp;
+    assert(tmp == (1 << (g_convertToBit[tmp] + 2)));
+    tmp = g_convertToBit[tmp] + 2;
+    m_unitMask = ~((1 << tmp) - 1);
+
     m_qp     = (char*)X265_MALLOC(char,   numPartition);
     m_depth  = (UChar*)X265_MALLOC(UChar, numPartition);
     m_width  = (UChar*)X265_MALLOC(UChar, numPartition);
@@ -123,7 +128,6 @@
     m_partSizes = new char[numPartition];
     memset(m_partSizes, SIZE_NONE, numPartition * sizeof(*m_partSizes));
     m_predModes = new char[numPartition];
-    m_cmv_predModes = new char[numPartition];
     m_cuTransquantBypass = new bool[numPartition];
 
     m_bMergeFlags     = (bool*)X265_MALLOC(bool,  numPartition);
@@ -177,7 +181,6 @@
     if (m_skipFlag) { delete[] m_skipFlag; m_skipFlag = NULL; }
     if (m_partSizes) { delete[] m_partSizes; m_partSizes = NULL; }
     if (m_predModes) { delete[] m_predModes; m_predModes = NULL; }
-    if (m_cmv_predModes) { delete[] m_cmv_predModes; m_cmv_predModes = NULL; }
     if (m_cuTransquantBypass) { delete[] m_cuTransquantBypass; m_cuTransquantBypass = NULL; }
     if (m_cbf[0]) { X265_FREE(m_cbf[0]); m_cbf[0] = NULL; }
     if (m_cbf[1]) { X265_FREE(m_cbf[1]); m_cbf[1] = NULL; }
@@ -3007,7 +3010,7 @@
  */
 bool TComDataCU::xGetColMVP(RefPicList picList, int cuAddr, int partUnitIdx, MV& outMV, int& outRefIdx)
 {
-    UInt absPartAddr = partUnitIdx;
+    UInt absPartAddr = partUnitIdx & m_unitMask;
 
     RefPicList colRefPicList;
     int colPOC, colRefPOC, curPOC, curRefPOC, scale;
@@ -3025,18 +3028,18 @@
     curRefPOC = m_slice->getRefPic(picList, outRefIdx)->getPOC();
     colPOC = colCU->getSlice()->getPOC();
 
-    if (colCU->isIntra_cmv(absPartAddr))
+    if (colCU->isIntra(absPartAddr))
     {
         return false;
     }
     colRefPicList = getSlice()->getCheckLDC() ? picList : RefPicList(getSlice()->getColFromL0Flag());
 
-    int colRefIdx = colCU->getCUMvField(RefPicList(colRefPicList))->getRefIdx_cmv(absPartAddr);
+    int colRefIdx = colCU->getCUMvField(RefPicList(colRefPicList))->getRefIdx(absPartAddr);
 
     if (colRefIdx < 0)
     {
         colRefPicList = RefPicList(1 - colRefPicList);
-        colRefIdx = colCU->getCUMvField(RefPicList(colRefPicList))->getRefIdx_cmv(absPartAddr);
+        colRefIdx = colCU->getCUMvField(RefPicList(colRefPicList))->getRefIdx(absPartAddr);
 
         if (colRefIdx < 0)
         {
@@ -3046,7 +3049,7 @@
 
     // Scale the vector.
     colRefPOC = colCU->getSlice()->getRefPOC(colRefPicList, colRefIdx);
-    colmv = colCU->getCUMvField(colRefPicList)->getMv_cmv(absPartAddr);
+    colmv = colCU->getCUMvField(colRefPicList)->getMv(absPartAddr);
 
     curRefPOC = m_slice->getRefPic(picList, outRefIdx)->getPOC();
     bool bIsCurrRefLongTerm = m_slice->getRefPic(picList, outRefIdx)->getIsLongTerm();
@@ -3115,18 +3118,6 @@
                                        + (partWidth / m_pic->getMinCUWidth()) / 2];
 }
 
-void TComDataCU::compressMV()
-{
-    int scaleFactor = 4 * AMVP_DECIMATION_FACTOR / m_unitSize;
-
-    if (scaleFactor > 0)
-    {
-        memcpy(m_cmv_predModes, m_predModes, m_numPartitions * sizeof(m_predModes[0]));
-        m_cuMvField[0].compress(m_cmv_predModes, scaleFactor);
-        m_cuMvField[1].compress(m_cmv_predModes, scaleFactor);
-    }
-}
-
 UInt TComDataCU::getCoefScanIdx(UInt absPartIdx, UInt width, bool bIsLuma, bool bIsIntra)
 {
     UInt uiCTXIdx;
diff -r b121e96290e2 -r d6df26c90ee5 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Thu Sep 05 20:16:41 2013 +0800
+++ b/source/Lib/TLibCommon/TComDataCU.h	Thu Sep 05 20:16:59 2013 +0800
@@ -126,6 +126,7 @@
     UChar*        m_height;        ///< array of heights
     UChar*        m_depth;         ///< array of depths
     int           m_unitSize;         ///< size of a "minimum partition"
+    UInt          m_unitMask;       ///< mask for mapping index to CompressMV field
 
     // -------------------------------------------------------------------------------------------------------------------
     // CU data
@@ -133,7 +134,6 @@
     bool*         m_skipFlag;         ///< array of skip flags
     char*         m_partSizes;       ///< array of partition sizes
     char*         m_predModes;       ///< array of prediction modes
-    char*         m_cmv_predModes;       ///< array of prediction modes
     bool*         m_cuTransquantBypass; ///< array of cu_transquant_bypass flags
     char*         m_qp;             ///< array of QP values
     UChar*        m_trIdx;         ///< array of transform indices
@@ -461,8 +461,6 @@
 
     void          getMvPredAboveRight(MV& mvPred) { mvPred = m_mvFieldC.mv; }
 
-    void          compressMV();
-
     // -------------------------------------------------------------------------------------------------------------------
     // utility functions for neighboring information
     // -------------------------------------------------------------------------------------------------------------------
@@ -513,7 +511,6 @@
     // -------------------------------------------------------------------------------------------------------------------
 
     bool          isIntra(UInt partIdx)  { return m_predModes[partIdx] == MODE_INTRA; }
-    bool          isIntra_cmv(UInt partIdx)  { return m_cmv_predModes[partIdx] == MODE_INTRA; }
 
     bool          isSkipped(UInt partIdx);                                                      ///< SKIP (no residual)
     bool          isBipredRestriction(UInt puIdx);
diff -r b121e96290e2 -r d6df26c90ee5 source/Lib/TLibCommon/TComMotionInfo.cpp
--- a/source/Lib/TLibCommon/TComMotionInfo.cpp	Thu Sep 05 20:16:41 2013 +0800
+++ b/source/Lib/TLibCommon/TComMotionInfo.cpp	Thu Sep 05 20:16:59 2013 +0800
@@ -59,16 +59,10 @@
     assert(m_mvd    == NULL);
     assert(m_refIdx == NULL);
 
-    assert(m_cmv_mv == NULL);
-    assert(m_cmv_refIdx == NULL);
-
     m_mv     = new MV[numPartition];
     m_mvd    = new MV[numPartition];
     m_refIdx = new char[numPartition];
 
-    m_cmv_mv     = new MV[numPartition];
-    m_cmv_refIdx = new char[numPartition];
-
     m_numPartitions = numPartition;
 }
 
@@ -78,23 +72,14 @@
     assert(m_mvd    != NULL);
     assert(m_refIdx != NULL);
 
-    assert(m_cmv_mv     != NULL);
-    assert(m_cmv_refIdx != NULL);
-
     delete[] m_mv;
     delete[] m_mvd;
     delete[] m_refIdx;
 
-    delete[] m_cmv_mv;
-    delete[] m_cmv_refIdx;
-
     m_mv     = NULL;
     m_mvd    = NULL;
     m_refIdx = NULL;
 
-    m_cmv_mv     = NULL;
-    m_cmv_refIdx = NULL;
-
     m_numPartitions = 0;
 }
 
@@ -347,27 +332,4 @@
     setAllRefIdx(mvField.refIdx, cuMode, partAddr, depth, partIdx);
 }
 
-/**Subsampling of the stored prediction mode, reference index and motion vector
- * \param predMode   Pointer to prediction modes
- * \param scale      Factor by which to subsample motion information
- */
-void TComCUMvField::compress(char* predMode, int scale)
-{
-    int N = scale * scale;
-
-    assert(N > 0 && N <= m_numPartitions);
-
-    for (int partIdx = 0; partIdx < m_numPartitions; partIdx += N)
-    {
-        MV mv = m_mv[partIdx];
-        PredMode mode = static_cast<PredMode>(predMode[partIdx]);
-        int refIdx = m_refIdx[partIdx];
-        for (int i = 0; i < N; i++)
-        {
-            m_cmv_mv[partIdx + i] = mv;
-            predMode[partIdx + i] = mode;
-            m_cmv_refIdx[partIdx + i] = refIdx;
-        }
-    }
-}
 //! \}
diff -r b121e96290e2 -r d6df26c90ee5 source/Lib/TLibCommon/TComMotionInfo.h
--- a/source/Lib/TLibCommon/TComMotionInfo.h	Thu Sep 05 20:16:41 2013 +0800
+++ b/source/Lib/TLibCommon/TComMotionInfo.h	Thu Sep 05 20:16:59 2013 +0800
@@ -92,15 +92,12 @@
     UInt      m_numPartitions;
     AMVPInfo  m_cAMVPInfo;
 
-    MV*       m_cmv_mv;
-    char*     m_cmv_refIdx;
-
     template<typename T>
     void setAll(T *p, T const & val, PartSize cuMode, int partAddr, UInt depth, int partIdx);
 
 public:
 
-    TComCUMvField() : m_mv(NULL), m_mvd(NULL), m_refIdx(NULL), m_numPartitions(0), m_cmv_mv(NULL), m_cmv_refIdx(NULL) {}
+    TComCUMvField() : m_mv(NULL), m_mvd(NULL), m_refIdx(NULL), m_numPartitions(0) {}
 
     ~TComCUMvField() {}
 
@@ -126,12 +123,10 @@
     // ------------------------------------------------------------------------------------------------------------------
 
     const MV & getMv(int idx) const { return m_mv[idx]; }
-    const MV & getMv_cmv(int idx) const { return m_cmv_mv[idx]; }
 
     const MV & getMvd(int idx) const { return m_mvd[idx]; }
 
     int getRefIdx(int idx) const { return m_refIdx[idx]; }
-    int getRefIdx_cmv(int idx) const { return m_cmv_refIdx[idx]; }
 
     AMVPInfo* getAMVPInfo() { return &m_cAMVPInfo; }
 
diff -r b121e96290e2 -r d6df26c90ee5 source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Thu Sep 05 20:16:41 2013 +0800
+++ b/source/Lib/TLibCommon/TComPic.cpp	Thu Sep 05 20:16:59 2013 +0800
@@ -120,17 +120,6 @@
     m_lowres.destroy();
 }
 
-void TComPic::compressMotion()
-{
-    TComPicSym* sym = getPicSym();
-
-    for (UInt cuAddr = 0; cuAddr < sym->getFrameHeightInCU() * sym->getFrameWidthInCU(); cuAddr++)
-    {
-        TComDataCU* cu = sym->getCU(cuAddr);
-        cu->compressMV();
-    }
-}
-
 /** Create non-deblocked filter information
  * \param pSliceStartAddress array for storing slice start addresses
  * \param numSlices number of slices in picture
diff -r b121e96290e2 -r d6df26c90ee5 source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Thu Sep 05 20:16:41 2013 +0800
+++ b/source/Lib/TLibCommon/TComPic.h	Thu Sep 05 20:16:59 2013 +0800
@@ -137,8 +137,6 @@
 
     int           getCStride()            { return m_reconPicYuv->getCStride(); }
 
-    void          compressMotion();
-
     Window&       getConformanceWindow()  { return m_conformanceWindow; }
 
     Window&       getDefDisplayWindow()   { return m_defaultDisplayWindow; }
diff -r b121e96290e2 -r d6df26c90ee5 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Thu Sep 05 20:16:41 2013 +0800
+++ b/source/encoder/framefilter.cpp	Thu Sep 05 20:16:59 2013 +0800
@@ -222,18 +222,6 @@
         }
     }
 
-    // CompressMV for reference
-    if (row > 0)
-    {
-        for (UInt col = 0; col < numCols; col++)
-        {
-            const uint32_t cuAddr = lineStartCUAddr - numCols + col;
-            TComDataCU* cu = m_pic->getCU(cuAddr);
-
-            cu->compressMV();
-        }
-    }
-
     // this row of CTUs has been encoded
 
     // TODO: extend margins for motion reference
@@ -307,15 +295,6 @@
             }
         }
 
-        // CompressMV
-        for (UInt col = 0; col < numCols; col++)
-        {
-            const uint32_t cuAddr = lineStartCUAddr + col;
-            TComDataCU* cu = m_pic->getCU(cuAddr);
-
-            cu->compressMV();
-        }
-
         // TODO: Remove when we confirm below code is right
         //recon->xExtendPicCompBorder(recon->getLumaAddr(), recon->getStride(), recon->getWidth(), recon->getHeight(), recon->m_lumaMarginX, recon->m_lumaMarginY);
         //recon->xExtendPicCompBorder(recon->getCbAddr(), recon->getCStride(), recon->getWidth() >> 1, recon->getHeight() >> 1, recon->m_chromaMarginX, recon->m_chromaMarginY);



More information about the x265-devel mailing list