[x265] primitives: change planeClipAndMax to calcStats_HDR, add YUV to RGB conversions
Deepthi Nandakumar
deepthi at multicorewareinc.com
Tue Mar 1 04:53:21 CET 2016
# HG changeset patch
# User Deepthi Nandakumar <deepthi at multicorewareinc.com>
# Date 1456592330 -19800
# Sat Feb 27 22:28:50 2016 +0530
# Node ID 631fe6745d9deaab1577b769c6e8feb79ca084da
# Parent 107d56fa9b06ae9d240b0608d38d403ccc974b7a
primitives: change planeClipAndMax to calcStats_HDR, add YUV to RGB
conversions
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/constants.cpp
--- a/source/common/constants.cpp Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/constants.cpp Sat Feb 27 22:28:50 2016 +0530
@@ -568,4 +568,11 @@
{ 42, 43, 46, 47, 58, 59, 62, 63, }
};
+const double g_YUVtoRGB_BT2020[3][3] =
+{
+ { 1.00, 0.00, 1.47460, },
+ { 1.00, -0.16455, -0.57135, },
+ { 1.00, 1.88140, 0.00, }
+};
+
}
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/constants.h
--- a/source/common/constants.h Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/constants.h Sat Feb 27 22:28:50 2016 +0530
@@ -98,6 +98,8 @@
extern const uint32_t g_depthScanIdx[8][8];
+extern const double g_YUVtoRGB_BT2020[3][3];
+
}
#endif
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/picyuv.cpp
--- a/source/common/picyuv.cpp Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/picyuv.cpp Sat Feb 27 22:28:50 2016 +0530
@@ -46,6 +46,8 @@
m_maxLumaLevel = 0;
m_avgLumaLevel = 0;
+ m_stride = 0;
+ m_strideC = 0;
}
bool PicYuv::create(uint32_t picWidth, uint32_t picHeight, uint32_t picCsp)
@@ -283,11 +285,13 @@
pixel *U = m_picOrg[1];
pixel *V = m_picOrg[2];
+ bool calcHDRParams = !!param.maxLuma || !!param.minLuma ||
!!param.maxCLL;
/* Apply min/max luma bounds and calculate max and avg luma levels for
HDR SEI messages */
- if (!!param.maxLuma || !!param.minLuma || !!param.maxCLL)
+ if (calcHDRParams)
{
+ X265_CHECK(pic.bitDepth == 10, "HDR stats can be
applied/calculated only for 10bpp content");
uint64_t sumLuma;
- m_maxLumaLevel = primitives.planeClipAndMax(Y, m_stride, width,
height, &sumLuma, (pixel)param.minLuma, (pixel)param.maxLuma);
+ primitives.calcHDRStats(Y, U, V, m_stride, m_strideC, width,
height, &sumLuma, &m_maxLumaLevel, (pixel)param.minLuma,
(pixel)param.maxLuma, m_hChromaShift, m_vChromaShift);
m_avgLumaLevel = (double)(sumLuma) / (m_picHeight * m_picWidth);
}
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/picyuv.h
--- a/source/common/picyuv.h Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/picyuv.h Sat Feb 27 22:28:50 2016 +0530
@@ -60,7 +60,7 @@
uint32_t m_chromaMarginX;
uint32_t m_chromaMarginY;
- uint16_t m_maxLumaLevel;
+ pixel m_maxLumaLevel;
double m_avgLumaLevel;
PicYuv();
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/pixel.cpp
--- a/source/common/pixel.cpp Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/pixel.cpp Sat Feb 27 22:28:50 2016 +0530
@@ -873,28 +873,86 @@
}
}
-static pixel planeClipAndMax_c(pixel *src, intptr_t stride, int width, int
height, uint64_t *outsum, const pixel minPix, const pixel maxPix)
+static void calcHDRStats_c(pixel *srcY, pixel* srcU, pixel* srcV, intptr_t
stride, intptr_t strideC, int width, int height, uint64_t *outsum,
+ pixel *outMax, const pixel minPix, const pixel
maxPix, const int hShift, const int vShift)
{
pixel maxLumaLevel = 0;
uint64_t sumLuma = 0;
+ pixel rgb[3];
- for (int r = 0; r < height; r++)
+ if (!hShift && !vShift) /* YUV444 */
{
- for (int c = 0; c < width; c++)
+ for (int r = 0; r < height; r++)
{
- /* Clip luma of source picture to max and min values before
extending edges of picYuv */
- src[c] = x265_clip3((pixel)minPix, (pixel)maxPix, src[c]);
+ for (int c = 0; c < width; c++)
+ {
+ /* Clip luma of source picture to max and min */
+ srcY[c] = x265_clip3((pixel)minPix, (pixel)maxPix,
srcY[c]);
- /* Determine maximum and average luma level in a picture */
- maxLumaLevel = X265_MAX(src[c], maxLumaLevel);
- sumLuma += src[c];
+ /* Rec 2020 Yuv to RGB */
+ for (int i = 0; i < 3; i++)
+ rgb[i] = (pixel) (srcY[c] * g_YUVtoRGB_BT2020[i][0] +
srcU[c] * g_YUVtoRGB_BT2020[i][1] + srcV[c] * g_YUVtoRGB_BT2020[i][2]);
+ /* maxCLL and maxFALL */
+ maxLumaLevel = X265_MAX(maxLumaLevel, X265_MAX(rgb[0],
X265_MAX(rgb[1], rgb[2])));
+ sumLuma += maxLumaLevel;
+ }
+ srcY += stride; srcU += strideC; srcV += strideC;
}
-
- src += stride;
}
-
+ else if (hShift && !vShift) /* YUV422 */
+ {
+ for (int r = 0; r < height; r++)
+ {
+ for (int c = 0; c < width >> hShift; c++)
+ {
+ 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]);
+ pixel y = (srcY[2*c] + srcY[2*c + 1]) >> 1;
+ for (int i = 0; i < 3; i++)
+ rgb[i] = (pixel)(y * g_YUVtoRGB_BT2020[i][0] + srcU[c]
* g_YUVtoRGB_BT2020[i][1] + srcV[c] * g_YUVtoRGB_BT2020[i][2]);
+ maxLumaLevel = X265_MAX(maxLumaLevel, X265_MAX(rgb[0],
X265_MAX(rgb[1], rgb[2])));
+ sumLuma += maxLumaLevel;
+ }
+ srcY += stride; srcU += strideC; srcV += strideC;
+ }
+ }
+ else if (hShift && vShift) /* YUV420 */
+ {
+ for (int r = 0; r < height >> vShift; r++)
+ {
+ for (int c = 0; c < width >> vShift; c++)
+ {
+ 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]);
+ pixel y = (srcY[2*c] + srcY[2*c + 1] + srcY[stride + 2*c]
+ srcY[stride + 2*c + 1]) >> 2;
+ for (int i = 0; i < 3; i++)
+ rgb[i] = (pixel) (y * g_YUVtoRGB_BT2020[i][0] +
srcU[c] * g_YUVtoRGB_BT2020[i][1] + srcV[c] * g_YUVtoRGB_BT2020[i][2]);
+ maxLumaLevel = X265_MAX(maxLumaLevel, X265_MAX(rgb[0],
X265_MAX(rgb[1], rgb[2])));
+ sumLuma += maxLumaLevel;
+ }
+ srcY += (stride << 1); srcU += strideC; srcV += strideC;
+ }
+ }
+ else if (!strideC) /* YUV400 */
+ {
+ for (int r = 0; r < height; r++)
+ {
+ for (int c = 0; c < width; c++)
+ {
+ srcY[c] = x265_clip3((pixel)minPix, (pixel)maxPix,
srcY[c]);
+ for (int i = 0; i < 3; i++)
+ rgb[i] = (pixel) (srcY[c] * g_YUVtoRGB_BT2020[i][0]);
+ /* maxCLL and maxFALL */
+ maxLumaLevel = X265_MAX(maxLumaLevel, X265_MAX(rgb[0],
X265_MAX(rgb[1], rgb[2])));
+ sumLuma += maxLumaLevel;
+ }
+ srcY += stride;
+ }
+ }
*outsum = sumLuma;
- return maxLumaLevel;
+ *outMax = maxLumaLevel;
}
} // end anonymous namespace
@@ -1181,7 +1239,7 @@
p.planecopy_cp = planecopy_cp_c;
p.planecopy_sp = planecopy_sp_c;
p.planecopy_sp_shl = planecopy_sp_shl_c;
- p.planeClipAndMax = planeClipAndMax_c;
+ p.calcHDRStats = calcHDRStats_c;
p.propagateCost = estimateCUPropagateCost;
}
}
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/primitives.h
--- a/source/common/primitives.h Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/primitives.h Sat Feb 27 22:28:50 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 pixel (*planeClipAndMax_t)(pixel *src, intptr_t stride, int width,
int height, uint64_t *outsum, const pixel minPix, const pixel maxPix);
+typedef void (*calcHDRStats_t)(pixel *srcY, pixel* srcU, pixel* srcV,
intptr_t stride, intptr_t strideC, int width, int height, uint64_t *outsum,
pixel *outMax, const pixel minPix, const pixel maxPix, const int hShift,
const int vShift);
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);
@@ -318,7 +318,7 @@
planecopy_cp_t planecopy_cp;
planecopy_sp_t planecopy_sp;
planecopy_sp_t planecopy_sp_shl;
- planeClipAndMax_t planeClipAndMax;
+ calcHDRStats_t calcHDRStats;
weightp_sp_t weight_sp;
weightp_pp_t weight_pp;
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/x86/asm-primitives.cpp
--- a/source/common/x86/asm-primitives.cpp Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/x86/asm-primitives.cpp Sat Feb 27 22:28:50 2016 +0530
@@ -3658,7 +3658,6 @@
p.chroma[X265_CSP_I420].cu[CHROMA_420_32x32].copy_ps =
PFX(blockcopy_ps_32x32_avx2);
p.chroma[X265_CSP_I422].cu[CHROMA_422_32x64].copy_ps =
PFX(blockcopy_ps_32x64_avx2);
p.cu[BLOCK_64x64].copy_ps = PFX(blockcopy_ps_64x64_avx2);
- p.planeClipAndMax = PFX(planeClipAndMax_avx2);
p.pu[LUMA_32x8].sad_x3 = PFX(pixel_sad_x3_32x8_avx2);
p.pu[LUMA_32x16].sad_x3 = PFX(pixel_sad_x3_32x16_avx2);
diff -r 107d56fa9b06 -r 631fe6745d9d source/common/x86/pixel.h
--- a/source/common/x86/pixel.h Sun Feb 28 14:22:40 2016 +0530
+++ b/source/common/x86/pixel.h Sat Feb 27 22:28:50 2016 +0530
@@ -36,7 +36,6 @@
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 107d56fa9b06 -r 631fe6745d9d source/test/pixelharness.cpp
--- a/source/test/pixelharness.cpp Sun Feb 28 14:22:40 2016 +0530
+++ b/source/test/pixelharness.cpp Sat Feb 27 22:28:50 2016 +0530
@@ -1818,34 +1818,6 @@
return true;
}
-bool PixelHarness::check_planeClipAndMax(planeClipAndMax_t ref,
planeClipAndMax_t opt)
-{
- for (int i = 0; i < ITERS; i++)
- {
- intptr_t rand_stride = rand() % STRIDE;
- int rand_width = (rand() % (STRIDE * 2)) + 1;
- const int rand_height = (rand() % MAX_HEIGHT) + 1;
- const pixel rand_min = rand() % 32;
- const pixel rand_max = PIXEL_MAX - (rand() % 32);
- uint64_t ref_sum, opt_sum;
-
- // video width must be more than or equal to 32
- if (rand_width < 32)
- rand_width = 32;
-
- // stride must be more than or equal to width
- if (rand_stride < rand_width)
- rand_stride = rand_width;
-
- pixel ref_max = ref(pbuf1, rand_stride, rand_width, rand_height,
&ref_sum, rand_min, rand_max);
- pixel opt_max = (pixel)checked(opt, pbuf1, rand_stride,
rand_width, rand_height, &opt_sum, rand_min, rand_max);
-
- if (ref_max != opt_max)
- return false;
- }
- return true;
-}
-
bool PixelHarness::check_pelFilterLumaStrong_H(pelFilterLumaStrong_t ref,
pelFilterLumaStrong_t opt)
{
intptr_t srcStep = 1, offset = 64;
@@ -2543,15 +2515,6 @@
}
- if (opt.planeClipAndMax)
- {
- if (!check_planeClipAndMax(ref.planeClipAndMax,
opt.planeClipAndMax))
- {
- printf("planeClipAndMax failed!\n");
- return false;
- }
- }
-
if (opt.pelFilterLumaStrong[0])
{
if (!check_pelFilterLumaStrong_V(ref.pelFilterLumaStrong[0],
opt.pelFilterLumaStrong[0]))
@@ -3047,13 +3010,6 @@
REPORT_SPEEDUP(opt.costC1C2Flag, ref.costC1C2Flag, abscoefBuf,
C1FLAG_NUMBER, (uint8_t*)psbuf1, 1);
}
- if (opt.planeClipAndMax)
- {
- HEADER0("planeClipAndMax");
- uint64_t dummy;
- REPORT_SPEEDUP(opt.planeClipAndMax, ref.planeClipAndMax, pbuf1,
128, 63, 62, &dummy, 1, PIXEL_MAX - 1);
- }
-
if (opt.pelFilterLumaStrong[0])
{
int32_t tcP = (rand() % PIXEL_MAX) - 1;
diff -r 107d56fa9b06 -r 631fe6745d9d source/test/pixelharness.h
--- a/source/test/pixelharness.h Sun Feb 28 14:22:40 2016 +0530
+++ b/source/test/pixelharness.h Sat Feb 27 22:28:50 2016 +0530
@@ -120,7 +120,6 @@
bool check_costCoeffNxN(costCoeffNxN_t ref, costCoeffNxN_t opt);
bool check_costCoeffRemain(costCoeffRemain_t ref, costCoeffRemain_t
opt);
bool check_costC1C2Flag(costC1C2Flag_t ref, costC1C2Flag_t opt);
- bool check_planeClipAndMax(planeClipAndMax_t ref, planeClipAndMax_t
opt);
bool check_pelFilterLumaStrong_V(pelFilterLumaStrong_t ref,
pelFilterLumaStrong_t opt);
bool check_pelFilterLumaStrong_H(pelFilterLumaStrong_t ref,
pelFilterLumaStrong_t opt);
--
Deepthi Nandakumar
Engineering Manager, x265
Multicoreware, Inc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20160301/3bb337b5/attachment-0001.html>
More information about the x265-devel
mailing list