[x265] [PATCH] SAO: sao initial offset calculation separated from distortion calculation

ashok at multicorewareinc.com ashok at multicorewareinc.com
Mon Jan 18 16:50:44 CET 2016


# HG changeset patch
# User Ashok Kumar Mishra<ashok at multicorewareinc.com>
# Date 1453132227 -19800
#      Mon Jan 18 21:20:27 2016 +0530
# Node ID e7768afed62fad78a193ea0d54137c4f5d8d2db3
# Parent  5ba1062898a0965690e2ddf28fd193321f493542
SAO: sao initial offset calculation separated from distortion calculation
The function saoStatsInitialOffset() can be written in asm.

diff -r 5ba1062898a0 -r e7768afed62f source/encoder/sao.cpp
--- a/source/encoder/sao.cpp	Mon Jan 18 21:19:56 2016 +0530
+++ b/source/encoder/sao.cpp	Mon Jan 18 21:20:27 2016 +0530
@@ -1415,12 +1415,17 @@
         saoParam->ctuParam[i][addr].reset();
 
     if (saoParam->bSaoFlag[0])
+    {
         calcSaoStatsCu(addr, 0);
+        saoStatsInitialOffset(0);
+    }
 
     if (saoParam->bSaoFlag[1])
     {
         calcSaoStatsCu(addr, 1);
         calcSaoStatsCu(addr, 2);
+        saoStatsInitialOffset(1);
+        saoStatsInitialOffset(2);
     }
 
     double mergeDist[NUM_MERGE_MODE] = {0.0, 0.0, 0.0};
@@ -1516,6 +1521,47 @@
     }
 }
 
+
+// Rounds the division of initial offsets by the number of samples in
+// each of the statistics table entries.
+void SAO::saoStatsInitialOffset(int plane)
+{
+    // EO
+    for (int typeIdx = 0; typeIdx < MAX_NUM_SAO_TYPE - 1; typeIdx++)
+    {
+        for (int classIdx = 1; classIdx < SAO_EO_LEN + 1; classIdx++)
+        {
+            int32_t  count     = m_count[plane][typeIdx][classIdx];
+            int32_t& offsetOrg = m_offsetOrg[plane][typeIdx][classIdx];
+            int32_t& offsetOut = m_offset[plane][typeIdx][classIdx];
+
+            if (count)
+            {
+                offsetOut = roundIBDI(offsetOrg, count << SAO_BIT_INC);
+                offsetOut = x265_clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offsetOut);
+
+                if (classIdx < 3) 
+                    offsetOut = X265_MAX(offsetOut, 0);
+                else
+                    offsetOut = X265_MIN(offsetOut, 0);
+            }
+        }
+    }
+    // BO
+    for (int classIdx = 1; classIdx < SAO_NUM_BO_CLASSES + 1; classIdx++)
+    {
+        int32_t  count     = m_count[plane][SAO_BO][classIdx];
+        int32_t& offsetOrg = m_offsetOrg[plane][SAO_BO][classIdx];
+        int32_t& offsetOut = m_offset[plane][SAO_BO][classIdx];
+
+        if (count)
+        {
+            offsetOut = roundIBDI(offsetOrg, count << SAO_BIT_INC);
+            offsetOut = x265_clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offsetOut);
+        }
+    }
+}
+
 inline int SAO::estIterOffset(int typeIdx, int classIdx, double lambda, int offset, int32_t count, int32_t offsetOrg, int32_t* currentDistortionTableBo, double* currentRdCostTableBo)
 {
     int offsetOut = 0;
@@ -1577,15 +1623,7 @@
 
             if (count)
             {
-                int offset = roundIBDI(offsetOrg << (X265_DEPTH - 8), count);
-                offset = x265_clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offset);
-
-                if (classIdx < 3)
-                    offset = X265_MAX(offset, 0);
-                else
-                    offset = X265_MIN(offset, 0);
-
-                offsetOut = estIterOffset(typeIdx, classIdx, m_lumaLambda, offset, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
+                offsetOut = estIterOffset(typeIdx, classIdx, m_lumaLambda, offsetOut, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
             }
             else
             {
@@ -1630,10 +1668,7 @@
 
         if (count)
         {
-            int offset = roundIBDI(offsetOrg << (X265_DEPTH - 8), count);
-            offset = x265_clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offset);
-
-            offsetOut = estIterOffset(SAO_BO, classIdx, m_lumaLambda, offset, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
+            offsetOut = estIterOffset(SAO_BO, classIdx, m_lumaLambda, offsetOut, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
         }
         else
         {
@@ -1718,15 +1753,7 @@
 
                 if (count)
                 {
-                    int offset = roundIBDI(offsetOrg << (X265_DEPTH - 8), count);
-                    offset = x265_clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offset);
-
-                    if (classIdx < 3)
-                        offset = X265_MAX(offset, 0);
-                    else
-                        offset = X265_MIN(offset, 0);
-
-                    offsetOut = estIterOffset(typeIdx, classIdx, m_chromaLambda, offset, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
+                    offsetOut = estIterOffset(typeIdx, classIdx, m_chromaLambda, offsetOut, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
                 }
                 else
                 {
@@ -1784,10 +1811,7 @@
 
             if (count)
             {
-                int offset = roundIBDI(offsetOrg << (X265_DEPTH - 8), count);
-                offset = x265_clip3(-OFFSET_THRESH + 1, OFFSET_THRESH - 1, offset);
-
-                offsetOut = estIterOffset(SAO_BO, classIdx, m_chromaLambda, offset, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
+                offsetOut = estIterOffset(SAO_BO, classIdx, m_chromaLambda, offsetOut, count, offsetOrg, currentDistortionTableBo, currentRdCostTableBo);
             }
             else
             {
diff -r 5ba1062898a0 -r e7768afed62f source/encoder/sao.h
--- a/source/encoder/sao.h	Mon Jan 18 21:19:56 2016 +0530
+++ b/source/encoder/sao.h	Mon Jan 18 21:20:27 2016 +0530
@@ -150,6 +150,8 @@
     void rdoSaoUnitRow(SAOParam* saoParam, int idxY);
     void rdoSaoUnitCu(SAOParam* saoParam, int rowBaseAddr, int idxX, int addr);
 
+    void saoStatisticInitOffset(int plane);
+
     friend class FrameFilter;
 };
 


More information about the x265-devel mailing list