[x265] [PATCH 2 of 3] replace parameters (oneCtx, absCtx) by pointer m_estBitsSbac->

Min Chen chenm003 at 163.com
Wed Mar 19 01:34:03 CET 2014


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1395189216 25200
# Node ID e08877d1b13ae1cca82a5d63e26a9f4089e9a300
# Parent  e9f08d038ff0dc17152002d2b2b70138d08465d7
replace parameters (oneCtx, absCtx) by pointer m_estBitsSbac->..

diff -r e9f08d038ff0 -r e08877d1b13a source/Lib/TLibCommon/TComTrQuant.cpp
--- a/source/Lib/TLibCommon/TComTrQuant.cpp	Tue Mar 18 17:33:12 2014 -0700
+++ b/source/Lib/TLibCommon/TComTrQuant.cpp	Tue Mar 18 17:33:36 2014 -0700
@@ -628,15 +628,17 @@
 
                 //===== coefficient level estimation =====
                 uint32_t level;
-                uint32_t oneCtx = 4 * ctxSet + c1;
-                uint32_t absCtx = ctxSet + c2;
+                const uint32_t oneCtx = 4 * ctxSet + c1;
+                const uint32_t absCtx = ctxSet + c2;
+                const int *greaterOneBits = m_estBitsSbac->greaterOneBits[oneCtx];
+                const int *levelAbsBits = m_estBitsSbac->levelAbsBits[absCtx];
                 double curCostSig = 0;
 
                 costCoeff[scanPos] = MAX_DOUBLE;
                 if (scanPos == lastScanPos)
                 {
                     level = xGetCodedLevel(costCoeff[scanPos], curCostSig, costSig[scanPos],
-                                           levelDouble, maxAbsLevel, baseLevel, oneCtx, absCtx, goRiceParam,
+                                           levelDouble, maxAbsLevel, baseLevel, greaterOneBits, levelAbsBits, goRiceParam,
                                            c1c2Idx, qbits, scaleFactor, 1);
                 }
                 else
@@ -651,7 +653,7 @@
                     {
                         curCostSig = xGetRateSigCoef(1, ctxSig);
                         level = xGetCodedLevel(costCoeff[scanPos], curCostSig, costSig[scanPos],
-                                               levelDouble, maxAbsLevel, baseLevel, oneCtx, absCtx, goRiceParam,
+                                               levelDouble, maxAbsLevel, baseLevel, greaterOneBits, levelAbsBits, goRiceParam,
                                                c1c2Idx, qbits, scaleFactor, 0);
                     }
                     else
@@ -663,13 +665,13 @@
                 deltaU[blkPos] = (levelDouble - ((int)level << qbits)) >> (qbits - 8);
                 if (level > 0)
                 {
-                    int rateNow = xGetICRate(level, level - baseLevel, oneCtx, absCtx, goRiceParam, c1c2Idx);
-                    rateIncUp[blkPos] = xGetICRate(level + 1, level + 1 - baseLevel, oneCtx, absCtx, goRiceParam, c1c2Idx) - rateNow;
-                    rateIncDown[blkPos] = xGetICRate(level - 1, level - 1 - baseLevel, oneCtx, absCtx, goRiceParam, c1c2Idx) - rateNow;
+                    int rateNow = xGetICRate(level, level - baseLevel, greaterOneBits, levelAbsBits, goRiceParam, c1c2Idx);
+                    rateIncUp[blkPos] = xGetICRate(level + 1, level + 1 - baseLevel, greaterOneBits, levelAbsBits, goRiceParam, c1c2Idx) - rateNow;
+                    rateIncDown[blkPos] = xGetICRate(level - 1, level - 1 - baseLevel, greaterOneBits, levelAbsBits, goRiceParam, c1c2Idx) - rateNow;
                 }
                 else // level == 0
                 {
-                    rateIncUp[blkPos] = m_estBitsSbac->greaterOneBits[oneCtx][0];
+                    rateIncUp[blkPos] = greaterOneBits[0];
                 }
                 dstCoeff[blkPos] = level;
                 baseCost           += costCoeff[scanPos];
@@ -1145,8 +1147,8 @@
                                             int      levelDouble,
                                             uint32_t maxAbsLevel,
                                             uint32_t baseLevel,
-                                            uint32_t ctxNumOne,
-                                            uint32_t ctxNumAbs,
+                                            const int *greaterOneBits,
+                                            const int *levelAbsBits,
                                             uint32_t absGoRice,
                                             uint32_t c1c2Idx,
                                             int      qbits,
@@ -1176,10 +1178,11 @@
 
     double bestCodedCost = codedCost;
     double bestCodedCostSig = codedCostSig;
+    int diffLevel = maxAbsLevel - baseLevel;
     for (int absLevel = maxAbsLevel; absLevel >= minAbsLevel; absLevel--)
     {
         assert(fabs((double)err2 - double(levelDouble  - (absLevel << qbits)) * double(levelDouble  - (absLevel << qbits)) * scaleFactor) < 1e-5);
-        double curCost = err2 + xGetICRateCost(absLevel, absLevel - baseLevel, ctxNumOne, ctxNumAbs, absGoRice, c1c2Idx);
+        double curCost = err2 + xGetICRateCost(absLevel, diffLevel, greaterOneBits, levelAbsBits, absGoRice, c1c2Idx);
         curCost       += curCostSig;
 
         if (curCost < bestCodedCost)
@@ -1189,6 +1192,7 @@
             bestCodedCostSig = curCostSig;
         }
         err2 += errInc;
+        diffLevel--;
     }
     codedCost = bestCodedCost;
     codedCostSig = bestCodedCostSig;
@@ -1204,15 +1208,13 @@
  */
 FORCEINLINE double TComTrQuant::xGetICRateCost(uint32_t absLevel,
                                           int32_t  diffLevel,
-                                          uint32_t ctxNumOne,
-                                          uint32_t ctxNumAbs,
+                                          const int *greaterOneBits,
+                                          const int *levelAbsBits,
                                           uint32_t absGoRice,
                                           uint32_t c1c2Idx) const
 {
     assert(absLevel > 0);
     uint32_t rate = xGetIEPRate();
-    const int *greaterOneBits = m_estBitsSbac->greaterOneBits[ctxNumOne];
-    const int *levelAbsBits = m_estBitsSbac->levelAbsBits[ctxNumAbs];
 
     if (diffLevel < 0)
     {
@@ -1262,8 +1264,8 @@
 
 inline int TComTrQuant::xGetICRate(uint32_t absLevel,
                                     int32_t diffLevel,
-                                   uint32_t ctxNumOne,
-                                   uint32_t ctxNumAbs,
+                                   const int *greaterOneBits,
+                                   const int *levelAbsBits,
                                    uint32_t absGoRice,
                                    uint32_t c1c2Idx) const
 {
@@ -1275,8 +1277,8 @@
         return 0;
     }
     int rate = 0;
-    const int *greaterOneBits = m_estBitsSbac->greaterOneBits[ctxNumOne];
-    const int *levelAbsBits = m_estBitsSbac->levelAbsBits[ctxNumAbs];
+    //const int *greaterOneBits = m_estBitsSbac->greaterOneBits[ctxNumOne];
+    //const int *levelAbsBits = m_estBitsSbac->levelAbsBits[ctxNumAbs];
 
     if (diffLevel < 0)
     {
diff -r e9f08d038ff0 -r e08877d1b13a source/Lib/TLibCommon/TComTrQuant.h
--- a/source/Lib/TLibCommon/TComTrQuant.h	Tue Mar 18 17:33:12 2014 -0700
+++ b/source/Lib/TLibCommon/TComTrQuant.h	Tue Mar 18 17:33:36 2014 -0700
@@ -194,12 +194,12 @@
     uint32_t xRateDistOptQuant(TComDataCU* cu, int32_t* srcCoeff, TCoeff* dstCoeff, uint32_t trSize, TextType ttype, uint32_t absPartIdx, int32_t *lastPos);
 
     inline uint32_t xGetCodedLevel(double& codedCost, const double curCostSig, double& codedCostSig, int levelDouble,
-                                   uint32_t maxAbsLevel, uint32_t baseLevel, uint32_t ctxNumOne, uint32_t ctxNumAbs, uint32_t absGoRice,
+                                   uint32_t maxAbsLevel, uint32_t baseLevel, const int *greaterOneBits, const int *levelAbsBits, uint32_t absGoRice,
                                    uint32_t c1c2Idx, int qbits, double scale, bool bLast) const;
 
-    inline double xGetICRateCost(uint32_t absLevel, int32_t  diffLevel, uint32_t ctxNumOne, uint32_t ctxNumAbs, uint32_t absGoRice, uint32_t c1c2Idx) const;
+    inline double xGetICRateCost(uint32_t absLevel, int32_t  diffLevel, const int *greaterOneBits, const int *levelAbsBits, uint32_t absGoRice, uint32_t c1c2Idx) const;
 
-    inline int    xGetICRate(uint32_t absLevel, int32_t diffLevel, uint32_t ctxNumOne, uint32_t ctxNumAbs, uint32_t absGoRice, uint32_t c1c2Idx) const;
+    inline int    xGetICRate(uint32_t absLevel, int32_t diffLevel, const int *greaterOneBits, const int *levelAbsBits, uint32_t absGoRice, uint32_t c1c2Idx) const;
 
     inline double xGetRateLast(uint32_t posx, uint32_t posy) const;
 
@@ -207,7 +207,7 @@
 
     inline double xGetRateSigCoef(uint32_t sig, uint32_t ctxNumSig) const { return m_lambda * m_estBitsSbac->significantBits[ctxNumSig][sig]; }
 
-    inline double xGetICost(double rage) const { return m_lambda * rage; } ///< Get the cost for a specific rate
+    inline double xGetICost(double rate) const { return m_lambda * rate; } ///< Get the cost for a specific rate
 
     inline uint32_t xGetIEPRate() const          { return 32768; }            ///< Get the cost of an equal probable bit
 



More information about the x265-devel mailing list