1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

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.
This commit is contained in:
Zaggy1024 2023-04-15 15:24:51 -05:00 committed by Tim Flynn
parent 7b10c8048c
commit 57c7389200

View file

@ -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
};
};