[x265] [PATCH] improvement getSigCoeffGroupCtxInc by merge pointer calculate

Min Chen chenm003 at 163.com
Thu Oct 24 13:56:09 CEST 2013


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1382615758 -28800
# Node ID 8430c3486b416687a25e37c60090a2358ceec47e
# Parent  d088c6af083c273b91b5b50e4db1cf5e367f9adc
improvement getSigCoeffGroupCtxInc by merge pointer calculate

diff -r d088c6af083c -r 8430c3486b41 source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Thu Oct 24 19:33:15 2013 +0800
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Thu Oct 24 19:55:58 2013 +0800
@@ -730,7 +730,7 @@
             {
                 if (sigCoeffGroupFlag[cgBlkPos] == 0)
                 {
-                    UInt  ctxSig = getSigCoeffGroupCtxInc(sigCoeffGroupFlag, cgPosX, cgPosY, width, height);
+                    UInt  ctxSig = getSigCoeffGroupCtxInc(sigCoeffGroupFlag, cgPosX, cgPosY, log2BlkSize);
                     baseCost += xGetRateSigCoeffGroup(0, ctxSig) - rdStats.sigCost;
                     costCoeffGroupSig[cgScanPos] = xGetRateSigCoeffGroup(0, ctxSig);
                 }
@@ -747,7 +747,7 @@
                         double costZeroCG = baseCost;
 
                         // add SigCoeffGroupFlag cost to total cost
-                        UInt  ctxSig = getSigCoeffGroupCtxInc(sigCoeffGroupFlag, cgPosX, cgPosY, width, height);
+                        UInt  ctxSig = getSigCoeffGroupCtxInc(sigCoeffGroupFlag, cgPosX, cgPosY, log2BlkSize);
                         if (cgScanPos < cgLastScanPos)
                         {
                             baseCost  += xGetRateSigCoeffGroup(1, ctxSig);
@@ -1351,23 +1351,20 @@
  * \param uiLog2BlkSize log2 value of block size
  * \returns ctxInc for current scan position
  */
-UInt TComTrQuant::getSigCoeffGroupCtxInc(const UInt* sigCoeffGroupFlag, UInt cgPosX, UInt cgPosY,
-                                         int width, int height)
+UInt TComTrQuant::getSigCoeffGroupCtxInc(const UInt* sigCoeffGroupFlag, UInt cgPosX, UInt cgPosY, int log2BlockSize)
 {
-    UInt right = 0;
-    UInt lower = 0;
+    log2BlockSize -= 2;
 
-    width >>= 2;
-    height >>= 2;
-    if (cgPosX < width - 1)
-    {
-        right = (sigCoeffGroupFlag[cgPosY * width + cgPosX + 1] != 0);
-    }
-    if (cgPosY < height - 1)
-    {
-        lower = (sigCoeffGroupFlag[(cgPosY  + 1) * width + cgPosX] != 0);
-    }
-    return right || lower;
+    const int size = (1 << log2BlockSize);
+    const UInt* sigPos = &sigCoeffGroupFlag[(cgPosY << log2BlockSize) + cgPosX];
+
+    assert(sigPos[1] <= 1);
+    assert(sigPos[size] <= 1);
+
+    UInt sigRight = (cgPosX == size - 1) ? 0 : (sigPos[1]);
+    UInt sigLower = (cgPosY == size - 1) ? 0 : (sigPos[size]);
+
+    return sigRight | sigLower;
 }
 
 /** set quantized matrix coefficient for encode
diff -r d088c6af083c -r 8430c3486b41 source/Lib/TLibCommon/TComTrQuant.h
--- a/source/Lib/TLibCommon/TComTrQuant.h	Thu Oct 24 19:33:15 2013 +0800
+++ b/source/Lib/TLibCommon/TComTrQuant.h	Thu Oct 24 19:55:58 2013 +0800
@@ -164,7 +164,7 @@
 
     static int  getSigCtxInc(int patternSigCtx, UInt scanIdx, int posX, int posY, int log2BlkSize, TextType ttype);
 
-    static UInt getSigCoeffGroupCtxInc(const UInt* sigCoeffGroupFlag, UInt cGPosX, UInt cGPosY, int width, int height);
+    static UInt getSigCoeffGroupCtxInc(const UInt* sigCoeffGroupFlag, UInt cGPosX, UInt cGPosY, int log2BlockSize);
 
     estBitsSbacStruct* m_estBitsSbac;
 
diff -r d088c6af083c -r 8430c3486b41 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Thu Oct 24 19:33:15 2013 +0800
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Thu Oct 24 19:55:58 2013 +0800
@@ -2321,7 +2321,7 @@
         else
         {
             UInt sigCoeffGroup = (sigCoeffGroupFlag[cgBlkPos] != 0);
-            UInt ctxSig = TComTrQuant::getSigCoeffGroupCtxInc(sigCoeffGroupFlag, cgPosX, cgPosY, width, height);
+            UInt ctxSig = TComTrQuant::getSigCoeffGroupCtxInc(sigCoeffGroupFlag, cgPosX, cgPosY, log2BlockSize);
             m_binIf->encodeBin(sigCoeffGroup, baseCoeffGroupCtx[ctxSig]);
         }
 



More information about the x265-devel mailing list