rv6: fix special case for chroma motion compensation
[nihav.git] / nihav-realmedia / src / codecs / rv60dsp.rs
index 3a90123f44d9571a24acc747e43d530385bfdac3..be88a3e1b9fbfcf6d67f4f23783c500612b06957 100644 (file)
@@ -110,10 +110,12 @@ fn chroma_mc(dst: &mut [u8], mut didx: usize, dstride: usize, src: &[u8], mut si
         return;
     }
     if (x > 0) && (y > 0) {
-        let a = ((4 - x) * (4 - y)) as u16;
-        let b = ((    x) * (4 - y)) as u16;
-        let c = ((4 - x) * (    y)) as u16;
-        let d = ((    x) * (    y)) as u16;
+        // 3,3 case is the same as 3,2 for some reason
+        let ymod = if (x == 3) && (y == 3) { 2 } else { y };
+        let a = ((4 - x) * (4 - ymod)) as u16;
+        let b = ((    x) * (4 - ymod)) as u16;
+        let c = ((4 - x) * (    ymod)) as u16;
+        let d = ((    x) * (    ymod)) as u16;
         for _ in 0..h {
             for x in 0..w {
                 dst[didx + x] = ((a * (src[sidx + x] as u16)
@@ -492,7 +494,7 @@ impl RV60DSP {
                 luma_mc(dst, doffset, dstride, src, soffset, sstride, w, h, cx, cy);
             } else {
                 let mut ebuf: [u8; 70*70] = [0; 70*70];
-                edge_emu(prev_frame, (x as isize) + (dx as isize) - 2, (y as isize) + (dy as isize) - 2, w+5, h+5, &mut ebuf, 70, 0, 0);
+                edge_emu(prev_frame, (x as isize) + (dx as isize) - 2, (y as isize) + (dy as isize) - 2, w+5, h+5, &mut ebuf, 70, 0, 4);
                 luma_mc(dst, doffset, dstride, &ebuf, 70*2 + 2, 70, w, h, cx, cy);
             }
         }
@@ -520,7 +522,7 @@ impl RV60DSP {
                 chroma_mc(frame.data, doffset, dstride, src, soffset, sstride, cw, ch, cx, cy);
             } else {
                 let mut ebuf: [u8; 40*40] = [0; 40*40];
-                edge_emu(prev_frame, ((x >> 1) as isize) + (dx as isize), ((y >> 1) as isize) + (dy as isize), cw+1, ch+1, &mut ebuf, 40, comp, 0);
+                edge_emu(prev_frame, ((x >> 1) as isize) + (dx as isize), ((y >> 1) as isize) + (dy as isize), cw+1, ch+1, &mut ebuf, 40, comp, 3);
                 chroma_mc(frame.data, doffset, dstride, &ebuf, 0, 40, cw, ch, cx, cy);
             }
         }