vp7: fix split block chroma motion compensation
[nihav.git] / nihav-duck / src / codecs / vp7.rs
index ea423ad26145b2070bd88df7c038eea9620b9a23..a4a0d1bf26a55df420c1661e59f6d0cacd93b028 100644 (file)
@@ -552,7 +552,7 @@ impl VP7Decoder {
             }
             if has_ac[24] {
                 idct4x4(y2block);
-            } else {
+            } else if y2block[0] != 0 {
                 idct4x4_dc(y2block);
             }
             for i in 0..16 {
@@ -562,7 +562,7 @@ impl VP7Decoder {
         for i in 0..24 {
             if has_ac[i] {
                 idct4x4(&mut self.coeffs[i]);
-            } else {
+            } else if self.coeffs[i][0] != 0 {
                 idct4x4_dc(&mut self.coeffs[i]);
             }
         }
@@ -871,13 +871,14 @@ impl VP7Decoder {
                     }
                 }
             }
+            let tr_edge = if has_top { ydst[yoff - ystride + 15] } else { 0x80 };
             for y in 0..4 {
                 for x in 0..4 {
                     ipred_ctx_y.has_left = has_left || x > 0;
                     let bmode = self.ymodes[iidx + x];
                     let cur_yoff = yoff + x * 4;
-                    let has_tr = has_top && ((x < 3) || ((y == 0) && (mb_y < self.mb_w - 1)));
-                    let has_dl = ipred_ctx_y.has_left && (y < 3);
+                    let has_tr = ipred_ctx_y.has_top && ((x < 3) || ((y == 0) && (mb_y < self.mb_w - 1)));
+                    let has_dl = ipred_ctx_y.has_left && (x == 0) && (y < 3);
                     ipred_ctx_y.fill(ydst, cur_yoff, ystride,
                                      if has_tr { 8 } else { 4 },
                                      if has_dl { 8 } else { 4 });
@@ -890,6 +891,11 @@ impl VP7Decoder {
                             tr_save[x * 4 + i] = ipred_ctx_y.top[i + 4];
                         }
                     }
+                    if (mb_x == self.mb_w - 1) && has_top && (x == 3) {
+                        for i in 0..4 {
+                            ipred_ctx_y.top[i + 4] = tr_edge;
+                        }
+                    }
                     match bmode {
                         PredMode::DCPred => IPred4x4::ipred_dc(ydst, cur_yoff, ystride, ipred_ctx_y),
                         PredMode::TMPred => IPred4x4::ipred_tm(ydst, cur_yoff, ystride, ipred_ctx_y),
@@ -1011,22 +1017,32 @@ impl VP7Decoder {
         } else {
             for y in 0..2 {
                 for x in 0..2 {
-                    let mut chroma_mv = self.mvs[iidx] + self.mvs[iidx + 1]
-                                       + self.mvs[iidx + self.mv_stride]
-                                       + self.mvs[iidx + self.mv_stride + 1];
-                    chroma_mv.x /= 4;
-                    chroma_mv.y /= 4;
+                    let mut chroma_mv = self.mvs[iidx + x * 2] + self.mvs[iidx + x * 2 + 1]
+                                       + self.mvs[iidx + x * 2 + self.mv_stride]
+                                       + self.mvs[iidx + x * 2 + self.mv_stride + 1];
+                    if chroma_mv.x < 0 {
+                        chroma_mv.x += 1;
+                    } else {
+                        chroma_mv.x += 2;
+                    }
+                    if chroma_mv.y < 0 {
+                        chroma_mv.y += 1;
+                    } else {
+                        chroma_mv.y += 2;
+                    }
+                    chroma_mv.x >>= 2;
+                    chroma_mv.y >>= 2;
 
                     if pitch_smode == 0 {
-                        mc_block4x4(dst, uoff, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
+                        mc_block4x4(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
                                     chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf);
-                        mc_block4x4(dst, voff, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
+                        mc_block4x4(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
                                     chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf);
                     } else {
-                        mc_block_special(dst, uoff, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
+                        mc_block_special(dst, uoff + x * 4, ustride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
                                          chroma_mv.x, chroma_mv.y, refframe.clone(), 1, &mut mc_buf,
                                          4, pitch_smode);
-                        mc_block_special(dst, voff, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
+                        mc_block_special(dst, voff + x * 4, vstride, mb_x * 8 + x * 4, mb_y * 8 + y * 4,
                                          chroma_mv.x, chroma_mv.y, refframe.clone(), 2, &mut mc_buf,
                                          4, pitch_smode);
                     }