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