浏览代码

LibVideo/VP9: Fix rounding of components in the motion vector selection

The division in the `round_mv_...()` functions contained in the motion
vector selection process was done by bit shifting right. However, since
bit shifting negative values will truncate towards the negative end, it
was flooring instead of rounding.

This changes it to match the spec and rely on the compiler to simplify
down to a bit shift.
Zaggy1024 2 年之前
父节点
当前提交
57c7389200
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      Userland/Libraries/LibVideo/VP9/Decoder.cpp

+ 4 - 4
Userland/Libraries/LibVideo/VP9/Decoder.cpp

@@ -693,15 +693,15 @@ MotionVector Decoder::select_motion_vector(u8 plane, BlockContext const& block_c
     auto round_mv_comp_q2 = [&](MotionVector in) {
     auto round_mv_comp_q2 = [&](MotionVector in) {
         // return (value < 0 ? value - 1 : value + 1) / 2
         // return (value < 0 ? value - 1 : value + 1) / 2
         return MotionVector {
         return MotionVector {
-            (in.row() < 0 ? in.row() - 1 : in.row() + 1) >> 1,
-            (in.column() < 0 ? in.column() - 1 : in.column() + 1) >> 1
+            (in.row() < 0 ? in.row() - 1 : in.row() + 1) / 2,
+            (in.column() < 0 ? in.column() - 1 : in.column() + 1) / 2
         };
         };
     };
     };
     auto round_mv_comp_q4 = [&](MotionVector in) {
     auto round_mv_comp_q4 = [&](MotionVector in) {
         // return (value < 0 ? value - 2 : value + 2) / 4
         // return (value < 0 ? value - 2 : value + 2) / 4
         return MotionVector {
         return MotionVector {
-            (in.row() < 0 ? in.row() - 2 : in.row() + 2) >> 2,
-            (in.column() < 0 ? in.column() - 2 : in.column() + 2) >> 2
+            (in.row() < 0 ? in.row() - 2 : in.row() + 2) / 4,
+            (in.column() < 0 ? in.column() - 2 : in.column() + 2) / 4
         };
         };
     };
     };