[x265] reduce unused context models

Satoshi Nakagawa nakagawa424 at oki.com
Thu Jan 30 03:01:46 CET 2014


# HG changeset patch
# User Satoshi Nakagawa <nakagawa424 at oki.com>
# Date 1391005695 -32400
#      Wed Jan 29 23:28:15 2014 +0900
# Node ID 505eac50c7f2f7db24561639a887da2463c30b8e
# Parent  8552e8cc1a3c60ddcab85e7421229c9a86d4785f
reduce unused context models

diff -r 8552e8cc1a3c -r 505eac50c7f2 source/Lib/TLibCommon/ContextTables.h
--- a/source/Lib/TLibCommon/ContextTables.h	Tue Jan 28 08:49:01 2014 -0600
+++ b/source/Lib/TLibCommon/ContextTables.h	Wed Jan 29 23:28:15 2014 +0900
@@ -67,7 +67,7 @@
 
 #define NUM_REF_NO_CTX                2       ///< number of context models for reference index
 #define NUM_TRANS_SUBDIV_FLAG_CTX     3       ///< number of context models for transform subdivision flags
-#define NUM_QT_CBF_CTX                4       ///< number of context models for QT CBF
+#define NUM_QT_CBF_CTX                6       ///< number of context models for QT CBF
 #define NUM_QT_ROOT_CBF_CTX           1       ///< number of context models for QT ROOT CBF
 #define NUM_DELTA_QP_CTX              3       ///< number of context models for dQP
 
@@ -111,7 +111,7 @@
 #define OFF_REF_NO_CTX                      (OFF_INTER_DIR_CTX          +     NUM_INTER_DIR_CTX)
 #define OFF_MV_RES_CTX                      (OFF_REF_NO_CTX             +     NUM_REF_NO_CTX)
 #define OFF_QT_CBF_CTX                      (OFF_MV_RES_CTX             +     NUM_MV_RES_CTX)
-#define OFF_TRANS_SUBDIV_FLAG_CTX           (OFF_QT_CBF_CTX             + 2 * NUM_QT_CBF_CTX)
+#define OFF_TRANS_SUBDIV_FLAG_CTX           (OFF_QT_CBF_CTX             +     NUM_QT_CBF_CTX)
 #define OFF_QT_ROOT_CBF_CTX                 (OFF_TRANS_SUBDIV_FLAG_CTX  +     NUM_TRANS_SUBDIV_FLAG_CTX)
 #define OFF_SIG_CG_FLAG_CTX                 (OFF_QT_ROOT_CBF_CTX        +     NUM_QT_ROOT_CBF_CTX)
 #define OFF_SIG_FLAG_CTX                    (OFF_SIG_CG_FLAG_CTX        + 2 * NUM_SIG_CG_FLAG_CTX)
@@ -265,11 +265,11 @@
 };
 
 static const uint8_t
-    INIT_QT_CBF[3][2 * NUM_QT_CBF_CTX] =
+    INIT_QT_CBF[3][NUM_QT_CBF_CTX] =
 {
-    { 153,  111,  CNU,  CNU,  149,   92,  167,  154, },
-    { 153,  111,  CNU,  CNU,  149,  107,  167,  154, },
-    { 111,  141,  CNU,  CNU,   94,  138,  182,  154, },
+    { 153,  111,  149,   92,  167,  154, },
+    { 153,  111,  149,  107,  167,  154, },
+    { 111,  141,   94,  138,  182,  154, },
 };
 
 static const uint8_t
diff -r 8552e8cc1a3c -r 505eac50c7f2 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp	Tue Jan 28 08:49:01 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.cpp	Wed Jan 29 23:28:15 2014 +0900
@@ -1239,19 +1239,6 @@
     return ctx;
 }
 
-uint32_t TComDataCU::getCtxQtCbf(TextType ttype, uint32_t trDepth)
-{
-    if (ttype)
-    {
-        return trDepth;
-    }
-    else
-    {
-        const uint32_t ctx = (trDepth == 0 ? 1 : 0);
-        return ctx;
-    }
-}
-
 uint32_t TComDataCU::getQuadtreeTULog2MinSizeInCU(uint32_t absPartIdx)
 {
     uint32_t log2CbSize = g_convertToBit[getWidth(absPartIdx)] + 2;
diff -r 8552e8cc1a3c -r 505eac50c7f2 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h	Tue Jan 28 08:49:01 2014 -0600
+++ b/source/Lib/TLibCommon/TComDataCU.h	Wed Jan 29 23:28:15 2014 +0900
@@ -467,7 +467,7 @@
     // -------------------------------------------------------------------------------------------------------------------
 
     uint32_t      getCtxSplitFlag(uint32_t absPartIdx, uint32_t depth);
-    uint32_t      getCtxQtCbf(TextType ttype, uint32_t trDepth);
+    uint32_t      getCtxQtCbf(TextType ttype, uint32_t trDepth) { return ttype == TEXT_LUMA ? (trDepth == 0 ? 1 : 0) : trDepth + 2; }
 
     uint32_t      getCtxSkipFlag(uint32_t absPartIdx);
     uint32_t      getCtxInterDir(uint32_t absPartIdx);
diff -r 8552e8cc1a3c -r 505eac50c7f2 source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Tue Jan 28 08:49:01 2014 -0600
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Wed Jan 29 23:28:15 2014 +0900
@@ -789,7 +789,6 @@
     else
     {
         ctxCbf    = cu->getCtxQtCbf(ttype, cu->getTransformIdx(absPartIdx));
-        ctxCbf    = (ttype ? NUM_QT_CBF_CTX : 0) + ctxCbf;
         bestCost  = blockUncodedCost + xGetICost(m_estBitsSbac->blockCbpBits[ctxCbf][0]);
         baseCost += xGetICost(m_estBitsSbac->blockCbpBits[ctxCbf][1]);
     }
diff -r 8552e8cc1a3c -r 505eac50c7f2 source/Lib/TLibCommon/TComTrQuant.h
--- a/source/Lib/TLibCommon/TComTrQuant.h	Tue Jan 28 08:49:01 2014 -0600
+++ b/source/Lib/TLibCommon/TComTrQuant.h	Wed Jan 29 23:28:15 2014 +0900
@@ -68,7 +68,7 @@
     int greaterOneBits[NUM_ONE_FLAG_CTX][2];
     int levelAbsBits[NUM_ABS_FLAG_CTX][2];
 
-    int blockCbpBits[2 * NUM_QT_CBF_CTX][2];
+    int blockCbpBits[NUM_QT_CBF_CTX][2];
     int blockRootCbpBits[4][2];
 } estBitsSbacStruct;
 
diff -r 8552e8cc1a3c -r 505eac50c7f2 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Tue Jan 28 08:49:01 2014 -0600
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Wed Jan 29 23:28:15 2014 +0900
@@ -224,7 +224,7 @@
     initBuffer(&m_contextModels[OFF_INTER_DIR_CTX], sliceType, qp, (UChar*)INIT_INTER_DIR, NUM_INTER_DIR_CTX);
     initBuffer(&m_contextModels[OFF_REF_NO_CTX], sliceType, qp, (UChar*)INIT_REF_PIC, NUM_REF_NO_CTX);
     initBuffer(&m_contextModels[OFF_MV_RES_CTX], sliceType, qp, (UChar*)INIT_MVD, NUM_MV_RES_CTX);
-    initBuffer(&m_contextModels[OFF_QT_CBF_CTX], sliceType, qp, (UChar*)INIT_QT_CBF, 2 * NUM_QT_CBF_CTX);
+    initBuffer(&m_contextModels[OFF_QT_CBF_CTX], sliceType, qp, (UChar*)INIT_QT_CBF, NUM_QT_CBF_CTX);
     initBuffer(&m_contextModels[OFF_TRANS_SUBDIV_FLAG_CTX], sliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG, NUM_TRANS_SUBDIV_FLAG_CTX);
     initBuffer(&m_contextModels[OFF_QT_ROOT_CBF_CTX], sliceType, qp, (UChar*)INIT_QT_ROOT_CBF, NUM_QT_ROOT_CBF_CTX);
     initBuffer(&m_contextModels[OFF_SIG_CG_FLAG_CTX], sliceType, qp, (UChar*)INIT_SIG_CG_FLAG, 2 * NUM_SIG_CG_FLAG_CTX);
@@ -275,7 +275,7 @@
             curCost += calcCost(&m_contextModels[OFF_INTER_DIR_CTX], curSliceType, qp, (UChar*)INIT_INTER_DIR, NUM_INTER_DIR_CTX);
             curCost += calcCost(&m_contextModels[OFF_REF_NO_CTX], curSliceType, qp, (UChar*)INIT_REF_PIC, NUM_REF_NO_CTX);
             curCost += calcCost(&m_contextModels[OFF_MV_RES_CTX], curSliceType, qp, (UChar*)INIT_MVD, NUM_MV_RES_CTX);
-            curCost += calcCost(&m_contextModels[OFF_QT_CBF_CTX], curSliceType, qp, (UChar*)INIT_QT_CBF, 2 * NUM_QT_CBF_CTX);
+            curCost += calcCost(&m_contextModels[OFF_QT_CBF_CTX], curSliceType, qp, (UChar*)INIT_QT_CBF, NUM_QT_CBF_CTX);
             curCost += calcCost(&m_contextModels[OFF_TRANS_SUBDIV_FLAG_CTX], curSliceType, qp, (UChar*)INIT_TRANS_SUBDIV_FLAG, NUM_TRANS_SUBDIV_FLAG_CTX);
             curCost += calcCost(&m_contextModels[OFF_QT_ROOT_CBF_CTX], curSliceType, qp, (UChar*)INIT_QT_ROOT_CBF, NUM_QT_ROOT_CBF_CTX);
             curCost += calcCost(&m_contextModels[OFF_SIG_CG_FLAG_CTX], curSliceType, qp, (UChar*)INIT_SIG_CG_FLAG, 2 * NUM_SIG_CG_FLAG_CTX);
@@ -1897,7 +1897,7 @@
     uint32_t cbf = cu->getCbf(absPartIdx, ttype, trDepth);
     uint32_t ctx = cu->getCtxQtCbf(ttype, trDepth);
 
-    m_binIf->encodeBin(cbf, m_contextModels[OFF_QT_CBF_CTX + (ttype ? NUM_QT_CBF_CTX : 0) + ctx]);
+    m_binIf->encodeBin(cbf, m_contextModels[OFF_QT_CBF_CTX + ctx]);
     DTRACE_CABAC_VL(g_nSymbolCounter++)
     DTRACE_CABAC_T("\tparseQtCbf()")
     DTRACE_CABAC_T("\tsymbol=")
@@ -2042,7 +2042,7 @@
     uint32_t cbf = 0;
     uint32_t ctx = cu->getCtxQtCbf(ttype, trDepth);
 
-    m_binIf->encodeBin(cbf, m_contextModels[OFF_QT_CBF_CTX + (ttype ? NUM_QT_CBF_CTX : 0) + ctx]);
+    m_binIf->encodeBin(cbf, m_contextModels[OFF_QT_CBF_CTX + ctx]);
 }
 
 void TEncSbac::codeQtRootCbfZero(TComDataCU*)
@@ -2459,7 +2459,7 @@
 {
     ContextModel *ctx = &m_contextModels[OFF_QT_CBF_CTX];
 
-    for (uint32_t ctxInc = 0; ctxInc < 2 * NUM_QT_CBF_CTX; ctxInc++)
+    for (uint32_t ctxInc = 0; ctxInc < NUM_QT_CBF_CTX; ctxInc++)
     {
         estBitsSbac->blockCbpBits[ctxInc][0] = sbacGetEntropyBits(ctx[ctxInc].m_state, 0);
         estBitsSbac->blockCbpBits[ctxInc][1] = sbacGetEntropyBits(ctx[ctxInc].m_state, 1);


More information about the x265-devel mailing list