<div dir="ltr"><div>I did a double take on the if (padx) part as well, then figured it works since padx is guaranteed to be non-zero (because of padx++). <br><br></div>Min, can you do a quick profile on whether it is better to do this outside the padx loop, for the whole frame, or inside the padx loop, one row at a time?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 13, 2015 at 6:19 PM, Steve Borho <span dir="ltr"><<a href="mailto:steve@borho.org" target="_blank">steve@borho.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 08/13, <a href="mailto:kavitha@multicorewareinc.com">kavitha@multicorewareinc.com</a> wrote:<br>
> # HG changeset patch<br>
> # User Kavitha Sampath <<a href="mailto:kavitha@multicorewareinc.com">kavitha@multicorewareinc.com</a>><br>
> # Date 1439458769 -19800<br>
> #      Thu Aug 13 15:09:29 2015 +0530<br>
> # Node ID 27226b1c447f4df9cde5b7688f34fb8b7a86e193<br>
> # Parent  bc5a7c2ac38b06d2a232b983f10bc0394d252ad7<br>
> stats: fix use of uninitialized pixels in maximum and average luma level calculation<br>
><br>
> To avoid complexity in determining pixels of border CUs that lie outside the frame,<br>
> luma level calculations are performed at the frame level, immediately after<br>
> copying the picture into PicYuv<br>
><br>
> diff -r bc5a7c2ac38b -r 27226b1c447f source/common/framedata.h<br>
> --- a/source/common/framedata.h       Wed Aug 12 15:13:51 2015 +0530<br>
> +++ b/source/common/framedata.h       Thu Aug 13 15:09:29 2015 +0530<br>
> @@ -55,8 +55,6 @@<br>
>      double      avgLumaDistortion;<br>
>      double      avgChromaDistortion;<br>
>      double      avgPsyEnergy;<br>
> -    double      avgLumaLevel;<br>
> -    double      lumaLevel;<br>
>      double      percentIntraNxN;<br>
>      double      percentSkipCu[NUM_CU_DEPTH];<br>
>      double      percentMergeCu[NUM_CU_DEPTH];<br>
> @@ -75,7 +73,6 @@<br>
>      uint64_t    cntIntra[NUM_CU_DEPTH];<br>
>      uint64_t    cuInterDistribution[NUM_CU_DEPTH][INTER_MODES];<br>
>      uint64_t    cuIntraDistribution[NUM_CU_DEPTH][INTRA_MODES];<br>
> -    uint16_t    maxLumaLevel;<br>
><br>
>      FrameStats()<br>
>      {<br>
> diff -r bc5a7c2ac38b -r 27226b1c447f source/common/picyuv.cpp<br>
> --- a/source/common/picyuv.cpp        Wed Aug 12 15:13:51 2015 +0530<br>
> +++ b/source/common/picyuv.cpp        Thu Aug 13 15:09:29 2015 +0530<br>
> @@ -42,6 +42,9 @@<br>
>      m_cuOffsetC = NULL;<br>
>      m_buOffsetY = NULL;<br>
>      m_buOffsetC = NULL;<br>
> +<br>
> +    m_maxLumaLevel = 0;<br>
> +    m_avgLumaLevel = 0;<br>
>  }<br>
><br>
>  bool PicYuv::create(uint32_t picWidth, uint32_t picHeight, uint32_t picCsp)<br>
> @@ -235,17 +238,25 @@<br>
>          pixel *U = m_picOrg[1];<br>
>          pixel *V = m_picOrg[2];<br>
<br>
<br>
> +        uint64_t sumLuma = 0;<br>
>          for (int r = 0; r < height; r++)<br>
>          {<br>
> -            /* Clip luma of source picture to max and min values before extending edges of picYuv */<br>
> -            for (int c = 0; c < m_stride; c++)<br>
> +            for (int c = 0; c < width; c++)<br>
> +            {<br>
> +                /* Clip luma of source picture to max and min values before extending edges of picYuv */<br>
>                  Y[c] = x265_clip3((pixel)param.minLuma, (pixel)param.maxLuma, Y[c]);<br>
><br>
> +                /* Determine maximum and average luma level in a picture */<br>
> +                m_maxLumaLevel = X265_MAX(Y[c], m_maxLumaLevel);<br>
> +                sumLuma += Y[c];<br>
> +            }<br>
<br>
this whole nested for-loop needs to be moved out of the if (padx)<br>
conditional expression<br>
<br>
> +<br>
>              for (int x = 0; x < padx; x++)<br>
>                  Y[width + x] = Y[width - 1];<br>
><br>
>              Y += m_stride;<br>
>          }<br>
> +        m_avgLumaLevel = (double)(sumLuma) / (m_picHeight * m_picWidth);<br>
><br>
>          for (int r = 0; r < height >> m_vChromaShift; r++)<br>
>          {<br>
> diff -r bc5a7c2ac38b -r 27226b1c447f source/common/picyuv.h<br>
> --- a/source/common/picyuv.h  Wed Aug 12 15:13:51 2015 +0530<br>
> +++ b/source/common/picyuv.h  Thu Aug 13 15:09:29 2015 +0530<br>
> @@ -60,6 +60,9 @@<br>
>      uint32_t m_chromaMarginX;<br>
>      uint32_t m_chromaMarginY;<br>
><br>
> +    uint16_t m_maxLumaLevel;<br>
> +    double   m_avgLumaLevel;<br>
> +<br>
>      PicYuv();<br>
><br>
>      bool  create(uint32_t picWidth, uint32_t picHeight, uint32_t csp);<br>
> diff -r bc5a7c2ac38b -r 27226b1c447f source/encoder/encoder.cpp<br>
> --- a/source/encoder/encoder.cpp      Wed Aug 12 15:13:51 2015 +0530<br>
> +++ b/source/encoder/encoder.cpp      Thu Aug 13 15:09:29 2015 +0530<br>
> @@ -1163,8 +1163,8 @@<br>
>          frameStats->avgChromaDistortion     = curFrame->m_encData->m_frameStats.avgChromaDistortion;<br>
>          frameStats->avgLumaDistortion       = curFrame->m_encData->m_frameStats.avgLumaDistortion;<br>
>          frameStats->avgPsyEnergy            = curFrame->m_encData->m_frameStats.avgPsyEnergy;<br>
> -        frameStats->avgLumaLevel            = curFrame->m_encData->m_frameStats.avgLumaLevel;<br>
> -        frameStats->maxLumaLevel            = curFrame->m_encData->m_frameStats.maxLumaLevel;<br>
> +        frameStats->avgLumaLevel            = curFrame->m_fencPic->m_avgLumaLevel;<br>
> +        frameStats->maxLumaLevel            = curFrame->m_fencPic->m_maxLumaLevel;<br>
>          for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)<br>
>          {<br>
>              frameStats->cuStats.percentSkipCu[depth]  = curFrame->m_encData->m_frameStats.percentSkipCu[depth];<br>
> diff -r bc5a7c2ac38b -r 27226b1c447f source/encoder/frameencoder.cpp<br>
> --- a/source/encoder/frameencoder.cpp Wed Aug 12 15:13:51 2015 +0530<br>
> +++ b/source/encoder/frameencoder.cpp Thu Aug 13 15:09:29 2015 +0530<br>
> @@ -592,10 +592,7 @@<br>
>          m_frame->m_encData->m_frameStats.lumaDistortion   += m_rows[i].rowStats.lumaDistortion;<br>
>          m_frame->m_encData->m_frameStats.chromaDistortion += m_rows[i].rowStats.chromaDistortion;<br>
>          m_frame->m_encData->m_frameStats.psyEnergy        += m_rows[i].rowStats.psyEnergy;<br>
> -        m_frame->m_encData->m_frameStats.lumaLevel        += m_rows[i].rowStats.lumaLevel;<br>
><br>
> -        if (m_rows[i].rowStats.maxLumaLevel > m_frame->m_encData->m_frameStats.maxLumaLevel)<br>
> -            m_frame->m_encData->m_frameStats.maxLumaLevel = m_rows[i].rowStats.maxLumaLevel;<br>
>          for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)<br>
>          {<br>
>              m_frame->m_encData->m_frameStats.cntSkipCu[depth] += m_rows[i].rowStats.cntSkipCu[depth];<br>
> @@ -609,7 +606,6 @@<br>
>      m_frame->m_encData->m_frameStats.avgLumaDistortion   = (double)(m_frame->m_encData->m_frameStats.lumaDistortion / m_frame->m_encData->m_frameStats.totalCtu);<br>
>      m_frame->m_encData->m_frameStats.avgChromaDistortion = (double)(m_frame->m_encData->m_frameStats.chromaDistortion / m_frame->m_encData->m_frameStats.totalCtu);<br>
>      m_frame->m_encData->m_frameStats.avgPsyEnergy        = (double)(m_frame->m_encData->m_frameStats.psyEnergy / m_frame->m_encData->m_frameStats.totalCtu);<br>
> -    m_frame->m_encData->m_frameStats.avgLumaLevel        = (double)(m_frame->m_encData->m_frameStats.lumaLevel / m_frame->m_encData->m_frameStats.totalCtu);<br>
>      m_frame->m_encData->m_frameStats.percentIntraNxN     = (double)(m_frame->m_encData->m_frameStats.cntIntraNxN * 100) / m_frame->m_encData->m_frameStats.totalCu;<br>
>      for (uint32_t depth = 0; depth <= g_maxCUDepth; depth++)<br>
>      {<br>
> @@ -990,17 +986,6 @@<br>
>                  curRow.rowStats.cuIntraDistribution[depth][n] += frameLog.cuIntraDistribution[depth][n];<br>
>          }<br>
><br>
> -        /* calculate maximum and average luma levels */<br>
> -        uint32_t ctuLumaLevel = 0;<br>
> -        uint32_t ctuNoOfPixels = best.fencYuv->m_size * best.fencYuv->m_size;<br>
> -        for (uint32_t i = 0; i < ctuNoOfPixels; i++)<br>
> -        {<br>
> -            pixel p = best.fencYuv->m_buf[0][i];<br>
> -            ctuLumaLevel += p;<br>
> -            curRow.rowStats.maxLumaLevel = X265_MAX(p, curRow.rowStats.maxLumaLevel);<br>
> -        }<br>
> -        curRow.rowStats.lumaLevel += (double)(ctuLumaLevel) / ctuNoOfPixels;<br>
> -<br>
>          curEncData.m_cuStat[cuAddr].totalBits = best.totalBits;<br>
>          x265_emms();<br>
><br>
> _______________________________________________<br>
> x265-devel mailing list<br>
> <a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
> <a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Steve Borho<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</font></span></blockquote></div><br></div>