[x265] [PATCH 2 of 5] rdoQuant: fast zero cost compute path

Min Chen chenm003 at 163.com
Fri Apr 17 15:32:18 CEST 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1429277479 -28800
# Node ID 65f20e04bd36ef95988cd0ef3a608b1ffe3858c7
# Parent  5cab20b7a0620e128c69d2886fb6e9c896178b4a
rdoQuant: fast zero cost compute path
---
 source/common/quant.cpp |   44 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 41 insertions(+), 3 deletions(-)

diff -r 5cab20b7a062 -r 65f20e04bd36 source/common/quant.cpp
--- a/source/common/quant.cpp	Fri Apr 17 21:31:12 2015 +0800
+++ b/source/common/quant.cpp	Fri Apr 17 21:31:19 2015 +0800
@@ -587,7 +587,6 @@
     EstBitsSbac& estBitsSbac = m_entropyCoder->m_estBitsSbac;
 
     uint32_t scanPos;
-    coeffGroupRDStats cgRdStats;
     uint32_t c1 = 1;
 
     // process trail all zero Coeff Group
@@ -632,14 +631,53 @@
         const uint32_t cgPosY   = cgBlkPos >> codeParams.log2TrSizeCG;
         const uint32_t cgPosX   = cgBlkPos - (cgPosY << codeParams.log2TrSizeCG);
         const uint64_t cgBlkPosMask = ((uint64_t)1 << cgBlkPos);
-        memset(&cgRdStats, 0, sizeof(coeffGroupRDStats));
-
         const int patternSigCtx = calcPatternSigCtx(sigCoeffGroupFlag64, cgPosX, cgPosY, cgBlkPos, cgStride);
 
         if (c1 == 0)
             ctxSet++;
         c1 = 1;
 
+        if (cgScanPos && (coeffNum[cgScanPos] == 0))
+        {
+            // TODO: does we need zero-coeff cost?
+            for (int scanPosinCG = 0; scanPosinCG < SCAN_SET_SIZE; scanPosinCG++)
+            {
+                scanPos              = (cgScanPos << MLS_CG_SIZE) + scanPosinCG;
+                uint32_t blkPos      = codeParams.scan[scanPos];
+
+                // TODO: get 16 of ctxSig
+                const uint32_t ctxSig = getSigCtxInc(patternSigCtx, log2TrSize, trSize, blkPos, bIsLuma, codeParams.firstSignificanceMapContext);
+
+                /* set default costs to uncoded costs */
+                int signCoef         = m_resiDctCoeff[blkPos];            /* pre-quantization DCT coeff */
+                int predictedCoef    = m_fencDctCoeff[blkPos] - signCoef; /* predicted DCT = source DCT - residual DCT*/
+
+                /* cost of not coding this coefficient (all distortion, no signal bits) */
+                costUncoded[blkPos] = ((int64_t)signCoef * signCoef) << scaleBits;
+                if (usePsyMask & scanPos)
+                    /* when no residual coefficient is coded, predicted coef == recon coef */
+                    costUncoded[blkPos] -= PSYVALUE(predictedCoef);
+
+                totalUncodedCost += costUncoded[blkPos];
+
+                costSig[scanPos] = SIGCOST(estBitsSbac.significantBits[ctxSig][0]);
+                costCoeff[scanPos] = costUncoded[blkPos];
+                sigRateDelta[blkPos] = estBitsSbac.significantBits[ctxSig][1] - estBitsSbac.significantBits[ctxSig][0];
+                totalRdCost += costCoeff[scanPos];
+            }
+
+            /* there were no coded coefficients in this coefficient group */
+            {
+                uint32_t ctxSig = getSigCoeffGroupCtxInc(sigCoeffGroupFlag64, cgPosX, cgPosY, cgBlkPos, cgStride);
+                costCoeffGroupSig[cgScanPos] = SIGCOST(estBitsSbac.significantCoeffGroupBits[ctxSig][0]);
+                totalRdCost += costCoeffGroupSig[cgScanPos];  /* add cost of 0 bit in significant CG bitmap */
+            }
+            continue;
+        }
+
+        coeffGroupRDStats cgRdStats;
+        memset(&cgRdStats, 0, sizeof(coeffGroupRDStats));
+
         int    c2            = 0;
         uint32_t goRiceParam = 0;
         uint32_t c1Idx       = 0;



More information about the x265-devel mailing list