[x265] [PATCH 7 of 7] cleanup on TComTrQuant::getTUEntropyCodingParameters

Min Chen chenm003 at 163.com
Mon Mar 24 20:00:44 CET 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1395687606 25200
# Node ID 6d4a78f0c1b603370fcebafa70eee2f2dffdc11a
# Parent  5d22c7cd7cd603a3481720dd2467865012e39d37
cleanup on TComTrQuant::getTUEntropyCodingParameters

diff -r 5d22c7cd7cd6 -r 6d4a78f0c1b6 source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Mon Mar 24 11:59:50 2014 -0700
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Mon Mar 24 12:00:06 2014 -0700
@@ -486,41 +486,6 @@
     }
 }
 
-void TComTrQuant::getTUEntropyCodingParameters(TComDataCU*                cu,
-                                               TUEntropyCodingParameters &result,
-                                               uint32_t                   absPartIdx,
-                                               uint32_t                   log2TrSize,
-                                               TextType                   ttype)
-{
-    //set the group layout
-    const uint32_t log2TrSizeCG = log2TrSize - MLS_CG_LOG2_SIZE;
-    result.log2TrSize   = log2TrSize;
-    result.log2TrSizeCG = log2TrSizeCG;
-
-    //set the scan orders
-    result.scanType = COEFF_SCAN_TYPE(cu->getCoefScanIdx(absPartIdx, log2TrSize, ttype == TEXT_LUMA, cu->isIntra(absPartIdx)));
-    result.scan   = g_scanOrder[SCAN_GROUPED_4x4][result.scanType][log2TrSize];
-    result.scanCG = g_scanOrder[SCAN_UNGROUPED][result.scanType][log2TrSizeCG];
-
-    //set the significance map context selection parameters
-    TextType ctype = ttype == TEXT_LUMA ? TEXT_LUMA : TEXT_CHROMA;
-    result.ctype = ctype;
-    if (log2TrSize == 2)
-    {
-        result.firstSignificanceMapContext = significanceMapContextSetStart[ctype][CONTEXT_TYPE_4x4];
-    }
-    else if (log2TrSize == 3)
-    {
-        result.firstSignificanceMapContext = significanceMapContextSetStart[ctype][CONTEXT_TYPE_8x8];
-        if (result.scanType != SCAN_DIAG)
-            result.firstSignificanceMapContext += nonDiagonalScan8x8ContextOffset[ctype];
-    }
-    else
-    {
-        result.firstSignificanceMapContext = significanceMapContextSetStart[ctype][CONTEXT_TYPE_NxN];
-    }
-}
-
 /** RDOQ with CABAC
  * \param cu pointer to coding unit structure
  * \param plSrcCoeff pointer to input buffer
@@ -643,7 +608,8 @@
                 }
                 else
                 {
-                    const uint32_t ctxSig = getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, codingParameters);
+                    // NOTE: ttype is different to ctype, but getSigCtxInc may safety use it 
+                    const uint32_t ctxSig = getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, ttype, codingParameters.firstSignificanceMapContext);
                     if (maxAbsLevel < 3)
                     {
                         costSig[scanPos] = xGetRateSigCoef(0, ctxSig);
@@ -1055,7 +1021,8 @@
                                    const uint32_t                   log2TrSize,
                                    const uint32_t                   trSize,
                                    const uint32_t                   blkPos,
-                                   const TUEntropyCodingParameters &codingParameters)
+                                   const TextType                   ctype,
+                                   const uint32_t                   firstSignificanceMapContext)
 {
     static const uint8_t ctxIndMap[16] =
     {
@@ -1114,11 +1081,11 @@
     };
 
     int cnt = table_cnt[patternSigCtx][posXinSubset][posYinSubset];
-    int offset = codingParameters.firstSignificanceMapContext;
+    int offset = firstSignificanceMapContext;
 
     offset += cnt;
 
-    return (codingParameters.ctype == TEXT_LUMA && (posX | posY) >= 4) ? 3 + offset : offset;
+    return (ctype == TEXT_LUMA && (posX | posY) >= 4) ? 3 + offset : offset;
 }
 
 /** Get the best level in RD sense
diff -r 5d22c7cd7cd6 -r 6d4a78f0c1b6 source/Lib/TLibCommon/TComTrQuant.h
--- a/source/Lib/TLibCommon/TComTrQuant.h	Mon Mar 24 11:59:50 2014 -0700
+++ b/source/Lib/TLibCommon/TComTrQuant.h	Mon Mar 24 12:00:06 2014 -0700
@@ -159,9 +159,42 @@
     void processScalingListEnc(int32_t *coeff, int32_t *quantcoeff, int quantScales, uint32_t height, uint32_t width, uint32_t ratio, int sizuNum, uint32_t dc);
     void processScalingListDec(int32_t *coeff, int32_t *dequantcoeff, int invQuantScales, uint32_t height, uint32_t width, uint32_t ratio, int sizuNum, uint32_t dc);
     static uint32_t calcPatternSigCtx(const uint64_t sigCoeffGroupFlag64, uint32_t cgPosX, uint32_t cgPosY, uint32_t log2TrSizeCG);
-    static uint32_t getSigCtxInc(uint32_t patternSigCtx, const uint32_t log2TrSize, const uint32_t trSize, const uint32_t blkPos, const TUEntropyCodingParameters &codingParameters);
+    static uint32_t getSigCtxInc(uint32_t patternSigCtx, const uint32_t log2TrSize, const uint32_t trSize, const uint32_t blkPos, const TextType ctype, const uint32_t firstSignificanceMapContext);
     static uint32_t getSigCoeffGroupCtxInc(const uint64_t sigCoeffGroupFlag64, uint32_t cgPosX, uint32_t cgPosY, const uint32_t log2TrSizeCG);
-    static void getTUEntropyCodingParameters(TComDataCU* cu, TUEntropyCodingParameters &result, uint32_t absPartIdx, uint32_t log2TrSize, TextType ttype);
+    inline static void getTUEntropyCodingParameters(TComDataCU* cu, TUEntropyCodingParameters &result, uint32_t absPartIdx, uint32_t log2TrSize, TextType ttype)
+    {
+        //set the group layout
+        const uint32_t log2TrSizeCG = log2TrSize - MLS_CG_LOG2_SIZE;
+        result.log2TrSizeCG = log2TrSizeCG;
+
+        //set the scan orders
+        result.scanType = COEFF_SCAN_TYPE(cu->getCoefScanIdx(absPartIdx, log2TrSize, ttype == TEXT_LUMA, cu->isIntra(absPartIdx)));
+        result.scan   = g_scanOrder[SCAN_GROUPED_4x4][result.scanType][log2TrSize];
+        result.scanCG = g_scanOrder[SCAN_UNGROUPED][result.scanType][log2TrSizeCG];
+
+        //set the significance map context selection parameters
+        TextType ctype = (ttype == TEXT_LUMA) ? TEXT_LUMA : TEXT_CHROMA;
+        if (log2TrSize == 2)
+        {
+            result.firstSignificanceMapContext = 0;
+            assert(significanceMapContextSetStart[ctype][CONTEXT_TYPE_4x4] == 0);
+        }
+        else if (log2TrSize == 3)
+        {
+            result.firstSignificanceMapContext = 9;
+            assert(significanceMapContextSetStart[ctype][CONTEXT_TYPE_8x8] == 9);
+            if (result.scanType != SCAN_DIAG && !ctype)
+            {
+                result.firstSignificanceMapContext += 6;
+                assert(nonDiagonalScan8x8ContextOffset[ctype] == 6);
+            }
+        }
+        else
+        {
+            result.firstSignificanceMapContext = (ctype ? 12 : 21);
+            assert(significanceMapContextSetStart[ctype][CONTEXT_TYPE_NxN] == (ctype ? 12 : 21));
+        }
+    }
     estBitsSbacStruct* m_estBitsSbac;
 
 protected:
diff -r 5d22c7cd7cd6 -r 6d4a78f0c1b6 source/Lib/TLibCommon/TypeDef.h
--- a/source/Lib/TLibCommon/TypeDef.h	Mon Mar 24 11:59:50 2014 -0700
+++ b/source/Lib/TLibCommon/TypeDef.h	Mon Mar 24 12:00:06 2014 -0700
@@ -176,8 +176,6 @@
     const uint16_t            *scan;
     const uint16_t            *scanCG;
     COEFF_SCAN_TYPE      scanType;
-    TextType             ctype;
-    uint32_t             log2TrSize;
     uint32_t             log2TrSizeCG;
     uint32_t             firstSignificanceMapContext;
 };
diff -r 5d22c7cd7cd6 -r 6d4a78f0c1b6 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Mon Mar 24 11:59:50 2014 -0700
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Mon Mar 24 12:00:06 2014 -0700
@@ -2172,7 +2172,7 @@
                 sig     = (coeff[blkPos] != 0);
                 if (scanPosSig > subPos || subSet == 0 || numNonZero)
                 {
-                    ctxSig  = TComTrQuant::getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, codingParameters);
+                    ctxSig  = TComTrQuant::getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, ttype, codingParameters.firstSignificanceMapContext);
                     m_binIf->encodeBin(sig, baseCtx[ctxSig]);
                 }
                 if (sig)



More information about the x265-devel mailing list