[x265] [PATCH] stats: use input source pictures to calculate avgerage and max luma level

Steve Borho steve at borho.org
Wed Aug 5 19:02:56 CEST 2015


On 08/05, kavitha at multicorewareinc.com wrote:
> # HG changeset patch
> # User Kavitha Sampath <kavitha at multicorewareinc.com>
> # Date 1438757018 -19800
> #      Wed Aug 05 12:13:38 2015 +0530
> # Node ID 3483e9cffd703c540f75068e358bb8261dd80165
> # Parent  3fa7f6838098854de79d3800b2d775dabaf45705
> stats: use input source pictures to calculate avgerage and max luma level
> 
> diff -r 3fa7f6838098 -r 3483e9cffd70 source/encoder/frameencoder.cpp
> --- a/source/encoder/frameencoder.cpp	Mon Aug 03 14:56:21 2015 -0500
> +++ b/source/encoder/frameencoder.cpp	Wed Aug 05 12:13:38 2015 +0530
> @@ -990,12 +990,12 @@
>          }
>          uint64_t ctuLumaLevel = 0;
>          uint64_t ctuNoOfPixels = 0;
> -        for (uint32_t i = 0; i < (best.reconYuv.m_size * best.reconYuv.m_size); i++)
> +        for (uint32_t i = 0; i < (best.fencYuv->m_size * best.fencYuv->m_size); i++)
>          {
> -            ctuLumaLevel += *(best.reconYuv.m_buf[0] + i);
> +            ctuLumaLevel += *(best.fencYuv->m_buf[0] + i);
>              ctuNoOfPixels++;
> -            if ((*(best.reconYuv.m_buf[0] + i)) > curRow.rowStats.maxLumaLevel)
> -                curRow.rowStats.maxLumaLevel = *(best.reconYuv.m_buf[0] + i);
> +            if ((*(best.fencYuv->m_buf[0] + i)) > curRow.rowStats.maxLumaLevel)
> +                curRow.rowStats.maxLumaLevel = *(best.fencYuv->m_buf[0] + i);
>          }
>          curRow.rowStats.lumaLevel += (double)(ctuLumaLevel / ctuNoOfPixels);

uint64_t is unnecessary, a ctu is at most 64x64 (4096, 12 bits) and a
pixel is at most 12 bits, so 32bits is sufficient.  Recommend some
simplifications:

uint32_t ctuLumaLevel = 0, ctuNoOfPixels = best.fencYuv->m_size * best.fencYuv->m_size;
for (uint32_t i = 0; i < ctuNoOfPixels; i++)
{
    pixel p = best.fencYuv->m_buf[0][i];
    ctuLumaLevel += p;
    curRow.rowStats.maxLumaLevel = X265_MAX(p, curRow.rowStats.maxLumaLevel);
}
curRow.rowStats.lumaLevel += (double)(ctuLumaLevel) / ctuNoOfPixels;

note the change in the last line, making it a floating point division.

-- 
Steve Borho


More information about the x265-devel mailing list