[x265] [PATCH] SAO: modified SignOf2()

ashok at multicorewareinc.com ashok at multicorewareinc.com
Tue Feb 16 16:11:19 CET 2016


# HG changeset patch
# User Ashok Kumar Mishra<ashok at multicorewareinc.com>
# Date 1455633534 -19800
#      Tue Feb 16 20:08:54 2016 +0530
# Node ID 5f1817e5ff55689c45b12e1982a4c4fc46201382
# Parent  a26f3d8c9758c1ee510c75518304d4c9445a202b
SAO: modified SignOf2()
Both SignOf and SignOf2 can be written as macro instead of using a separate namespace
estSaoDist() is used for sao distortion calculation, it should be part of sao class

diff -r a26f3d8c9758 -r 5f1817e5ff55 source/encoder/sao.cpp
--- a/source/encoder/sao.cpp	Tue Feb 16 20:00:33 2016 +0530
+++ b/source/encoder/sao.cpp	Tue Feb 16 20:08:54 2016 +0530
@@ -29,6 +29,10 @@
 #include "picyuv.h"
 #include "sao.h"
 
+/* get the sign of input variable */
+#define signOf(X) (((X) >> 31) | (((uint32_t)-(X)) >> 31))
+#define signOf2(A, B) (((A) < (B)) ? -1 : ((A) > (B)) ? 1 : 0)
+
 namespace {
 
 inline int32_t roundIBDI(int32_t num, int32_t den)
@@ -36,27 +40,6 @@
     return num >= 0 ? ((num * 2 + den) / (den * 2)) : -((-num * 2 + den) / (den * 2));
 }
 
-/* get the sign of input variable (TODO: this is a dup, make common) */
-inline int8_t signOf(int x)
-{
-    return (x >> 31) | ((int)((((uint32_t)-x)) >> 31));
-}
-
-inline int signOf2(const int a, const int b)
-{
-    // NOTE: don't reorder below compare, both ICL, VC, GCC optimize strong depends on order!
-    int r = 0;
-    if (a < b)
-        r = -1;
-    if (a > b)
-        r = 1;
-    return r;
-}
-
-inline int64_t estSaoDist(int32_t count, int offset, int32_t offsetOrg)
-{
-    return (count * offset - offsetOrg * 2) * offset;
-}
 } // end anonymous namespace
 
 
@@ -1413,7 +1396,12 @@
     }
 }
 
-inline int SAO::estIterOffset(int typeIdx, double lambda, int offset, int32_t count, int32_t offsetOrg, int& distBOClasses, double& costBOClasses)
+inline int64_t SAO::estSaoDist(int32_t count, int offset, int32_t offsetOrg)
+{
+    return (count * offset - offsetOrg * 2) * offset;
+}
+
+int SAO::estIterOffset(int typeIdx, double lambda, int offset, int32_t count, int32_t offsetOrg, int& distBOClasses, double& costBOClasses)
 {
     int bestOffset = 0;
 
@@ -1740,7 +1728,6 @@
         for (int x = 0; x < endX; x++)
         {
             int signRight = signOf2(rec[x], rec[x + 1]);
-            X265_CHECK(signRight == signOf(rec[x] - rec[x + 1]), "signDown check failure\n");
             uint32_t edgeType = signRight + signLeft + 2;
             signLeft = -signRight;
 
@@ -1777,7 +1764,6 @@
         for (int x = 0; x < endX; x++)
         {
             int signDown = signOf2(rec[x], rec[x + stride]);
-            X265_CHECK(signDown == signOf(rec[x] - rec[x + stride]), "signDown check failure\n");
             uint32_t edgeType = signDown + upBuff1[x] + 2;
             upBuff1[x] = (int8_t)(-signDown);
 
@@ -1813,7 +1799,6 @@
         for (int x = 0; x < endX; x++)
         {
             int signDown = signOf2(rec[x], rec[x + stride + 1]);
-            X265_CHECK(signDown == signOf(rec[x] - rec[x + stride + 1]), "signDown check failure\n");
             uint32_t edgeType = signDown + upBuff1[x] + 2;
             upBufft[x + 1] = (int8_t)(-signDown);
             tmp_stats[edgeType] += diff[x];
@@ -1849,7 +1834,6 @@
         for (int x = 0; x < endX; x++)
         {
             int signDown = signOf2(rec[x], rec[x + stride - 1]);
-            X265_CHECK(signDown == signOf(rec[x] - rec[x + stride - 1]), "signDown check failure\n");
             X265_CHECK(abs(upBuff1[x]) <= 1, "upBuffer1 check failure\n");
 
             uint32_t edgeType = signDown + upBuff1[x] + 2;
diff -r a26f3d8c9758 -r 5f1817e5ff55 source/encoder/sao.h
--- a/source/encoder/sao.h	Tue Feb 16 20:00:33 2016 +0530
+++ b/source/encoder/sao.h	Tue Feb 16 20:08:54 2016 +0530
@@ -141,10 +141,11 @@
     void saoLumaComponentParamDist(SAOParam* saoParam, int addr, double* mergeDist);
     void saoChromaComponentParamDist(SAOParam* saoParam, int addr, double* mergeDist);
 
-    inline int estIterOffset(int typeIdx, double lambda, int offset, int32_t count, int32_t offsetOrg,
+    int estIterOffset(int typeIdx, double lambda, int offset, int32_t count, int32_t offsetOrg,
                              int& currentDistortionTableBo, double& currentRdCostTableBo);
     void rdoSaoUnitRowEnd(const SAOParam* saoParam, int numctus);
     void rdoSaoUnitCu(SAOParam* saoParam, int rowBaseAddr, int idxX, int addr);
+    int64_t estSaoDist(int32_t count, int offset, int32_t offsetOrg);
 
     void saoStatsInitialOffset(bool chroma);
 


More information about the x265-devel mailing list