[x265] [PATCH 2 of 2] improve Quant::signBitHidingHDQ by scanPosLast and findPosFirstLast

Min Chen chenm003 at 163.com
Fri May 15 02:12:00 CEST 2015


# HG changeset patch
# User Min Chen <chenm003 at 163.com>
# Date 1431647431 25200
# Node ID 452ca58fb73cbecfb961838db7f0ba931c8155b1
# Parent  c3549eeb4b595e129d18bc75bb4f03272f1624d3
improve Quant::signBitHidingHDQ by scanPosLast and findPosFirstLast
---
 source/common/quant.cpp |   42 ++++++++++++++++++++++++++++++++++--------
 source/common/quant.h   |    2 +-
 2 files changed, 35 insertions(+), 9 deletions(-)

diff -r c3549eeb4b59 -r 452ca58fb73c source/common/quant.cpp
--- a/source/common/quant.cpp	Thu May 14 16:50:27 2015 -0700
+++ b/source/common/quant.cpp	Thu May 14 16:50:31 2015 -0700
@@ -251,30 +251,56 @@
 }
 
 /* To minimize the distortion only. No rate is considered */
-uint32_t Quant::signBitHidingHDQ(int16_t* coeff, int32_t* deltaU, uint32_t numSig, const TUEntropyCodingParameters &codeParams)
+uint32_t Quant::signBitHidingHDQ(int16_t* coeff, int32_t* deltaU, uint32_t numSig, const TUEntropyCodingParameters &codeParams, uint32_t log2TrSize)
 {
-    const uint32_t log2TrSizeCG = codeParams.log2TrSizeCG;
+    uint32_t trSize = 1 << log2TrSize;
     const uint16_t* scan = codeParams.scan;
     bool lastCG = true;
 
-    for (int cg = (1 << (log2TrSizeCG * 2)) - 1; cg >= 0; cg--)
+    uint8_t coeffNum[MLS_GRP_NUM];      // value range[0, 16]
+    uint16_t coeffSign[MLS_GRP_NUM];    // bit mask map for non-zero coeff sign
+    uint16_t coeffFlag[MLS_GRP_NUM];    // bit mask map for non-zero coeff
+
+#if CHECKED_BUILD || _DEBUG
+    // clean output buffer, the asm version of scanPosLast Never output anything after latest non-zero coeff group
+    memset(coeffNum, 0, sizeof(coeffNum));
+    memset(coeffSign, 0, sizeof(coeffNum));
+    memset(coeffFlag, 0, sizeof(coeffNum));
+#endif
+    const int lastScanPos = primitives.scanPosLast(codeParams.scan, coeff, coeffSign, coeffFlag, coeffNum, numSig, g_scan4x4[codeParams.scanType], trSize);
+    const int cgLastScanPos = (lastScanPos >> LOG2_SCAN_SET_SIZE);
+
+    for (int cg = cgLastScanPos; cg >= 0; cg--)
     {
         int cgStartPos = cg << LOG2_SCAN_SET_SIZE;
         int n;
 
+        const uint32_t posFirstLast = primitives.findPosFirstLast(&coeff[codeParams.scan[cgStartPos]], trSize, g_scan4x4[codeParams.scanType]);
+#if CHECKED_BUILD || _DEBUG
         for (n = SCAN_SET_SIZE - 1; n >= 0; --n)
             if (coeff[scan[n + cgStartPos]])
                 break;
-        if (n < 0)
+        int lastNZPosInCG0 = n;
+#endif
+
+        if (coeffNum[cg] == 0)
+        {
+            X265_CHECK(lastNZPosInCG0 < 0, "all zero block check failure\n");
             continue;
+        }
+        int firstNZPosInCG = (uint16_t)posFirstLast;
+        int lastNZPosInCG = posFirstLast >> 16;
 
-        int lastNZPosInCG = n;
-
+#if CHECKED_BUILD || _DEBUG
         for (n = 0;; n++)
             if (coeff[scan[n + cgStartPos]])
                 break;
 
-        int firstNZPosInCG = n;
+        int firstNZPosInCG0 = n;
+
+        X265_CHECK(firstNZPosInCG0 == firstNZPosInCG, "firstNZPosInCG0 check failure\n");
+        X265_CHECK(lastNZPosInCG0 == lastNZPosInCG, "lastNZPosInCG0 check failure\n");
+#endif
 
         if (lastNZPosInCG - firstNZPosInCG >= SBH_THRESHOLD)
         {
@@ -437,7 +463,7 @@
         {
             TUEntropyCodingParameters codeParams;
             cu.getTUEntropyCodingParameters(codeParams, absPartIdx, log2TrSize, isLuma);
-            return signBitHidingHDQ(coeff, deltaU, numSig, codeParams);
+            return signBitHidingHDQ(coeff, deltaU, numSig, codeParams, log2TrSize);
         }
         else
             return numSig;
diff -r c3549eeb4b59 -r 452ca58fb73c source/common/quant.h
--- a/source/common/quant.h	Thu May 14 16:50:27 2015 -0700
+++ b/source/common/quant.h	Thu May 14 16:50:31 2015 -0700
@@ -150,7 +150,7 @@
 
     void setChromaQP(int qpin, TextType ttype, int chFmt);
 
-    uint32_t signBitHidingHDQ(int16_t* qcoeff, int32_t* deltaU, uint32_t numSig, const TUEntropyCodingParameters &codingParameters);
+    uint32_t signBitHidingHDQ(int16_t* qcoeff, int32_t* deltaU, uint32_t numSig, const TUEntropyCodingParameters &codingParameters, uint32_t log2TrSize);
 
     uint32_t rdoQuant(const CUData& cu, int16_t* dstCoeff, uint32_t log2TrSize, TextType ttype, uint32_t absPartIdx, bool usePsy);
 };



More information about the x265-devel mailing list