<div dir="ltr"><div># HG changeset patch</div><div># User Deepthi Nandakumar <<a href="mailto:deepthi@multicorewareinc.com">deepthi@multicorewareinc.com</a>></div><div># Date 1468402632 -19800</div><div>#      Wed Jul 13 15:07:12 2016 +0530</div><div># Branch stable</div><div># Node ID 12beb237e9d92337e0ce7eceaf398094559329ab</div><div># Parent  d574d3d5b9cf7d06113b49af60448d1de08e0e67</div><div>hdr: revert calcHDRStats</div><div><br></div><div>This was developed with the goal of calculating the metadata extensions specified</div><div>by the CEA 861.3 specification(from the source YUV). However, we realised that</div><div>the specification is meant to work on RGB data, and transforming YUV (back) to RGB</div><div>domain will yield very different results. So, as of now, the user is required to</div><div>give the maxcll/maxfall arguments (generated as per recommendations) and x265</div><div>will generate the appropriate SEI messages. (Shout out to ColorFront team for</div><div>their helpful clarifications).</div><div><br></div><div>diff -r d574d3d5b9cf -r 12beb237e9d9 source/common/picyuv.cpp</div><div>--- a/source/common/picyuv.cpp<span class="" style="white-space:pre"> </span>Mon Jul 04 13:36:51 2016 +0530</div><div>+++ b/source/common/picyuv.cpp<span class="" style="white-space:pre">       </span>Wed Jul 13 15:07:12 2016 +0530</div><div>@@ -289,12 +289,14 @@</div><div>     pixel *V = m_picOrg[2];</div><div> </div><div> #if HIGH_BIT_DEPTH</div><div>-    bool calcHDRParams = !!param.minLuma || !!param.maxCLL || (param.maxLuma != PIXEL_MAX);</div><div>-    /* Apply min/max luma bounds and calculate max and avg luma levels for HDR SEI messages */</div><div>+    bool calcHDRParams = !!param.minLuma || (param.maxLuma != PIXEL_MAX);</div><div>+    /* Apply min/max luma bounds for HDR pixel manipulations */</div><div>     if (calcHDRParams)</div><div>     {</div><div>         X265_CHECK(pic.bitDepth == 10, "HDR stats can be applied/calculated only for 10bpp content");</div><div>-        primitives.calcHDRStats(Y, U, V, m_stride, m_strideC, width, height, &m_avgLumaLevel, &m_maxLumaLevel, (pixel)param.minLuma, (pixel)param.maxLuma, m_hChromaShift, m_vChromaShift);</div><div>+        uint64_t sumLuma;</div><div>+        m_maxLumaLevel = primitives.planeClipAndMax(Y, m_stride, width, height, &sumLuma, (pixel)param.minLuma, (pixel)param.maxLuma);</div><div>+        m_avgLumaLevel = (double) sumLuma / (m_picHeight * m_picWidth);</div><div>     }</div><div> #else</div><div>     (void) param;</div><div>diff -r d574d3d5b9cf -r 12beb237e9d9 source/common/pixel.cpp</div><div>--- a/source/common/pixel.cpp<span class="" style="white-space:pre">  </span>Mon Jul 04 13:36:51 2016 +0530</div><div>+++ b/source/common/pixel.cpp<span class="" style="white-space:pre">        </span>Wed Jul 13 15:07:12 2016 +0530</div><div>@@ -889,69 +889,27 @@</div><div> }</div><div> </div><div> #if HIGH_BIT_DEPTH</div><div>-static void calcHDRStats_c(pixel *srcY, pixel* srcU, pixel* srcV, intptr_t stride, intptr_t strideC, int width, int height, double *outsum, </div><div>-                           pixel *outMax, const pixel minPix, const pixel maxPix, const int hShift, const int vShift)</div><div>+static pixel planeClipAndMax_c(pixel *src, intptr_t stride, int width, int height, uint64_t *outsum, </div><div>+                               const pixel minPix, const pixel maxPix)</div><div> {</div><div>-    pixel rgb[3];</div><div>-    uint16_t maxRGB = 0, maxLumaLevel = 0;</div><div>-    uint64_t rowsumLuma = 0;</div><div>-    double rowavgLuma = 0;</div><div>+    pixel maxLumaLevel = 0;</div><div>+    uint64_t sumLuma = 0;</div><div> </div><div>-    uint16_t minLegal = (uint16_t)MIN_HDR_LEGAL_RANGE, maxLegal = (uint16_t)MAX_HDR_LEGAL_RANGE;</div><div>+    for (int r = 0; r < height; r++)</div><div>+    {</div><div>+        for (int c = 0; c < width; c++)</div><div>+        {</div><div>+            /* Clip luma of source picture to max and min*/</div><div>+            src[c] = x265_clip3((pixel)minPix, (pixel)maxPix, src[c]);</div><div>+            maxLumaLevel = X265_MAX(src[c], maxLumaLevel);</div><div>+            sumLuma += src[c];</div><div>+        }</div><div>+        src += stride;</div><div>+    }</div><div>+    *outsum = sumLuma;</div><div>+    return maxLumaLevel;</div><div>+}</div><div> </div><div>-    for (int r = 0; r < height >> vShift; r++)</div><div>-    {</div><div>-        rowsumLuma = 0;</div><div>-        for (int c = 0; c < width >> hShift; c++)</div><div>-        {</div><div>-            pixel y = 0, cb = 0, cr = 0;</div><div>-            /* Clip luma of source picture to max and min, only if they are specified. Average luma values for RGB conversions */</div><div>-            if (!hShift && !vShift) /* YUV444 */</div><div>-            {</div><div>-                y = srcY[c] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[c]);</div><div>-                cb = srcU[c]; cr = srcV[c];</div><div>-            }</div><div>-            else if (hShift && !vShift) /* YUV422 */</div><div>-            {</div><div>-                srcY[2*c] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[2*c]);</div><div>-                srcY[2*c + 1] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[2*c + 1]);</div><div>-                y = (srcY[2*c] + srcY[2*c + 1]) >> 1;</div><div>-                cb = srcU[c]; cr = srcV[c];</div><div>-            }</div><div>-            else if (hShift && vShift) /* YUV420 */</div><div>-            {</div><div>-                srcY[2*c] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[2*c]);</div><div>-                srcY[2*c + 1] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[2*c + 1]);</div><div>-                srcY[stride + 2*c] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[stride + 2*c]);</div><div>-                srcY[stride + 2*c + 1] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[stride + 2*c + 1]);</div><div>-                y = (srcY[2*c] + srcY[2*c + 1] + srcY[stride + 2*c] + srcY[stride + 2*c + 1]) >> 2;</div><div>-                cb = srcU[c]; cr = srcV[c];</div><div>-            }</div><div>-            else if (!strideC) /* YUV400 */</div><div>-            {</div><div>-                y = srcY[c] = x265_clip3((pixel)minPix, (pixel)maxPix, srcY[c]);</div><div>-                cb = cr = 0;</div><div>-            }</div><div>-            /* Rec 2020 Yuv to RGB */</div><div>-            for (int i = 0; i < 3; i++)</div><div>-                rgb[i] = (pixel) (y * g_YUVtoRGB_BT2020[i][0] + (cb - CBCR_OFFSET) * g_YUVtoRGB_BT2020[i][1] + (cr - CBCR_OFFSET) * g_YUVtoRGB_BT2020[i][2]);</div><div>-            /* maxCLL and maxFALL */</div><div>-            maxRGB = X265_MAX(maxRGB, X265_MAX(rgb[0], X265_MAX(rgb[1], rgb[2])));</div><div>-            maxRGB = X265_MIN(X265_MAX(maxRGB, minLegal), maxLegal);</div><div>-            maxLumaLevel = (uint16_t) g_ST2084_PQTable[maxRGB - minLegal];</div><div>-            rowsumLuma += maxLumaLevel;</div><div>-        }</div><div>-        srcY += stride << vShift; </div><div>-        if (strideC)</div><div>-        {</div><div>-            srcU += strideC;</div><div>-            srcV += strideC;</div><div>-        }</div><div>-        rowavgLuma += ((double)rowsumLuma / width);</div><div>-    }</div><div>-    *outsum = rowavgLuma / height;</div><div>-    *outMax = maxLumaLevel;</div><div>-}</div><div> #endif</div><div> }  // end anonymous namespace</div><div> </div><div>@@ -1238,7 +1196,7 @@</div><div>     p.planecopy_sp = planecopy_sp_c;</div><div>     p.planecopy_sp_shl = planecopy_sp_shl_c;</div><div> #if HIGH_BIT_DEPTH</div><div>-    p.calcHDRStats = calcHDRStats_c;</div><div>+    p.planeClipAndMax = planeClipAndMax_c;</div><div> #endif</div><div>     p.propagateCost = estimateCUPropagateCost;</div><div>     p.fix8Unpack = cuTreeFix8Unpack;</div><div>diff -r d574d3d5b9cf -r 12beb237e9d9 source/common/primitives.h</div><div>--- a/source/common/primitives.h<span class="" style="white-space:pre">       </span>Mon Jul 04 13:36:51 2016 +0530</div><div>+++ b/source/common/primitives.h<span class="" style="white-space:pre">     </span>Wed Jul 13 15:07:12 2016 +0530</div><div>@@ -185,7 +185,7 @@</div><div> typedef void (*sign_t)(int8_t *dst, const pixel *src1, const pixel *src2, const int endX);</div><div> typedef void (*planecopy_cp_t) (const uint8_t* src, intptr_t srcStride, pixel* dst, intptr_t dstStride, int width, int height, int shift);</div><div> typedef void (*planecopy_sp_t) (const uint16_t* src, intptr_t srcStride, pixel* dst, intptr_t dstStride, int width, int height, int shift, uint16_t mask);</div><div>-typedef void (*calcHDRStats_t)(pixel *srcY, pixel* srcU, pixel* srcV, intptr_t stride, intptr_t strideC, int width, int height, double *outsum, pixel *outMax, const pixel minPix, const pixel maxPix, const int hShift, const int vShift);</div><div>+typedef pixel (*planeClipAndMax_t)(pixel *src, intptr_t stride, int width, int height, uint64_t *outsum, const pixel minPix, const pixel maxPix);</div><div> </div><div> typedef void (*cutree_propagate_cost) (int* dst, const uint16_t* propagateIn, const int32_t* intraCosts, const uint16_t* interCosts, const int32_t* invQscales, const double* fpsFactor, int len);</div><div> </div><div>@@ -324,7 +324,7 @@</div><div>     planecopy_cp_t        planecopy_cp;</div><div>     planecopy_sp_t        planecopy_sp;</div><div>     planecopy_sp_t        planecopy_sp_shl;</div><div>-    calcHDRStats_t        calcHDRStats;</div><div>+    planeClipAndMax_t     planeClipAndMax;</div><div> </div><div>     weightp_sp_t          weight_sp;</div><div>     weightp_pp_t          weight_pp;</div><div>diff -r d574d3d5b9cf -r 12beb237e9d9 source/common/x86/asm-primitives.cpp</div><div>--- a/source/common/x86/asm-primitives.cpp<span class="" style="white-space:pre">   </span>Mon Jul 04 13:36:51 2016 +0530</div><div>+++ b/source/common/x86/asm-primitives.cpp<span class="" style="white-space:pre">   </span>Wed Jul 13 15:07:12 2016 +0530</div><div>@@ -2157,6 +2157,9 @@</div><div>         p.fix8Unpack = PFX(cutree_fix8_unpack_avx2);</div><div>         p.fix8Pack = PFX(cutree_fix8_pack_avx2);</div><div> </div><div>+        /* TODO: This kernel needs to be modified to work with HIGH_BIT_DEPTH only </div><div>+        p.planeClipAndMax = PFX(planeClipAndMax_avx2); */</div><div>+</div><div>         // TODO: depends on hps and vsp</div><div>         ALL_LUMA_PU_T(luma_hvpp, interp_8tap_hv_pp_cpu);                        // calling luma_hvpp for all sizes</div><div>         p.pu[LUMA_4x4].luma_hvpp = interp_8tap_hv_pp_cpu<LUMA_4x4>;             // ALL_LUMA_PU_T has declared all sizes except 4x4, hence calling luma_hvpp[4x4] </div><div>diff -r d574d3d5b9cf -r 12beb237e9d9 source/common/x86/pixel.h</div><div>--- a/source/common/x86/pixel.h<span class="" style="white-space:pre">       </span>Mon Jul 04 13:36:51 2016 +0530</div><div>+++ b/source/common/x86/pixel.h<span class="" style="white-space:pre">      </span>Wed Jul 13 15:07:12 2016 +0530</div><div>@@ -36,6 +36,7 @@</div><div> void PFX(upShift_16_avx2)(const uint16_t* src, intptr_t srcStride, pixel* dst, intptr_t dstStride, int width, int height, int shift, uint16_t mask);</div><div> void PFX(upShift_8_sse4)(const uint8_t* src, intptr_t srcStride, pixel* dst, intptr_t dstStride, int width, int height, int shift);</div><div> void PFX(upShift_8_avx2)(const uint8_t* src, intptr_t srcStride, pixel* dst, intptr_t dstStride, int width, int height, int shift);</div><div>+pixel PFX(planeClipAndMax_avx2)(pixel *src, intptr_t stride, int width, int height, uint64_t *outsum, const pixel minPix, const pixel maxPix);</div><div> </div><div> #define DECL_PIXELS(cpu) \</div><div>     FUNCDEF_PU(sse_t, pixel_ssd, cpu, const pixel*, intptr_t, const pixel*, intptr_t); \</div><div>diff -r d574d3d5b9cf -r 12beb237e9d9 source/encoder/encoder.cpp</div><div>--- a/source/encoder/encoder.cpp<span class="" style="white-space:pre">     </span>Mon Jul 04 13:36:51 2016 +0530</div><div>+++ b/source/encoder/encoder.cpp<span class="" style="white-space:pre">     </span>Wed Jul 13 15:07:12 2016 +0530</div><div>@@ -1243,12 +1243,6 @@</div><div> </div><div>         stats->maxCLL         = m_analyzeAll.m_maxCLL;</div><div>         stats->maxFALL        = (uint16_t)(m_analyzeAll.m_maxFALL / m_analyzeAll.m_numPics);</div><div>-</div><div>-        if (m_emitCLLSEI)</div><div>-        {</div><div>-            m_param->maxCLL = stats->maxCLL;</div><div>-            m_param->maxFALL = stats->maxFALL;</div><div>-        }</div><div>     }</div><div> </div><div>     /* If new statistics are added to x265_stats, we must check here whether the</div><div><br></div><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div>Deepthi Nandakumar<br></div>Engineering Manager, x265<br></div>Multicoreware, Inc<br></div></div>
</div>