From: Kostya Shishkov Date: Sat, 16 Mar 2019 06:36:14 +0000 (+0100) Subject: bink2: implement calc_dc as in the reference X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=5de1b1183a7a086f03fa5de407bb5df2445a3524;p=nihav.git bink2: implement calc_dc as in the reference --- diff --git a/nihav-rad/src/codecs/bink2.rs b/nihav-rad/src/codecs/bink2.rs index 775a558..e200a0c 100644 --- a/nihav-rad/src/codecs/bink2.rs +++ b/nihav-rad/src/codecs/bink2.rs @@ -133,13 +133,30 @@ macro_rules! chroma_interp { }; } +macro_rules! avg_tree { + ($a: expr, $b: expr) => (($a + $b + 1) >> 1); + ($a: expr, $b: expr, $c: expr, $d: expr) => (avg_tree!(avg_tree!($a, $b), avg_tree!($c, $d))); +} + impl Bink2DSP { fn calc_dc(src: &[u8], stride: usize) -> i32 { + let mut sums = [0u16; 8]; + for i in 0..8 { + let s0 = src[i + stride * 0] as u16; + let s1 = src[i + stride * 1] as u16; + let s2 = src[i + stride * 2] as u16; + let s3 = src[i + stride * 3] as u16; + let s4 = src[i + stride * 4] as u16; + let s5 = src[i + stride * 5] as u16; + let s6 = src[i + stride * 6] as u16; + let s7 = src[i + stride * 7] as u16; + sums[i] = avg_tree!(avg_tree!(s0, s1, s2, s3), avg_tree!(s4, s5, s6, s7)); + } let mut sum = 0; - for row in src.chunks(stride).take(8) { - for i in 0..8 { sum += row[i] as i32; } + for e in sums.iter() { + sum += e; } - sum >> 3 + sum as i32 } fn put_mb4(dst: &mut [u8], mut off: usize, stride: usize, blk: &mut [[i32; 64]; 4]) { bink2_idct(&mut blk[0]);