[x265] [PATCH] stats: fix loss of precision in average luma level per frame

Divya Manivannan divya at multicorewareinc.com
Wed Jul 29 08:13:53 CEST 2015


# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1438150317 -19800
#      Wed Jul 29 11:41:57 2015 +0530
# Node ID e5f5e444fd0a762775bcb89d4efe1f17f822c540
# Parent  e08a245054434090ccb1fc1b985f955a66711157
stats: fix loss of precision in average luma level per frame

diff -r e08a24505443 -r e5f5e444fd0a source/common/framedata.h
--- a/source/common/framedata.h	Mon Jul 27 15:15:35 2015 +0530
+++ b/source/common/framedata.h	Wed Jul 29 11:41:57 2015 +0530
@@ -56,6 +56,7 @@
     double      avgChromaDistortion;
     double      avgPsyEnergy;
     double      avgLumaLevel;
+    double      lumaLevel;
     double      percentIntraNxN;
     double      percentSkipCu[NUM_CU_DEPTH];
     double      percentMergeCu[NUM_CU_DEPTH];
@@ -68,8 +69,6 @@
     uint64_t    lumaDistortion;
     uint64_t    chromaDistortion;
     uint64_t    psyEnergy;
-    uint64_t    lumaLevel;
-    uint64_t    noOfPixels;
     uint64_t    cntSkipCu[NUM_CU_DEPTH];
     uint64_t    cntMergeCu[NUM_CU_DEPTH];
     uint64_t    cntInter[NUM_CU_DEPTH];
diff -r e08a24505443 -r e5f5e444fd0a source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Mon Jul 27 15:15:35 2015 +0530
+++ b/source/encoder/frameencoder.cpp	Wed Jul 29 11:41:57 2015 +0530
@@ -592,7 +592,6 @@
         m_frame->m_encData->m_frameStats.chromaDistortion += m_rows[i].rowStats.chromaDistortion;
         m_frame->m_encData->m_frameStats.psyEnergy        += m_rows[i].rowStats.psyEnergy;
         m_frame->m_encData->m_frameStats.lumaLevel        += m_rows[i].rowStats.lumaLevel;
-        m_frame->m_encData->m_frameStats.noOfPixels       += m_rows[i].rowStats.noOfPixels;
 
         if (m_rows[i].rowStats.maxLumaLevel > m_frame->m_encData->m_frameStats.maxLumaLevel)
             m_frame->m_encData->m_frameStats.maxLumaLevel = m_rows[i].rowStats.maxLumaLevel;
@@ -609,7 +608,7 @@
     m_frame->m_encData->m_frameStats.avgLumaDistortion   = (double)(m_frame->m_encData->m_frameStats.lumaDistortion / m_frame->m_encData->m_frameStats.totalCtu);
     m_frame->m_encData->m_frameStats.avgChromaDistortion = (double)(m_frame->m_encData->m_frameStats.chromaDistortion / m_frame->m_encData->m_frameStats.totalCtu);
     m_frame->m_encData->m_frameStats.avgPsyEnergy        = (double)(m_frame->m_encData->m_frameStats.psyEnergy / m_frame->m_encData->m_frameStats.totalCtu);
-    m_frame->m_encData->m_frameStats.avgLumaLevel        = (double)(m_frame->m_encData->m_frameStats.lumaLevel / m_frame->m_encData->m_frameStats.noOfPixels);
+    m_frame->m_encData->m_frameStats.avgLumaLevel        = (double)(m_frame->m_encData->m_frameStats.lumaLevel / m_frame->m_encData->m_frameStats.totalCtu);
     m_frame->m_encData->m_frameStats.percentIntraNxN     = (double)(m_frame->m_encData->m_frameStats.cntIntraNxN * 100) / m_frame->m_encData->m_frameStats.totalCu;
     for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)
     {
@@ -989,13 +988,16 @@
             for (int n = 0; n < INTRA_MODES; n++)
                 curRow.rowStats.cuIntraDistribution[depth][n] += frameLog.cuIntraDistribution[depth][n];
         }
+        uint64_t ctuLumaLevel = 0;
+        uint64_t ctuNoOfPixels = 0;
         for (uint32_t i = 0; i < (best.reconYuv.m_size * best.reconYuv.m_size); i++)
         {
-            curRow.rowStats.lumaLevel += *(best.reconYuv.m_buf[0] + i);
-            curRow.rowStats.noOfPixels++;
+            ctuLumaLevel += *(best.reconYuv.m_buf[0] + i);
+            ctuNoOfPixels++;
             if ((*(best.reconYuv.m_buf[0] + i)) > curRow.rowStats.maxLumaLevel)
                 curRow.rowStats.maxLumaLevel = *(best.reconYuv.m_buf[0] + i);
         }
+        curRow.rowStats.lumaLevel += (double)(ctuLumaLevel / ctuNoOfPixels);
 
         curEncData.m_cuStat[cuAddr].totalBits = best.totalBits;
         x265_emms();


More information about the x265-devel mailing list