From d12a08712bfff48ee508bfd1048f231c298916d5 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Fri, 23 Jan 2015 22:16:33 +0000 Subject: [PATCH] adjust ubias to minimize error histogram centering error. BUG=324 TESTED=TestFullYUV R=harryjin@google.com Review URL: https://webrtc-codereview.appspot.com/37739004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@1248 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/version.h | 2 +- source/row_common.cc | 31 +++++++++++++++---------------- source/row_win.cc | 35 ++++++++++++++++------------------- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/README.chromium b/README.chromium index 09108862b..1149a0738 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1247 +Version: 1248 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 2ed7931ed..f79b54c0c 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1247 +#define LIBYUV_VERSION 1248 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/source/row_common.cc b/source/row_common.cc index d68ce1894..0204298d1 100644 --- a/source/row_common.cc +++ b/source/row_common.cc @@ -960,40 +960,39 @@ void I400ToARGBRow_C(const uint8* src_y, uint8* dst_argb, int width) { } } -// C reference code that mimics the YUV assembly. +// YUV to RGB conversion constants. #define YG 19071 /* round(1.164 * 64 * 256) */ #define YGB 1197 /* 1.164 * 64 * 16 - adjusted for even error distribution */ - -// TODO(fbarchard): Adjusted U and V bias for even error distribution. #define UB -128 /* -min(128, round(2.018 * 64)) */ +#define UBB -16385 /* approx -round(2.018 * 64 * 128) */ #define UG 25 /* -round(-0.391 * 64) */ -#define UR 0 - -#define VB 0 +#define UGB 3200 /* -round(-0.391 * 64) * 128 */ #define VG 52 /* -round(-0.813 * 64) */ +#define VGB 6656 /* -round(-0.813 * 64) * 128 */ #define VR -102 /* -round(1.596 * 64) */ +#define VRB -13056 /* -round(1.596 * 64) * 128 */ +#define BB (UBB - YGB) +#define BG (UGB + VGB - YGB) +#define BR ( VRB - YGB) -// Bias -#define BB (UB * 128 + VB * 128 - YGB) -#define BG (UG * 128 + VG * 128 - YGB) -#define BR (UR * 128 + VR * 128 - YGB) - +// C reference code that mimics the YUV assembly. static __inline void YuvPixel(uint8 y, uint8 u, uint8 v, uint8* b, uint8* g, uint8* r) { uint32 y1 = (uint32)(y * 0x0101 * YG) >> 16; - *b = Clamp((int32)(BB - (v * VB + u * UB) + y1) >> 6); + *b = Clamp((int32)(BB - ( u * UB) + y1) >> 6); *g = Clamp((int32)(BG - (v * VG + u * UG) + y1) >> 6); - *r = Clamp((int32)(BR - (v * VR + u * UR) + y1) >> 6); + *r = Clamp((int32)(BR - (v * VR ) + y1) >> 6); } - #undef YG #undef YGB #undef UB +#undef UBB #undef UG -#undef UR -#undef VB +#undef UGB #undef VG +#undef VGB #undef VR +#undef VRB #undef BB #undef BG #undef BR diff --git a/source/row_win.cc b/source/row_win.cc index 4b09d7598..805caa79d 100644 --- a/source/row_win.cc +++ b/source/row_win.cc @@ -24,30 +24,27 @@ extern "C" { #if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && \ (defined(_M_IX86) || defined(_M_X64)) -// YUV conversion constants. +// YUV to RGB conversion constants. #define YG 19071 /* round(1.164 * 64 * 256) */ #define YGB 1197 /* 1.164 * 64 * 16 - adjusted for even error distribution */ - -// TODO(fbarchard): Adjusted U and V bias for even error distribution. #define UB -128 /* -min(128, round(2.018 * 64)) */ +#define UBB -16385 /* approx -round(2.018 * 64 * 128) */ #define UG 25 /* -round(-0.391 * 64) */ -#define UR 0 - -#define VB 0 +#define UGB 3200 /* -round(-0.391 * 64) * 128 */ #define VG 52 /* -round(-0.813 * 64) */ +#define VGB 6656 /* -round(-0.813 * 64) * 128 */ #define VR -102 /* -round(1.596 * 64) */ - -// Bias -#define BB (UB * 128 + VB * 128 - YGB) -#define BG (UG * 128 + VG * 128 - YGB) -#define BR (UR * 128 + VR * 128 - YGB) +#define VRB -13056 /* -round(1.596 * 64) * 128 */ +#define BB (UBB - YGB) +#define BG (UGB + VGB - YGB) +#define BR ( VRB - YGB) static const vec8 kUVToB = { - UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB + UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0 }; static const vec8 kUVToR = { - UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR + 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR }; static const vec8 kUVToG = { @@ -55,11 +52,11 @@ static const vec8 kUVToG = { }; static const vec8 kVUToB = { - VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, + 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, }; static const vec8 kVUToR = { - VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, + VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, }; static const vec8 kVUToG = { @@ -1475,12 +1472,12 @@ void RGBAToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb, #if defined(HAS_I422TOARGBROW_AVX2) || defined(HAS_I422TOBGRAROW_AVX2) static const lvec8 kUVToB_AVX = { - UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, - UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB, UB, VB + UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, + UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0, UB, 0 }; static const lvec8 kUVToR_AVX = { - UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, - UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR, UR, VR + 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, + 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR, 0, VR }; static const lvec8 kUVToG_AVX = { UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG, UG, VG,