[x265] [PATCH] PSNR : moved SSD accumulators to Tcompic

santhoshini at multicorewareinc.com santhoshini at multicorewareinc.com
Tue Oct 15 11:54:28 CEST 2013


# HG changeset patch
# User Santhoshini Sekar <santhoshini at multicorewareinc.com>
# Date 1381830528 -19800
#      Tue Oct 15 15:18:48 2013 +0530
# Node ID a83fce64ad3060826abbcf6d573fba5f600b4f97
# Parent  1a85d8814346efdb984ea9eae24d1b06b973e9a8
PSNR : moved SSD accumulators to Tcompic

diff -r 1a85d8814346 -r a83fce64ad30 source/Lib/TLibCommon/TComPic.cpp
--- a/source/Lib/TLibCommon/TComPic.cpp	Tue Oct 15 12:45:58 2013 +0530
+++ b/source/Lib/TLibCommon/TComPic.cpp	Tue Oct 15 15:18:48 2013 +0530
@@ -61,6 +61,9 @@
     memset(&m_lowres, 0, sizeof(m_lowres));
     m_next = NULL;
     m_prev = NULL;
+    m_SSDY = 0;
+    m_SSDU = 0;
+    m_SSDV = 0;
 }
 
 TComPic::~TComPic()
diff -r 1a85d8814346 -r a83fce64ad30 source/Lib/TLibCommon/TComPic.h
--- a/source/Lib/TLibCommon/TComPic.h	Tue Oct 15 12:45:58 2013 +0530
+++ b/source/Lib/TLibCommon/TComPic.h	Tue Oct 15 15:18:48 2013 +0530
@@ -84,6 +84,10 @@
     TComPic*              m_next;
     TComPic*              m_prev;
 
+    UInt64                      m_SSDY;
+    UInt64                      m_SSDU;
+    UInt64                      m_SSDV;
+
     TComPic();
     virtual ~TComPic();
 
diff -r 1a85d8814346 -r a83fce64ad30 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Oct 15 12:45:58 2013 +0530
+++ b/source/encoder/encoder.cpp	Tue Oct 15 15:18:48 2013 +0530
@@ -362,109 +362,6 @@
 //       (we do not yet have a switch to disable PSNR reporting)
 //   2 - it would be better to accumulate SSD of each CTU at the end of processCTU() while it is cache-hot
 //       in fact, we almost certainly are already measuring the CTU distortion and not accumulating it
-static UInt64 computeSSD(Pel *fenc, Pel *rec, int stride, int width, int height)
-{
-    UInt64 ssd = 0;
-
-    if ((width | height) & 3)
-    {
-        /* Slow Path */
-        for (int y = 0; y < height; y++)
-        {
-            for (int x = 0; x < width; x++)
-            {
-                int diff = (int)(fenc[x] - rec[x]);
-                ssd += diff * diff;
-            }
-
-            fenc += stride;
-            rec += stride;
-        }
-
-        return ssd;
-    }
-
-    int y = 0;
-    /* Consume Y in chunks of 64 */
-    for (; y + 64 <= height; y += 64)
-    {
-        int x = 0;
-
-        if (!(stride & 31))
-            for (; x + 64 <= width; x += 64)
-            {
-                ssd += primitives.sse_pp[PARTITION_64x64](fenc + x, stride, rec + x, stride);
-            }
-
-        if (!(stride & 15))
-            for (; x + 16 <= width; x += 16)
-            {
-                ssd += primitives.sse_pp[PARTITION_16x64](fenc + x, stride, rec + x, stride);
-            }
-
-        for (; x + 4 <= width; x += 4)
-        {
-            ssd += primitives.sse_pp[PARTITION_4x64](fenc + x, stride, rec + x, stride);
-        }
-
-        fenc += stride * 64;
-        rec += stride * 64;
-    }
-
-    /* Consume Y in chunks of 16 */
-    for (; y + 16 <= height; y += 16)
-    {
-        int x = 0;
-
-        if (!(stride & 31))
-            for (; x + 64 <= width; x += 64)
-            {
-                ssd += primitives.sse_pp[PARTITION_64x16](fenc + x, stride, rec + x, stride);
-            }
-
-        if (!(stride & 15))
-            for (; x + 16 <= width; x += 16)
-            {
-                ssd += primitives.sse_pp[PARTITION_16x16](fenc + x, stride, rec + x, stride);
-            }
-
-        for (; x + 4 <= width; x += 4)
-        {
-            ssd += primitives.sse_pp[PARTITION_4x16](fenc + x, stride, rec + x, stride);
-        }
-
-        fenc += stride * 16;
-        rec += stride * 16;
-    }
-
-    /* Consume Y in chunks of 4 */
-    for (; y + 4 <= height; y += 4)
-    {
-        int x = 0;
-
-        if (!(stride & 31))
-            for (; x + 64 <= width; x += 64)
-            {
-                ssd += primitives.sse_pp[PARTITION_64x4](fenc + x, stride, rec + x, stride);
-            }
-
-        if (!(stride & 15))
-            for (; x + 16 <= width; x += 16)
-            {
-                ssd += primitives.sse_pp[PARTITION_16x4](fenc + x, stride, rec + x, stride);
-            }
-
-        for (; x + 4 <= width; x += 4)
-        {
-            ssd += primitives.sse_pp[PARTITION_4x4](fenc + x, stride, rec + x, stride);
-        }
-
-        fenc += stride * 4;
-        rec += stride * 4;
-    }
-
-    return ssd;
-}
 
 /**
  * Produce an ascii(hex) representation of picture digest.
@@ -496,27 +393,21 @@
 uint64_t Encoder::calculateHashAndPSNR(TComPic* pic, NALUnitEBSP **nalunits)
 {
     TComPicYuv* recon = pic->getPicYuvRec();
-    TComPicYuv* orig  = pic->getPicYuvOrg();
 
     //===== calculate PSNR =====
-    int stride = recon->getStride();
     int width  = recon->getWidth() - getPad(0);
     int height = recon->getHeight() - getPad(1);
     int size = width * height;
 
-    UInt64 ssdY = computeSSD(orig->getLumaAddr(), recon->getLumaAddr(), stride, width, height);
-
-    height >>= 1;
-    width  >>= 1;
-    stride = recon->getCStride();
-
-    UInt64 ssdU = computeSSD(orig->getCbAddr(), recon->getCbAddr(), stride, width, height);
-    UInt64 ssdV = computeSSD(orig->getCrAddr(), recon->getCrAddr(), stride, width, height);
 
     int maxvalY = 255 << (X265_DEPTH - 8);
     int maxvalC = 255 << (X265_DEPTH - 8);
     double refValueY = (double)maxvalY * maxvalY * size;
     double refValueC = (double)maxvalC * maxvalC * size / 4.0;
+    UInt64 ssdY, ssdU, ssdV;
+    ssdY = pic->m_SSDY;
+    ssdU = pic->m_SSDU;
+    ssdV = pic->m_SSDV;
     double psnrY = (ssdY ? 10.0 * log10(refValueY / (double)ssdY) : 99.99);
     double psnrU = (ssdU ? 10.0 * log10(refValueC / (double)ssdU) : 99.99);
     double psnrV = (ssdV ? 10.0 * log10(refValueC / (double)ssdV) : 99.99);
diff -r 1a85d8814346 -r a83fce64ad30 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Tue Oct 15 12:45:58 2013 +0530
+++ b/source/encoder/frameencoder.cpp	Tue Oct 15 15:18:48 2013 +0530
@@ -951,6 +951,10 @@
     UInt refLagRows = ((m_cfg->param.searchRange + NTAPS_LUMA/2 + g_maxCUHeight - 1) / g_maxCUHeight) + 1;
     int numPredDir = slice->isInterP() ? 1 : slice->isInterB() ? 2 : 0;
 
+    m_pic->m_SSDY = 0;
+    m_pic->m_SSDU = 0;
+    m_pic->m_SSDV = 0;
+
     m_frameFilter.start(m_pic);
 
     if (m_pool && m_cfg->param.bEnableWavefront)
diff -r 1a85d8814346 -r a83fce64ad30 source/encoder/framefilter.cpp
--- a/source/encoder/framefilter.cpp	Tue Oct 15 12:45:58 2013 +0530
+++ b/source/encoder/framefilter.cpp	Tue Oct 15 15:18:48 2013 +0530
@@ -265,6 +265,144 @@
     {
         m_pic->m_reconRowWait.trigger();
     }
+
+    if (m_cfg->param.bEnablePsnr)
+    {
+        calculatePSNR(lineStartCUAddr, row);
+    }
+}
+
+static UInt64 computeSSD(pixel *fenc, pixel *rec, int stride, int width, int height)
+{
+    UInt64 ssd = 0;
+
+    if ((width | height) & 3)
+    {
+        /* Slow Path */
+        for (int y = 0; y < height; y++)
+        {
+            for (int x = 0; x < width; x++)
+            {
+                int diff = (int)(fenc[x] - rec[x]);
+                ssd += diff * diff;
+            }
+
+            fenc += stride;
+            rec += stride;
+        }
+
+        return ssd;
+    }
+
+    int y = 0;
+    /* Consume Y in chunks of 64 */
+    for (; y + 64 <= height; y += 64)
+    {
+        int x = 0;
+
+        if (!(stride & 31))
+            for (; x + 64 <= width; x += 64)
+            {
+                ssd += primitives.sse_pp[PARTITION_64x64](fenc + x, stride, rec + x, stride);
+            }
+
+        if (!(stride & 15))
+            for (; x + 16 <= width; x += 16)
+            {
+                ssd += primitives.sse_pp[PARTITION_16x64](fenc + x, stride, rec + x, stride);
+            }
+
+        for (; x + 4 <= width; x += 4)
+        {
+            ssd += primitives.sse_pp[PARTITION_4x64](fenc + x, stride, rec + x, stride);
+        }
+
+        fenc += stride * 64;
+        rec += stride * 64;
+    }
+
+    /* Consume Y in chunks of 16 */
+    for (; y + 16 <= height; y += 16)
+    {
+        int x = 0;
+
+        if (!(stride & 31))
+            for (; x + 64 <= width; x += 64)
+            {
+                ssd += primitives.sse_pp[PARTITION_64x16](fenc + x, stride, rec + x, stride);
+            }
+
+        if (!(stride & 15))
+            for (; x + 16 <= width; x += 16)
+            {
+                ssd += primitives.sse_pp[PARTITION_16x16](fenc + x, stride, rec + x, stride);
+            }
+
+        for (; x + 4 <= width; x += 4)
+        {
+            ssd += primitives.sse_pp[PARTITION_4x16](fenc + x, stride, rec + x, stride);
+        }
+
+        fenc += stride * 16;
+        rec += stride * 16;
+    }
+
+    /* Consume Y in chunks of 4 */
+    for (; y + 4 <= height; y += 4)
+    {
+        int x = 0;
+
+        if (!(stride & 31))
+            for (; x + 64 <= width; x += 64)
+            {
+                ssd += primitives.sse_pp[PARTITION_64x4](fenc + x, stride, rec + x, stride);
+            }
+
+        if (!(stride & 15))
+            for (; x + 16 <= width; x += 16)
+            {
+                ssd += primitives.sse_pp[PARTITION_16x4](fenc + x, stride, rec + x, stride);
+            }
+
+        for (; x + 4 <= width; x += 4)
+        {
+            ssd += primitives.sse_pp[PARTITION_4x4](fenc + x, stride, rec + x, stride);
+        }
+
+        fenc += stride * 4;
+        rec += stride * 4;
+    }
+
+    return ssd;
+}
+
+void FrameFilter::calculatePSNR(uint32_t cuAddr, int row)
+{
+    TComPicYuv* recon = m_pic->getPicYuvRec();
+    TComPicYuv* orig  = m_pic->getPicYuvOrg();
+
+    //===== calculate PSNR =====
+    int stride = recon->getStride();
+
+    int width  = recon->getWidth() - m_cfg->getPad(0);
+    int height;
+    if (row == m_numRows - 1)
+        height = ((recon->getHeight() % g_maxCUHeight) ? (recon->getHeight() % g_maxCUHeight) : g_maxCUHeight);
+    else
+        height = g_maxCUHeight;
+
+    UInt64 ssdY = computeSSD(orig->getLumaAddr(cuAddr), recon->getLumaAddr(cuAddr), stride, width, height);
+
+    height >>= 1;
+    width  >>= 1;
+    stride = recon->getCStride();
+
+    UInt64 ssdU = computeSSD(orig->getCbAddr(cuAddr), recon->getCbAddr(cuAddr), stride, width, height);
+    UInt64 ssdV = computeSSD(orig->getCrAddr(cuAddr), recon->getCrAddr(cuAddr), stride, width, height);
+
+    m_pic->m_SSDY += ssdY;
+    m_pic->m_SSDU += ssdU;
+    m_pic->m_SSDV += ssdV;
 }
 
 void FrameFilter::processSao(int row)
diff -r 1a85d8814346 -r a83fce64ad30 source/encoder/framefilter.h
--- a/source/encoder/framefilter.h	Tue Oct 15 12:45:58 2013 +0530
+++ b/source/encoder/framefilter.h	Tue Oct 15 15:18:48 2013 +0530
@@ -53,6 +53,7 @@
     void processRow(int row);
     void processRowPost(int row);
     void processSao(int row);
+    void calculatePSNR(uint32_t cu, int row);
 
 protected:
 
@@ -72,6 +73,7 @@
     TEncBinCABAC                m_rdGoOnBinCodersCABAC;
     TComBitCounter              m_bitCounter;
     TEncSbac*                   m_rdGoOnSbacCoderRow0;  // for bitstream exact only, depends on HM's bug
+
 };
 }
 


More information about the x265-devel mailing list