realmedia/rv40dsp: fix 3,3 luma motion interpolation
[nihav.git] / nihav-realmedia / src / codecs / rv40dsp.rs
index 030321c30acd10307a22d8514de807c445fbdbcb..dce273a74c7a3d5edadce6f2da8c1008d4d216c4 100644 (file)
@@ -1,6 +1,6 @@
 use nihav_core::frame::{FrameType, NAVideoBuffer};
-use nihav_core::codecs::MV;
-use nihav_core::codecs::blockdsp::edge_emu;
+use nihav_codec_support::codecs::MV;
+use nihav_codec_support::codecs::blockdsp::edge_emu;
 use super::rv3040::{RV34DSP, RV34MBInfo};
 
 fn clip8(a: i16) -> u8 {
@@ -38,6 +38,12 @@ macro_rules! filter {
                      -5 * el!($s, $o + 2 * $step)
                         + el!($s, $o + 3 * $step) + 32) >> 6) as i16)
         );
+    (33; $s: ident, $o: expr, $stride: expr) => (
+            clip8(((  el!($s, $o)
+                    + el!($s, $o + 1)
+                    + el!($s, $o + $stride)
+                    + el!($s, $o + 1 + $stride) + 2) >> 2) as i16)
+        );
 }
 
 macro_rules! mc_func {
@@ -130,6 +136,15 @@ macro_rules! mc_func {
             $ofilt(dst, didx, dstride, &buf, 2*bstride, $size);
         }
         );
+    (mc33; $name: ident, $size: expr) => (
+        fn $name (dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut sidx: usize, sstride: usize) {
+            for _ in 0..$size {
+                for x in 0..$size { dst[didx + x] = filter!(33; src, sidx + x, sstride); }
+                sidx += sstride;
+                didx += dstride;
+            }
+        }
+        );
 }
 mc_func!(copy; copy_16, 16);
 mc_func!(copy; copy_8,   8);
@@ -161,8 +176,8 @@ mc_func!(cm03; luma_mc_31_16, 16, luma_mc_01_16);
 mc_func!(cm03; luma_mc_31_8,   8, luma_mc_01_8);
 mc_func!(cm03; luma_mc_32_16, 16, luma_mc_02_16);
 mc_func!(cm03; luma_mc_32_8,   8, luma_mc_02_8);
-mc_func!(cm03; luma_mc_33_16, 16, luma_mc_03_16);
-mc_func!(cm03; luma_mc_33_8,   8, luma_mc_03_8);
+mc_func!(mc33; luma_mc_33_16, 16);
+mc_func!(mc33; luma_mc_33_8,   8);
 
 const RV40_CHROMA_BIAS: [[u16; 4]; 4] = [
     [ 0, 4, 8, 4 ],
@@ -299,6 +314,7 @@ fn rv40_weak_loop_filter4_h(pix: &mut [u8], off: usize, stride: usize,
                             lim_p0q0: i16, lim_p1: i16, lim_q1: i16) {
     rv40_weak_loop_filter4(pix, off, stride, 1, filter_p1, filter_q1, alpha, beta, lim_p0q0, lim_p1, lim_q1);
 }
+#[allow(clippy::eq_op)]
 fn rv40_weak_loop_filter4_v(pix: &mut [u8], off: usize, stride: usize,
                             filter_p1: bool, filter_q1: bool, alpha: i16, beta: i16,
                             lim_p0q0: i16, lim_p1: i16, lim_q1: i16) {
@@ -457,6 +473,7 @@ fn rv40_loop_strength_h(pix: &[u8], off: usize, stride: usize,
     rv40_loop_strength(pix, off, stride, 1, beta, beta2, edge)
 }
 
+#[allow(clippy::eq_op)]
 fn rv40_loop_strength_v(pix: &[u8], off: usize, stride: usize,
                         beta: i16, beta2: i16, edge: bool) -> (bool, bool, bool) {
     let src = &pix[off - 3..][..stride * 3 + 3 + 3];
@@ -564,7 +581,7 @@ const RV40_EDGE1: [isize; 4] = [ 0, 2, 2, 2 ];
 const RV40_EDGE2: [isize; 4] = [ 0, 3, 3, 3 ];
 
 impl RV34DSP for RV40DSP {
-    fn loop_filter(&self, frame: &mut NAVideoBuffer<u8>, _ftype: FrameType, mbinfo: &[RV34MBInfo], mb_w: usize, row: usize) {
+    fn loop_filter(&self, frame: &mut NAVideoBuffer<u8>, _ftype: FrameType, mbinfo: &[RV34MBInfo], mb_w: usize, mb_h: usize, row: usize) {
         // todo proper B-frame filtering?
         let mut offs:   [usize; 3] = [0; 3];
         let mut stride: [usize; 3] = [0; 3];
@@ -577,7 +594,7 @@ impl RV34DSP for RV40DSP {
             offs[comp] = frame.get_offset(comp) + start * stride[comp];
         }
 
-        let mut data = frame.get_data_mut();
+        let data = frame.get_data_mut().unwrap();
         let dst: &mut [u8] = data.as_mut_slice();
 
         let mut mb_pos: usize = row * mb_w;
@@ -810,7 +827,7 @@ impl RV34DSP for RV40DSP {
         let size: usize = if use16 { 16 } else { 8 };
         let dstride = frame.get_stride(0);
         let doffset = frame.get_offset(0) + (if !avg { x + y * dstride } else { 0 });
-        let mut data = frame.get_data_mut();
+        let data = frame.get_data_mut().unwrap();
         let dst: &mut [u8] = data.as_mut_slice();
 
         let (w_, h_) = prev_frame.get_dimensions(0);
@@ -840,7 +857,7 @@ impl RV34DSP for RV40DSP {
         let size: usize = if use8 { 8 } else { 4 };
         let dstride = frame.get_stride(comp);
         let doffset = frame.get_offset(comp) + (if !avg { x + y * dstride } else { 0 });
-        let mut data = frame.get_data_mut();
+        let data = frame.get_data_mut().unwrap();
         let dst: &mut [u8] = data.as_mut_slice();
 
         let (w_, h_) = prev_frame.get_dimensions(comp);