From dd6800c5c3d91e52b8586e8aaa7db987da52342d Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Wed, 6 Oct 2021 09:35:01 +0200 Subject: [PATCH] core/scale: use BT.601 YUV by default in conversion --- nihav-core/src/scale/colorcvt.rs | 8 +++++--- nihav-core/src/scale/mod.rs | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/nihav-core/src/scale/colorcvt.rs b/nihav-core/src/scale/colorcvt.rs index 0343bdd..bc6c4b6 100644 --- a/nihav-core/src/scale/colorcvt.rs +++ b/nihav-core/src/scale/colorcvt.rs @@ -1,6 +1,8 @@ use super::*; use super::kernel::Kernel; +const DEFAULT_YUV: usize = 4; + const YUV_PARAMS: &[[f32; 2]] = &[ [ 0.333, 0.333 ], // RGB [ 0.2126, 0.0722 ], // ITU-R BT709 @@ -172,7 +174,7 @@ impl Kernel for RgbToYuv { fn init(&mut self, in_fmt: &ScaleInfo, dest_fmt: &ScaleInfo) -> ScaleResult { let mut df = dest_fmt.fmt; //todo coeff selection - make_rgb2yuv(YUV_PARAMS[2][0], YUV_PARAMS[2][1], &mut self.matrix); + make_rgb2yuv(YUV_PARAMS[DEFAULT_YUV][0], YUV_PARAMS[DEFAULT_YUV][1], &mut self.matrix); if let ColorModel::YUV(yuvsm) = df.get_model() { match yuvsm { YUVSubmodel::YCbCr => {}, @@ -302,12 +304,12 @@ impl Kernel for YuvToRgb { } } //todo coeff selection - make_yuv2rgb(YUV_PARAMS[2][0], YUV_PARAMS[2][1], &mut self.matrix); + make_yuv2rgb(YUV_PARAMS[DEFAULT_YUV][0], YUV_PARAMS[DEFAULT_YUV][1], &mut self.matrix); if let ColorModel::YUV(yuvsm) = in_fmt.fmt.get_model() { match yuvsm { YUVSubmodel::YCbCr => {}, YUVSubmodel::YIQ => { - make_rgb2yuv(YUV_PARAMS[2][0], YUV_PARAMS[2][1], &mut self.matrix); + make_rgb2yuv(YUV_PARAMS[DEFAULT_YUV][0], YUV_PARAMS[DEFAULT_YUV][1], &mut self.matrix); apply_ntsc_rgb2yiq(SMPTE_NTSC_COEFFS, &mut self.matrix); invert_matrix(&mut self.matrix); }, diff --git a/nihav-core/src/scale/mod.rs b/nihav-core/src/scale/mod.rs index b67a620..caf489b 100644 --- a/nihav-core/src/scale/mod.rs +++ b/nihav-core/src/scale/mod.rs @@ -530,9 +530,9 @@ mod test { let uoff = obuf.get_offset(1); let voff = obuf.get_offset(2); let odata = obuf.get_data(); - assert_eq!(odata[yoff], 28); - assert_eq!(odata[uoff], 154); - assert_eq!(odata[voff], 103); + assert_eq!(odata[yoff], 11); + assert_eq!(odata[uoff], 162); + assert_eq!(odata[voff], 118); } #[test] fn test_scale_and_convert_to_pal() { @@ -550,7 +550,7 @@ mod test { let odata = obuf.get_data(); assert_eq!(odata[dataoff], 0); assert_eq!(odata[paloff], 157); - assert_eq!(odata[paloff + 1], 99); + assert_eq!(odata[paloff + 1], 129); assert_eq!(odata[paloff + 2], 170); } } -- 2.30.2