From 57c7389200a4b01bec554b8482948a4f587be605 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sat, 15 Apr 2023 15:24:51 -0500 Subject: [PATCH] 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. --- Userland/Libraries/LibVideo/VP9/Decoder.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibVideo/VP9/Decoder.cpp b/Userland/Libraries/LibVideo/VP9/Decoder.cpp index a01a5681fb..15d9efd82e 100644 --- a/Userland/Libraries/LibVideo/VP9/Decoder.cpp +++ b/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) { // return (value < 0 ? value - 1 : value + 1) / 2 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) { // return (value < 0 ? value - 2 : value + 2) / 4 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 }; };