[x265] [PATCH 1 of 3] cleanup:reduce ContextModel3DBuffer to 1D

Min Chen chenm003 at 163.com
Tue Oct 15 14:31:41 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1381840243 -28800
# Node ID 369ea551e0304070c137fa5c0122c80dfeff96f6
# Parent  abae6903e0af0d9940bb734ba34dff6928d72e61
cleanup:reduce ContextModel3DBuffer to 1D

diff -r abae6903e0af -r 369ea551e030 source/Lib/TLibCommon/ContextModel.h
--- a/source/Lib/TLibCommon/ContextModel.h	Mon Oct 14 13:12:22 2013 -0500
+++ b/source/Lib/TLibCommon/ContextModel.h	Tue Oct 15 20:30:43 2013 +0800
@@ -56,7 +56,7 @@
 {
 public:
 
-    ContextModel()   { m_state = 0; m_binsCoded = 0; }
+    ContextModel()   { m_state = 0; bBinsCoded = 0; }
 
     ~ContextModel()  {}
 
@@ -64,8 +64,6 @@
 
     UChar getMps()   { return m_state  & 1; } ///< get curret MPS
 
-    void  setStateAndMps(UChar ucState, UChar ucMPS) { m_state = (ucState << 1) + ucMPS; } ///< set state and MPS
-
     void init(int qp, int initValue);   ///< initialize state with initial probability
 
     void updateLPS()
@@ -78,7 +76,7 @@
         m_state = s_nextStateMPS[m_state];
     }
 
-    int getEntropyBits(short val) { return s_entropyBits[m_state ^ val]; }
+    int getEntropyBits(UInt val) { return s_entropyBits[m_state ^ val]; }
 
     void update(int binVal)
     {
@@ -88,18 +86,18 @@
     static void buildNextStateTable();
     static int getEntropyBitsTrm(int val) { return s_entropyBits[126 ^ val]; }
 
-    void setBinsCoded(UInt val)   { m_binsCoded = val;  }
+    void setBinsCoded(UInt val)   { bBinsCoded = (UChar)val;  }
 
-    UInt getBinsCoded()           { return m_binsCoded;   }
+    UInt getBinsCoded()           { return bBinsCoded;   }
 
 private:
 
     UChar         m_state;  ///< internal state variable
+    UChar         bBinsCoded;
     static const UChar s_nextStateMPS[128];
     static const UChar s_nextStateLPS[128];
     static const int   s_entropyBits[128];
     static UChar  m_nextState[128][2];
-    UInt          m_binsCoded;
 };
 }
 //! \}
diff -r abae6903e0af -r 369ea551e030 source/Lib/TLibCommon/ContextModel3DBuffer.cpp
--- a/source/Lib/TLibCommon/ContextModel3DBuffer.cpp	Mon Oct 14 13:12:22 2013 -0500
+++ b/source/Lib/TLibCommon/ContextModel3DBuffer.cpp	Tue Oct 15 20:30:43 2013 +0800
@@ -46,10 +46,8 @@
 // Constructor / destructor / initialization / destroy
 // ====================================================================================================================
 
-ContextModel3DBuffer::ContextModel3DBuffer(UInt uiSizeZ, UInt uiSizeY, UInt uiSizeX, ContextModel *basePtr, int &count)
-    : m_sizeX(uiSizeX)
-    , m_sizeXY(uiSizeX * uiSizeY)
-    , m_sizeXYZ(uiSizeX * uiSizeY * uiSizeZ)
+ContextModel3DBuffer::ContextModel3DBuffer(UInt uiSizeY, UInt uiSizeX, ContextModel *basePtr, int &count)
+    : m_sizeXYZ(uiSizeX * uiSizeY)
 {
     // allocate 3D buffer
     m_contextModel = basePtr;
diff -r abae6903e0af -r 369ea551e030 source/Lib/TLibCommon/ContextModel3DBuffer.h
--- a/source/Lib/TLibCommon/ContextModel3DBuffer.h	Mon Oct 14 13:12:22 2013 -0500
+++ b/source/Lib/TLibCommon/ContextModel3DBuffer.h	Tue Oct 15 20:30:43 2013 +0800
@@ -62,31 +62,19 @@
 protected:
 
     ContextModel* m_contextModel; ///< array of context models
-    const UInt    m_sizeX;      ///< X size of 3D buffer
-    const UInt    m_sizeXY;     ///< X times Y size of 3D buffer
     const UInt    m_sizeXYZ;    ///< total size of 3D buffer
 
     ContextModel3DBuffer& operator =(const ContextModel3DBuffer&);
 
 public:
 
-    ContextModel3DBuffer(UInt uiSizeZ, UInt uiSizeY, UInt uiSizeX, ContextModel *basePtr, int &count);
+    ContextModel3DBuffer(UInt uiSizeY, UInt uiSizeX, ContextModel *basePtr, int &count);
     ~ContextModel3DBuffer() {}
 
     // access functions
-    ContextModel& get(UInt uiZ, UInt uiY, UInt uiX)
+    ContextModel& get(UInt uiX)
     {
-        return m_contextModel[uiZ * m_sizeXY + uiY * m_sizeX + uiX];
-    }
-
-    ContextModel* get(UInt uiZ, UInt uiY)
-    {
-        return &m_contextModel[uiZ * m_sizeXY + uiY * m_sizeX];
-    }
-
-    ContextModel* get(UInt uiZ)
-    {
-        return &m_contextModel[uiZ * m_sizeXY];
+        return m_contextModel[uiX];
     }
 
     // initialization & copy functions
diff -r abae6903e0af -r 369ea551e030 source/Lib/TLibCommon/ContextTables.h
--- a/source/Lib/TLibCommon/ContextTables.h	Mon Oct 14 13:12:22 2013 -0500
+++ b/source/Lib/TLibCommon/ContextTables.h	Tue Oct 15 20:30:43 2013 +0800
@@ -46,7 +46,7 @@
 // Constants
 // ====================================================================================================================
 
-#define MAX_NUM_CTX_MOD             512       ///< maximum number of supported contexts
+#define MAX_NUM_CTX_MOD             256       ///< maximum number of supported contexts
 
 #define NUM_SPLIT_FLAG_CTX            3       ///< number of context models for split flag
 #define NUM_SKIP_FLAG_CTX             3       ///< number of context models for skip flag
diff -r abae6903e0af -r 369ea551e030 source/Lib/TLibCommon/TypeDef.h
--- a/source/Lib/TLibCommon/TypeDef.h	Mon Oct 14 13:12:22 2013 -0500
+++ b/source/Lib/TLibCommon/TypeDef.h	Tue Oct 15 20:30:43 2013 +0800
@@ -126,7 +126,6 @@
     TEXT_CHROMA_U,      ///< chroma U
     TEXT_CHROMA_V,      ///< chroma V
     TEXT_ALL,           ///< Y+U+V
-    TEXT_NONE = 15
 };
 
 /// reference list index
diff -r abae6903e0af -r 369ea551e030 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Mon Oct 14 13:12:22 2013 -0500
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Tue Oct 15 20:30:43 2013 +0800
@@ -53,33 +53,33 @@
     , m_pcBinIf(NULL)
     , m_uiCoeffCost(0)
     , m_numContextModels(0)
-    , m_cCUSplitFlagSCModel(1,             1,               NUM_SPLIT_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUSkipFlagSCModel(1,             1,               NUM_SKIP_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUMergeFlagExtSCModel(1,             1,               NUM_MERGE_FLAG_EXT_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUMergeIdxExtSCModel(1,             1,               NUM_MERGE_IDX_EXT_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUPartSizeSCModel(1,             1,               NUM_PART_SIZE_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUPredModeSCModel(1,             1,               NUM_PRED_MODE_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUIntraPredSCModel(1,             1,               NUM_ADI_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUChromaPredSCModel(1,             1,               NUM_CHROMA_PRED_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUDeltaQpSCModel(1,             1,               NUM_DELTA_QP_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUInterDirSCModel(1,             1,               NUM_INTER_DIR_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCURefPicSCModel(1,             1,               NUM_REF_NO_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUMvdSCModel(1,             1,               NUM_MV_RES_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUQtCbfSCModel(1,             2,               NUM_QT_CBF_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUTransSubdivFlagSCModel(1,             1,               NUM_TRANS_SUBDIV_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUQtRootCbfSCModel(1,             1,               NUM_QT_ROOT_CBF_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUSigCoeffGroupSCModel(1,             2,               NUM_SIG_CG_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUSigSCModel(1,             1,               NUM_SIG_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCuCtxLastX(1,             2,               NUM_CTX_LAST_FLAG_XY, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCuCtxLastY(1,             2,               NUM_CTX_LAST_FLAG_XY, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUOneSCModel(1,             1,               NUM_ONE_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUAbsSCModel(1,             1,               NUM_ABS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cMVPIdxSCModel(1,             1,               NUM_MVP_IDX_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cCUAMPSCModel(1,             1,               NUM_CU_AMP_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cSaoMergeSCModel(1,             1,               NUM_SAO_MERGE_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cSaoTypeIdxSCModel(1,             1,               NUM_SAO_TYPE_IDX_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_cTransformSkipSCModel(1,             2,               NUM_TRANSFORMSKIP_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
-    , m_CUTransquantBypassFlagSCModel(1,          1,               NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUSplitFlagSCModel(1,          NUM_SPLIT_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUSkipFlagSCModel(1,           NUM_SKIP_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUMergeFlagExtSCModel(1,       NUM_MERGE_FLAG_EXT_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUMergeIdxExtSCModel(1,        NUM_MERGE_IDX_EXT_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUPartSizeSCModel(1,           NUM_PART_SIZE_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUPredModeSCModel(1,           NUM_PRED_MODE_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUIntraPredSCModel(1,          NUM_ADI_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUChromaPredSCModel(1,         NUM_CHROMA_PRED_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUDeltaQpSCModel(1,            NUM_DELTA_QP_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUInterDirSCModel(1,           NUM_INTER_DIR_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCURefPicSCModel(1,             NUM_REF_NO_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUMvdSCModel(1,                NUM_MV_RES_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUQtCbfSCModel(2,              NUM_QT_CBF_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUTransSubdivFlagSCModel(1,    NUM_TRANS_SUBDIV_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUQtRootCbfSCModel(1,          NUM_QT_ROOT_CBF_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUSigCoeffGroupSCModel(2,      NUM_SIG_CG_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUSigSCModel(1,                NUM_SIG_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCuCtxLastX(2,                  NUM_CTX_LAST_FLAG_XY, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCuCtxLastY(2,                  NUM_CTX_LAST_FLAG_XY, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUOneSCModel(1,                NUM_ONE_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUAbsSCModel(1,                NUM_ABS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cMVPIdxSCModel(1,               NUM_MVP_IDX_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cCUAMPSCModel(1,                NUM_CU_AMP_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cSaoMergeSCModel(1,             NUM_SAO_MERGE_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cSaoTypeIdxSCModel(1,           NUM_SAO_TYPE_IDX_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_cTransformSkipSCModel(2,        NUM_TRANSFORMSKIP_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
+    , m_CUTransquantBypassFlagSCModel(1,NUM_CU_TRANSQUANT_BYPASS_FLAG_CTX, m_contextModels + m_numContextModels, m_numContextModels)
 {
     assert(m_numContextModels <= MAX_NUM_CTX_MOD);
 }
@@ -398,7 +398,7 @@
     int iSymbol = cu->getMVPIdx(eRefList, absPartIdx);
     int iNum = AMVP_MAX_NUM_CANDS;
 
-    xWriteUnaryMaxSymbol(iSymbol, m_cMVPIdxSCModel.get(0), 1, iNum - 1);
+    xWriteUnaryMaxSymbol(iSymbol, &m_cMVPIdxSCModel.get(0), 1, iNum - 1);
 }
 
 void TEncSbac::codePartSize(TComDataCU* cu, UInt absPartIdx, UInt depth)
@@ -409,7 +409,7 @@
     {
         if (depth == g_maxCUDepth - g_addCUDepth)
         {
-            m_pcBinIf->encodeBin(partSize == SIZE_2Nx2N ? 1 : 0, m_cCUPartSizeSCModel.get(0, 0, 0));
+            m_pcBinIf->encodeBin(partSize == SIZE_2Nx2N ? 1 : 0, m_cCUPartSizeSCModel.get(0));
         }
         return;
     }
@@ -418,24 +418,24 @@
     {
     case SIZE_2Nx2N:
     {
-        m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get(0));
         break;
     }
     case SIZE_2NxN:
     case SIZE_2NxnU:
     case SIZE_2NxnD:
     {
-        m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0, 0, 0));
-        m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get(0, 0, 1));
+        m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0));
+        m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get(1));
         if (cu->getSlice()->getSPS()->getAMPAcc(depth))
         {
             if (partSize == SIZE_2NxN)
             {
-                m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get(0, 0, 0));
+                m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get(0));
             }
             else
             {
-                m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get(0, 0, 0));
+                m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get(0));
                 m_pcBinIf->encodeBinEP((partSize == SIZE_2NxnU ? 0 : 1));
             }
         }
@@ -445,21 +445,21 @@
     case SIZE_nLx2N:
     case SIZE_nRx2N:
     {
-        m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0, 0, 0));
-        m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0, 0, 1));
+        m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0));
+        m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(1));
         if (depth == g_maxCUDepth - g_addCUDepth && !(cu->getWidth(absPartIdx) == 8 && cu->getHeight(absPartIdx) == 8))
         {
-            m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get(0, 0, 2));
+            m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get(2));
         }
         if (cu->getSlice()->getSPS()->getAMPAcc(depth))
         {
             if (partSize == SIZE_Nx2N)
             {
-                m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get(0, 0, 0));
+                m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get(0));
             }
             else
             {
-                m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get(0, 0, 0));
+                m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get(0));
                 m_pcBinIf->encodeBinEP((partSize == SIZE_nLx2N ? 0 : 1));
             }
         }
@@ -469,9 +469,9 @@
     {
         if (depth == g_maxCUDepth - g_addCUDepth && !(cu->getWidth(absPartIdx) == 8 && cu->getHeight(absPartIdx) == 8))
         {
-            m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0, 0, 0));
-            m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0, 0, 1));
-            m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0, 0, 2));
+            m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(0));
+            m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(1));
+            m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get(2));
         }
         break;
     }
@@ -492,14 +492,14 @@
     // get context function is here
     int iPredMode = cu->getPredictionMode(absPartIdx);
 
-    m_pcBinIf->encodeBin(iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get(0, 0, 0));
+    m_pcBinIf->encodeBin(iPredMode == MODE_INTER ? 0 : 1, m_cCUPredModeSCModel.get(0));
 }
 
 void TEncSbac::codeCUTransquantBypassFlag(TComDataCU* cu, UInt absPartIdx)
 {
     UInt uiSymbol = cu->getCUTransquantBypass(absPartIdx);
 
-    m_pcBinIf->encodeBin(uiSymbol, m_CUTransquantBypassFlagSCModel.get(0, 0, 0));
+    m_pcBinIf->encodeBin(uiSymbol, m_CUTransquantBypassFlagSCModel.get(0));
 }
 
 /** code skip flag
@@ -513,7 +513,7 @@
     UInt uiSymbol = cu->isSkipped(absPartIdx) ? 1 : 0;
     UInt uiCtxSkip = cu->getCtxSkipFlag(absPartIdx);
 
-    m_pcBinIf->encodeBin(uiSymbol, m_cCUSkipFlagSCModel.get(0, 0, uiCtxSkip));
+    m_pcBinIf->encodeBin(uiSymbol, m_cCUSkipFlagSCModel.get(uiCtxSkip));
     DTRACE_CABAC_VL(g_nSymbolCounter++);
     DTRACE_CABAC_T("\tSkipFlag");
     DTRACE_CABAC_T("\tuiCtxSkip: ");
@@ -532,7 +532,7 @@
 {
     const UInt uiSymbol = cu->getMergeFlag(absPartIdx) ? 1 : 0;
 
-    m_pcBinIf->encodeBin(uiSymbol, *m_cCUMergeFlagExtSCModel.get(0));
+    m_pcBinIf->encodeBin(uiSymbol, m_cCUMergeFlagExtSCModel.get(0));
 
     DTRACE_CABAC_VL(g_nSymbolCounter++);
     DTRACE_CABAC_T("\tMergeFlag: ");
@@ -561,7 +561,7 @@
             const UInt uiSymbol = ui == uiUnaryIdx ? 0 : 1;
             if (ui == 0)
             {
-                m_pcBinIf->encodeBin(uiSymbol, m_cCUMergeIdxExtSCModel.get(0, 0, 0));
+                m_pcBinIf->encodeBin(uiSymbol, m_cCUMergeIdxExtSCModel.get(0));
             }
             else
             {
@@ -589,14 +589,14 @@
     UInt uiCurrSplitFlag = (cu->getDepth(absPartIdx) > depth) ? 1 : 0;
 
     assert(uiCtx < 3);
-    m_pcBinIf->encodeBin(uiCurrSplitFlag, m_cCUSplitFlagSCModel.get(0, 0, uiCtx));
+    m_pcBinIf->encodeBin(uiCurrSplitFlag, m_cCUSplitFlagSCModel.get(uiCtx));
     DTRACE_CABAC_VL(g_nSymbolCounter++)
     DTRACE_CABAC_T("\tSplitFlag\n")
 }
 
 void TEncSbac::codeTransformSubdivFlag(UInt uiSymbol, UInt uiCtx)
 {
-    m_pcBinIf->encodeBin(uiSymbol, m_cCUTransSubdivFlagSCModel.get(0, 0, uiCtx));
+    m_pcBinIf->encodeBin(uiSymbol, m_cCUTransSubdivFlagSCModel.get(uiCtx));
     DTRACE_CABAC_VL(g_nSymbolCounter++)
     DTRACE_CABAC_T("\tparseTransformSubdivFlag()")
     DTRACE_CABAC_T("\tsymbol=")
@@ -627,7 +627,7 @@
             }
         }
 
-        m_pcBinIf->encodeBin((predIdx[j] != -1) ? 1 : 0, m_cCUIntraPredSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin((predIdx[j] != -1) ? 1 : 0, m_cCUIntraPredSCModel.get(0));
     }
 
     for (j = 0; j < partNum; j++)
@@ -670,7 +670,7 @@
 
     if (uiIntraDirChroma == DM_CHROMA_IDX)
     {
-        m_pcBinIf->encodeBin(0, m_cCUChromaPredSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin(0, m_cCUChromaPredSCModel.get(0));
     }
     else
     {
@@ -686,7 +686,7 @@
             }
         }
 
-        m_pcBinIf->encodeBin(1, m_cCUChromaPredSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin(1, m_cCUChromaPredSCModel.get(0));
 
         m_pcBinIf->encodeBinsEP(uiIntraDirChroma, 2);
     }
@@ -696,15 +696,14 @@
 {
     const UInt uiInterDir = cu->getInterDir(absPartIdx) - 1;
     const UInt uiCtx      = cu->getCtxInterDir(absPartIdx);
-    ContextModel *pCtx    = m_cCUInterDirSCModel.get(0);
 
     if (cu->getPartitionSize(absPartIdx) == SIZE_2Nx2N || cu->getHeight(absPartIdx) != 8)
     {
-        m_pcBinIf->encodeBin(uiInterDir == 2 ? 1 : 0, *(pCtx + uiCtx));
+        m_pcBinIf->encodeBin(uiInterDir == 2 ? 1 : 0, m_cCUInterDirSCModel.get(uiCtx));
     }
     if (uiInterDir < 2)
     {
-        m_pcBinIf->encodeBin(uiInterDir, *(pCtx + 4));
+        m_pcBinIf->encodeBin(uiInterDir, m_cCUInterDirSCModel.get(4));
     }
 }
 
@@ -712,20 +711,20 @@
 {
     {
         int iRefFrame = cu->getCUMvField(eRefList)->getRefIdx(absPartIdx);
-        ContextModel *pCtx = m_cCURefPicSCModel.get(0);
-        m_pcBinIf->encodeBin((iRefFrame == 0 ? 0 : 1), *pCtx);
+        int idx = 0;
+        m_pcBinIf->encodeBin((iRefFrame == 0 ? 0 : 1), m_cCURefPicSCModel.get(0));
 
         if (iRefFrame > 0)
         {
             UInt uiRefNum = cu->getSlice()->getNumRefIdx(eRefList) - 2;
-            pCtx++;
+            idx++;
             iRefFrame--;
             for (UInt ui = 0; ui < uiRefNum; ++ui)
             {
                 const UInt uiSymbol = ui == iRefFrame ? 0 : 1;
                 if (ui == 0)
                 {
-                    m_pcBinIf->encodeBin(uiSymbol, *pCtx);
+                    m_pcBinIf->encodeBin(uiSymbol, m_cCURefPicSCModel.get(idx));
                 }
                 else
                 {
@@ -750,25 +749,23 @@
     const TComCUMvField* pcCUMvField = cu->getCUMvField(eRefList);
     const int iHor = pcCUMvField->getMvd(absPartIdx).x;
     const int iVer = pcCUMvField->getMvd(absPartIdx).y;
-    ContextModel* pCtx = m_cCUMvdSCModel.get(0);
 
-    m_pcBinIf->encodeBin(iHor != 0 ? 1 : 0, *pCtx);
-    m_pcBinIf->encodeBin(iVer != 0 ? 1 : 0, *pCtx);
+    m_pcBinIf->encodeBin(iHor != 0 ? 1 : 0, m_cCUMvdSCModel.get(0));
+    m_pcBinIf->encodeBin(iVer != 0 ? 1 : 0, m_cCUMvdSCModel.get(0));
 
     const bool bHorAbsGr0 = iHor != 0;
     const bool bVerAbsGr0 = iVer != 0;
     const UInt uiHorAbs   = 0 > iHor ? -iHor : iHor;
     const UInt uiVerAbs   = 0 > iVer ? -iVer : iVer;
-    pCtx++;
 
     if (bHorAbsGr0)
     {
-        m_pcBinIf->encodeBin(uiHorAbs > 1 ? 1 : 0, *pCtx);
+        m_pcBinIf->encodeBin(uiHorAbs > 1 ? 1 : 0, m_cCUMvdSCModel.get(1));
     }
 
     if (bVerAbsGr0)
     {
-        m_pcBinIf->encodeBin(uiVerAbs > 1 ? 1 : 0, *pCtx);
+        m_pcBinIf->encodeBin(uiVerAbs > 1 ? 1 : 0, m_cCUMvdSCModel.get(1));
     }
 
     if (bHorAbsGr0)
@@ -802,7 +799,7 @@
 
     UInt uiAbsDQp = (UInt)((iDQp > 0) ? iDQp  : (-iDQp));
     UInt TUValue = X265_MIN((int)uiAbsDQp, CU_DQP_TU_CMAX);
-    xWriteUnaryMaxSymbol(TUValue, &m_cCUDeltaQpSCModel.get(0, 0, 0), 1, CU_DQP_TU_CMAX);
+    xWriteUnaryMaxSymbol(TUValue, &m_cCUDeltaQpSCModel.get(0), 1, CU_DQP_TU_CMAX);
     if (uiAbsDQp >= CU_DQP_TU_CMAX)
     {
         xWriteEpExGolomb(uiAbsDQp - CU_DQP_TU_CMAX, CU_DQP_EG_k);
@@ -820,7 +817,7 @@
     UInt uiCbf = cu->getCbf(absPartIdx, ttype, trDepth);
     UInt uiCtx = cu->getCtxQtCbf(ttype, trDepth);
 
-    m_pcBinIf->encodeBin(uiCbf, m_cCUQtCbfSCModel.get(0, ttype ? TEXT_CHROMA : ttype, uiCtx));
+    m_pcBinIf->encodeBin(uiCbf, m_cCUQtCbfSCModel.get((ttype ? TEXT_CHROMA : 0) * NUM_QT_CBF_CTX + uiCtx));
     DTRACE_CABAC_VL(g_nSymbolCounter++)
     DTRACE_CABAC_T("\tparseQtCbf()")
     DTRACE_CABAC_T("\tsymbol=")
@@ -846,7 +843,7 @@
     }
 
     UInt useTransformSkip = cu->getTransformSkip(absPartIdx, eTType);
-    m_pcBinIf->encodeBin(useTransformSkip, m_cTransformSkipSCModel.get(0, eTType ? TEXT_CHROMA : TEXT_LUMA, 0));
+    m_pcBinIf->encodeBin(useTransformSkip, m_cTransformSkipSCModel.get((eTType ? TEXT_CHROMA : TEXT_LUMA) * NUM_TRANSFORMSKIP_FLAG_CTX));
     DTRACE_CABAC_VL(g_nSymbolCounter++)
     DTRACE_CABAC_T("\tparseTransformSkip()");
     DTRACE_CABAC_T("\tsymbol=")
@@ -946,7 +943,7 @@
     UInt uiCbf = cu->getQtRootCbf(absPartIdx);
     UInt uiCtx = 0;
 
-    m_pcBinIf->encodeBin(uiCbf, m_cCUQtRootCbfSCModel.get(0, 0, uiCtx));
+    m_pcBinIf->encodeBin(uiCbf, m_cCUQtRootCbfSCModel.get(uiCtx));
     DTRACE_CABAC_VL(g_nSymbolCounter++)
     DTRACE_CABAC_T("\tparseQtRootCbf()")
     DTRACE_CABAC_T("\tsymbol=")
@@ -965,7 +962,7 @@
     UInt cbf = 0;
     UInt ctx = cu->getCtxQtCbf(ttype, trDepth);
 
-    m_pcBinIf->encodeBin(cbf, m_cCUQtCbfSCModel.get(0, ttype ? TEXT_CHROMA : ttype, ctx));
+    m_pcBinIf->encodeBin(cbf, m_cCUQtCbfSCModel.get((ttype ? TEXT_CHROMA : 0) * NUM_QT_CBF_CTX + ctx));
 }
 
 void TEncSbac::codeQtRootCbfZero(TComDataCU*)
@@ -975,7 +972,7 @@
     UInt cbf = 0;
     UInt ctx = 0;
 
-    m_pcBinIf->encodeBin(cbf, m_cCUQtRootCbfSCModel.get(0, 0, ctx));
+    m_pcBinIf->encodeBin(cbf, m_cCUQtRootCbfSCModel.get(ctx));
 }
 
 /** Encode (X,Y) position of the last significant coefficient
@@ -989,6 +986,7 @@
  */
 void TEncSbac::codeLastSignificantXY(UInt posx, UInt posy, int width, int height, TextType eTType, UInt uiScanIdx)
 {
+    assert((eTType == TEXT_LUMA) || (eTType == TEXT_CHROMA));
     // swap
     if (uiScanIdx == SCAN_VER)
     {
@@ -996,8 +994,8 @@
     }
 
     UInt uiCtxLast;
-    ContextModel *pCtxX = m_cCuCtxLastX.get(0, eTType);
-    ContextModel *pCtxY = m_cCuCtxLastY.get(0, eTType);
+    ContextModel *pCtxX = &m_cCuCtxLastX.get(eTType ? NUM_CTX_LAST_FLAG_XY : 0);
+    ContextModel *pCtxY = &m_cCuCtxLastY.get(eTType ? NUM_CTX_LAST_FLAG_XY : 0);
     UInt uiGroupIdxX    = g_groupIdx[posx];
     UInt uiGroupIdxY    = g_groupIdx[posy];
 
@@ -1089,7 +1087,7 @@
     {
         codeTransformSkipFlags(cu, absPartIdx, width, height, eTType);
     }
-    eTType = eTType == TEXT_LUMA ? TEXT_LUMA : (eTType == TEXT_NONE ? TEXT_NONE : TEXT_CHROMA);
+    eTType = eTType == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA ;
 
     //----- encode significance map -----
     const UInt   uiLog2BlockSize = g_convertToBit[width] + 2;
@@ -1151,8 +1149,8 @@
     codeLastSignificantXY(posLastX, posLastY, width, height, eTType, uiScanIdx);
 
     //===== code significance flag =====
-    ContextModel * const baseCoeffGroupCtx = m_cCUSigCoeffGroupSCModel.get(0, eTType);
-    ContextModel * const baseCtx = (eTType == TEXT_LUMA) ? m_cCUSigSCModel.get(0, 0) : m_cCUSigSCModel.get(0, 0) + NUM_SIG_FLAG_CTX_LUMA;
+    ContextModel * const baseCoeffGroupCtx = &m_cCUSigCoeffGroupSCModel.get(eTType ? NUM_SIG_CG_FLAG_CTX : 0);
+    ContextModel * const baseCtx = (eTType == TEXT_LUMA) ? &m_cCUSigSCModel.get(0) : &m_cCUSigSCModel.get(NUM_SIG_FLAG_CTX_LUMA);
 
     const int  iLastScanSet      = scanPosLast >> LOG2_SCAN_SET_SIZE;
     UInt c1 = 1;
@@ -1238,7 +1236,7 @@
                 uiCtxSet++;
             }
             c1 = 1;
-            ContextModel *baseCtxMod = (eTType == TEXT_LUMA) ? m_cCUOneSCModel.get(0, 0) + 4 * uiCtxSet : m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet;
+            ContextModel *baseCtxMod = (eTType == TEXT_LUMA) ? &m_cCUOneSCModel.get(4 * uiCtxSet) : &m_cCUOneSCModel.get(NUM_ONE_FLAG_CTX_LUMA + 4 * uiCtxSet);
 
             int numC1Flag = X265_MIN(numNonZero, C1FLAG_NUMBER);
             int firstC2FlagIdx = -1;
@@ -1263,7 +1261,7 @@
 
             if (c1 == 0)
             {
-                baseCtxMod = (eTType == TEXT_LUMA) ? m_cCUAbsSCModel.get(0, 0) + uiCtxSet : m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA + uiCtxSet;
+                baseCtxMod = (eTType == TEXT_LUMA) ? &m_cCUAbsSCModel.get(uiCtxSet) : &m_cCUAbsSCModel.get(NUM_ABS_FLAG_CTX_LUMA + uiCtxSet);
                 if (firstC2FlagIdx != -1)
                 {
                     UInt symbol = absCoeff[firstC2FlagIdx] > 2;
@@ -1359,11 +1357,11 @@
 {
     if (uiCode == 0)
     {
-        m_pcBinIf->encodeBin(0,  m_cSaoMergeSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin(0,  m_cSaoMergeSCModel.get(0));
     }
     else
     {
-        m_pcBinIf->encodeBin(1,  m_cSaoMergeSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin(1,  m_cSaoMergeSCModel.get(0));
     }
 }
 
@@ -1374,11 +1372,11 @@
 {
     if (uiCode == 0)
     {
-        m_pcBinIf->encodeBin(0, m_cSaoTypeIdxSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin(0, m_cSaoTypeIdxSCModel.get(0));
     }
     else
     {
-        m_pcBinIf->encodeBin(1, m_cSaoTypeIdxSCModel.get(0, 0, 0));
+        m_pcBinIf->encodeBin(1, m_cSaoTypeIdxSCModel.get(0));
         m_pcBinIf->encodeBinEP(uiCode <= 4 ? 1 : 0);
     }
 }
@@ -1410,7 +1408,7 @@
  */
 void TEncSbac::estCBFBit(estBitsSbacStruct* pcEstBitsSbac)
 {
-    ContextModel *pCtx = m_cCUQtCbfSCModel.get(0);
+    ContextModel *pCtx = &m_cCUQtCbfSCModel.get(0);
 
     for (UInt uiCtxInc = 0; uiCtxInc < 3 * NUM_QT_CBF_CTX; uiCtxInc++)
     {
@@ -1418,7 +1416,7 @@
         pcEstBitsSbac->blockCbpBits[uiCtxInc][1] = pCtx[uiCtxInc].getEntropyBits(1);
     }
 
-    pCtx = m_cCUQtRootCbfSCModel.get(0);
+    pCtx = &m_cCUQtRootCbfSCModel.get(0);
 
     for (UInt uiCtxInc = 0; uiCtxInc < 4; uiCtxInc++)
     {
@@ -1435,13 +1433,14 @@
  */
 void TEncSbac::estSignificantCoeffGroupMapBit(estBitsSbacStruct* pcEstBitsSbac, TextType eTType)
 {
+    assert((eTType == TEXT_LUMA) || (eTType == TEXT_CHROMA));
     int firstCtx = 0, numCtx = NUM_SIG_CG_FLAG_CTX;
 
     for (int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++)
     {
         for (UInt uiBin = 0; uiBin < 2; uiBin++)
         {
-            pcEstBitsSbac->significantCoeffGroupBits[ctxIdx][uiBin] = m_cCUSigCoeffGroupSCModel.get(0, eTType, ctxIdx).getEntropyBits(uiBin);
+            pcEstBitsSbac->significantCoeffGroupBits[ctxIdx][uiBin] = m_cCUSigCoeffGroupSCModel.get((eTType ? NUM_SIG_CG_FLAG_CTX : 0) + ctxIdx).getEntropyBits(uiBin);
         }
     }
 }
@@ -1471,14 +1470,14 @@
     {
         for (UInt bin = 0; bin < 2; bin++)
         {
-            pcEstBitsSbac->significantBits[0][bin] = m_cCUSigSCModel.get(0, 0, 0).getEntropyBits(bin);
+            pcEstBitsSbac->significantBits[0][bin] = m_cCUSigSCModel.get(0).getEntropyBits(bin);
         }
 
         for (int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++)
         {
             for (UInt uiBin = 0; uiBin < 2; uiBin++)
             {
-                pcEstBitsSbac->significantBits[ctxIdx][uiBin] = m_cCUSigSCModel.get(0, 0, ctxIdx).getEntropyBits(uiBin);
+                pcEstBitsSbac->significantBits[ctxIdx][uiBin] = m_cCUSigSCModel.get(ctxIdx).getEntropyBits(uiBin);
             }
         }
     }
@@ -1486,14 +1485,14 @@
     {
         for (UInt bin = 0; bin < 2; bin++)
         {
-            pcEstBitsSbac->significantBits[0][bin] = m_cCUSigSCModel.get(0, 0, NUM_SIG_FLAG_CTX_LUMA + 0).getEntropyBits(bin);
+            pcEstBitsSbac->significantBits[0][bin] = m_cCUSigSCModel.get(NUM_SIG_FLAG_CTX_LUMA + 0).getEntropyBits(bin);
         }
 
         for (int ctxIdx = firstCtx; ctxIdx < firstCtx + numCtx; ctxIdx++)
         {
             for (UInt uiBin = 0; uiBin < 2; uiBin++)
             {
-                pcEstBitsSbac->significantBits[ctxIdx][uiBin] = m_cCUSigSCModel.get(0, 0, NUM_SIG_FLAG_CTX_LUMA + ctxIdx).getEntropyBits(uiBin);
+                pcEstBitsSbac->significantBits[ctxIdx][uiBin] = m_cCUSigSCModel.get(NUM_SIG_FLAG_CTX_LUMA + ctxIdx).getEntropyBits(uiBin);
             }
         }
     }
@@ -1505,22 +1504,21 @@
     shiftX = eTType ? g_convertToBit[width] : ((g_convertToBit[width] + 3) >> 2);
     shiftY = eTType ? g_convertToBit[height] : ((g_convertToBit[height] + 3) >> 2);
 
+    assert((eTType == TEXT_LUMA) || (eTType == TEXT_CHROMA));
     int ctx;
-    ContextModel *pCtxX      = m_cCuCtxLastX.get(0, eTType);
     for (ctx = 0; ctx < g_groupIdx[width - 1]; ctx++)
     {
         int ctxOffset = blkSizeOffsetX + (ctx >> shiftX);
-        pcEstBitsSbac->lastXBits[ctx] = iBitsX + pCtxX[ctxOffset].getEntropyBits(0);
-        iBitsX += pCtxX[ctxOffset].getEntropyBits(1);
+        pcEstBitsSbac->lastXBits[ctx] = iBitsX + m_cCuCtxLastX.get((eTType ? NUM_CTX_LAST_FLAG_XY : 0) + ctxOffset).getEntropyBits(0);
+        iBitsX += m_cCuCtxLastX.get((eTType ? NUM_CTX_LAST_FLAG_XY : 0) + ctxOffset).getEntropyBits(1);
     }
 
     pcEstBitsSbac->lastXBits[ctx] = iBitsX;
-    ContextModel *pCtxY      = m_cCuCtxLastY.get(0, eTType);
     for (ctx = 0; ctx < g_groupIdx[height - 1]; ctx++)
     {
         int ctxOffset = blkSizeOffsetY + (ctx >> shiftY);
-        pcEstBitsSbac->lastYBits[ctx] = iBitsY + pCtxY[ctxOffset].getEntropyBits(0);
-        iBitsY += pCtxY[ctxOffset].getEntropyBits(1);
+        pcEstBitsSbac->lastYBits[ctx] = iBitsY + m_cCuCtxLastY.get((eTType ? NUM_CTX_LAST_FLAG_XY : 0) + ctxOffset).getEntropyBits(0);
+        iBitsY += m_cCuCtxLastY.get((eTType ? NUM_CTX_LAST_FLAG_XY : 0) + ctxOffset).getEntropyBits(1);
     }
 
     pcEstBitsSbac->lastYBits[ctx] = iBitsY;
@@ -1536,8 +1534,8 @@
 {
     if (eTType == TEXT_LUMA)
     {
-        ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0);
-        ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0);
+        ContextModel *ctxOne = &m_cCUOneSCModel.get(0);
+        ContextModel *ctxAbs = &m_cCUAbsSCModel.get(0);
 
         for (int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_LUMA; ctxIdx++)
         {
@@ -1553,8 +1551,8 @@
     }
     else
     {
-        ContextModel *ctxOne = m_cCUOneSCModel.get(0, 0) + NUM_ONE_FLAG_CTX_LUMA;
-        ContextModel *ctxAbs = m_cCUAbsSCModel.get(0, 0) + NUM_ABS_FLAG_CTX_LUMA;
+        ContextModel *ctxOne = &m_cCUOneSCModel.get(NUM_ONE_FLAG_CTX_LUMA);
+        ContextModel *ctxAbs = &m_cCUAbsSCModel.get(NUM_ABS_FLAG_CTX_LUMA);
 
         for (int ctxIdx = 0; ctxIdx < NUM_ONE_FLAG_CTX_CHROMA; ctxIdx++)
         {



More information about the x265-devel mailing list