[x265] [PATCH] merge multiple encodeBinEP to encodeBinsEP

Min Chen chenm003 at 163.com
Mon Oct 21 14:37:12 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1382359024 -28800
# Node ID 881dea872e800800f2c987e5212a4554ff0abb6a
# Parent  8fc308449916b49cea8b0839690d91cebcfb528b
merge multiple encodeBinEP to encodeBinsEP

diff -r 8fc308449916 -r 881dea872e80 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Mon Oct 21 14:09:12 2013 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Mon Oct 21 20:37:04 2013 +0800
@@ -1317,12 +1317,11 @@
 *\param   piMode          it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
 *\returns Number of MPM
 */
-int TComDataCU::getIntraDirLumaPredictor(UInt absPartIdx, int* intraDirPred, int* modes)
+void TComDataCU::getIntraDirLumaPredictor(UInt absPartIdx, int* intraDirPred, int* modes)
 {
     TComDataCU* tempCU;
     UInt        tempPartIdx;
     int         leftIntraDir, aboveIntraDir;
-    int         predNum = 0;
 
     // Get intra direction of left PU
     tempCU = getPULeft(tempPartIdx, m_absIdxInLCU + absPartIdx);
@@ -1334,7 +1333,6 @@
 
     aboveIntraDir = tempCU ? (tempCU->isIntra(tempPartIdx) ? tempCU->getLumaIntraDir(tempPartIdx) : DC_IDX) : DC_IDX;
 
-    predNum = 3;
     if (leftIntraDir == aboveIntraDir)
     {
         if (modes)
@@ -1373,8 +1371,6 @@
             intraDirPred[2] =  (leftIntraDir + aboveIntraDir) < 2 ? VER_IDX : DC_IDX;
         }
     }
-
-    return predNum;
 }
 
 UInt TComDataCU::getCtxSplitFlag(UInt absPartIdx, UInt depth)
diff -r 8fc308449916 -r 881dea872e80 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Mon Oct 21 14:09:12 2013 +0530
+++ b/source/Lib/TLibCommon/TComDataCU.h	Mon Oct 21 20:37:04 2013 +0800
@@ -490,7 +490,7 @@
     UInt          getIntraSizeIdx(UInt absPartIdx);
 
     void          getAllowedChromaDir(UInt absPartIdx, UInt* modeList);
-    int           getIntraDirLumaPredictor(UInt absPartIdx, int* intraDirPred, int* mode = NULL);
+    void          getIntraDirLumaPredictor(UInt absPartIdx, int* intraDirPred, int* mode = NULL);
 
     // -------------------------------------------------------------------------------------------------------------------
     // member functions for SBAC context
diff -r 8fc308449916 -r 881dea872e80 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Mon Oct 21 14:09:12 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Mon Oct 21 20:37:04 2013 +0800
@@ -529,21 +529,15 @@
 
     if (numCand > 1)
     {
-        for (UInt ui = 0; ui < numCand - 1; ++ui)
+        m_binIf->encodeBin((unaryIdx != 0), m_contextModels[OFF_MERGE_IDX_EXT_CTX]);
+
+        assert(unaryIdx < numCand);
+
+        if (unaryIdx != 0)
         {
-            const UInt symbol = ui == unaryIdx ? 0 : 1;
-            if (ui == 0)
-            {
-                m_binIf->encodeBin(symbol, m_contextModels[OFF_MERGE_IDX_EXT_CTX]);
-            }
-            else
-            {
-                m_binIf->encodeBinEP(symbol);
-            }
-            if (symbol == 0)
-            {
-                break;
-            }
+            UInt mask = (1 << unaryIdx) - 2;
+            mask >>= (unaryIdx == numCand - 1) ? 1 : 0;
+            m_binIf->encodeBinsEP(mask, unaryIdx - (unaryIdx == numCand - 1));
         }
     }
     DTRACE_CABAC_VL(g_nSymbolCounter++);
@@ -583,7 +577,7 @@
 {
     UInt dir[4], j;
     int preds[4][3] = { { -1, -1, -1 }, { -1, -1, -1 }, { -1, -1, -1 }, { -1, -1, -1 } };
-    int predNum[4], predIdx[4] = { -1, -1, -1, -1 };
+    int predIdx[4] = { -1, -1, -1, -1 };
     PartSize mode = cu->getPartitionSize(absPartIdx);
     UInt partNum = isMultiple ? (mode == SIZE_NxN ? 4 : 1) : 1;
     UInt partOffset = (cu->getPic()->getNumPartInCU() >> (cu->getDepth(absPartIdx) << 1)) >> 2;
@@ -591,8 +585,8 @@
     for (j = 0; j < partNum; j++)
     {
         dir[j] = cu->getLumaIntraDir(absPartIdx + partOffset * j);
-        predNum[j] = cu->getIntraDirLumaPredictor(absPartIdx + partOffset * j, preds[j]);
-        for (UInt i = 0; i < predNum[j]; i++)
+        cu->getIntraDirLumaPredictor(absPartIdx + partOffset * j, preds[j]);
+        for (UInt i = 0; i < 3; i++)
         {
             if (dir[j] == preds[j][i])
             {
@@ -607,11 +601,13 @@
     {
         if (predIdx[j] != -1)
         {
-            m_binIf->encodeBinEP(predIdx[j] ? 1 : 0);
-            if (predIdx[j])
-            {
-                m_binIf->encodeBinEP(predIdx[j] - 1);
-            }
+            assert((predIdx[j] >= 0) && (predIdx[j] <= 2));
+            // NOTE: Mapping
+            //       0 = 0
+            //       1 = 10
+            //       2 = 11
+            int nonzero = (!!predIdx[j]);
+            m_binIf->encodeBinsEP(predIdx[j] + nonzero, 1 + nonzero);
         }
         else
         {
@@ -627,10 +623,9 @@
             {
                 std::swap(preds[j][1], preds[j][2]);
             }
-            for (int i = (predNum[j] - 1); i >= 0; i--)
-            {
-                dir[j] = dir[j] > preds[j][i] ? dir[j] - 1 : dir[j];
-            }
+            dir[j] += (dir[j] > preds[j][2]) ? -1 : 0;
+            dir[j] += (dir[j] > preds[j][1]) ? -1 : 0;
+            dir[j] += (dir[j] > preds[j][0]) ? -1 : 0;
 
             m_binIf->encodeBinsEP(dir[j], 5);
         }
@@ -692,6 +687,7 @@
             UInt refNum = cu->getSlice()->getNumRefIdx(eRefList) - 2;
             idx++;
             refFrame--;
+            // TODO: reference codeMergeIndex() to improvement
             for (UInt i = 0; i < refNum; ++i)
             {
                 const UInt symbol = i == refFrame ? 0 : 1;
@@ -1274,40 +1270,21 @@
     }
 }
 
-/** code SAO offset sign
- * \param code sign value
- */
-void TEncSbac::codeSAOSign(UInt code)
-{
-    m_binIf->encodeBinEP(code);
-}
-
 void TEncSbac::codeSaoMaxUvlc(UInt code, UInt maxSymbol)
 {
-    if (maxSymbol == 0)
+    assert(maxSymbol > 0);
+
+    UInt isCodeLast = (maxSymbol > code) ? 1 : 0;
+    UInt isCodeNonZero = (code != 0) ? 1 : 0;
+
+    m_binIf->encodeBinEP(isCodeNonZero);
+    if (isCodeNonZero)
     {
-        return;
-    }
+        UInt mask = (1 << (code - 1)) - 1;
+        UInt len = code - 1 + isCodeLast;
+        mask <<= isCodeLast;
 
-    int i;
-    bool bCodeLast = (maxSymbol > code);
-
-    if (code == 0)
-    {
-        m_binIf->encodeBinEP(0);
-    }
-    else
-    {
-        m_binIf->encodeBinEP(1);
-        for (i = 0; i < code - 1; i++)
-        {
-            m_binIf->encodeBinEP(1);
-        }
-
-        if (bCodeLast)
-        {
-            m_binIf->encodeBinEP(0);
-        }
+        m_binIf->encodeBinsEP(mask, len);
     }
 }
 
diff -r 8fc308449916 -r 881dea872e80 source/Lib/TLibEncoder/TEncSbac.h
--- a/source/Lib/TLibEncoder/TEncSbac.h	Mon Oct 21 14:09:12 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSbac.h	Mon Oct 21 20:37:04 2013 +0800
@@ -100,7 +100,15 @@
     void  codeSaoMerge(UInt code);
     void  codeSaoTypeIdx(UInt code);
     void  codeSaoUflc(UInt length, UInt code);
-    void  codeSAOSign(UInt code);
+
+    /** code SAO offset sign
+     * \param code sign value
+     */
+    void TEncSbac::codeSAOSign(UInt code)
+    {
+        m_binIf->encodeBinEP(code);
+    }
+
     void  codeScalingList(TComScalingList*) { assert(0); }
 
 private:
diff -r 8fc308449916 -r 881dea872e80 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Mon Oct 21 14:09:12 2013 +0530
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Mon Oct 21 20:37:04 2013 +0800
@@ -1678,7 +1678,8 @@
 
             int preds[3] = { -1, -1, -1 };
             int mode = -1;
-            int numCand = cu->getIntraDirLumaPredictor(partOffset, preds, &mode);
+            int numCand = 3;
+            cu->getIntraDirLumaPredictor(partOffset, preds, &mode);
             if (mode >= 0)
             {
                 numCand = mode;



More information about the x265-devel mailing list