summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVideo
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2022-11-25 04:19:35 -0600
committerAndreas Kling <kling@serenityos.org>2022-11-30 08:28:30 +0100
commitd82dc14bd9f92904805bb9029dd2fb2f9a4ea361 (patch)
treeab208931dc5951019c4fe97eb180f97e449b9ae4 /Userland/Libraries/LibVideo
parentf4761dab09a4fd2dd4a9293e255f5e2f27bd95e8 (diff)
downloadserenity-d82dc14bd9f92904805bb9029dd2fb2f9a4ea361.zip
LibVideo/VP9: Use a bitwise enum for motion vector joint selection
The motion vector joints enum is set up so that the first bit indicates that a vector should have a non-zero value in the column, and the second bit indicates a non-zero value for the row. Taking advantage of this makes the code a bit more legible.
Diffstat (limited to 'Userland/Libraries/LibVideo')
-rw-r--r--Userland/Libraries/LibVideo/VP9/Enums.h7
-rw-r--r--Userland/Libraries/LibVideo/VP9/LookupTables.h6
-rw-r--r--Userland/Libraries/LibVideo/VP9/Parser.cpp16
3 files changed, 14 insertions, 15 deletions
diff --git a/Userland/Libraries/LibVideo/VP9/Enums.h b/Userland/Libraries/LibVideo/VP9/Enums.h
index f639cc38bf..a46c4c41bc 100644
--- a/Userland/Libraries/LibVideo/VP9/Enums.h
+++ b/Userland/Libraries/LibVideo/VP9/Enums.h
@@ -113,10 +113,9 @@ enum class PredictionMode : u8 {
};
enum MvJoint : u8 {
- MvJointZero = 0,
- MvJointHnzvz = 1,
- MvJointHzvnz = 2,
- MvJointHnzvnz = 3,
+ MotionVectorAllZero = 0,
+ MotionVectorNonZeroColumn = 1,
+ MotionVectorNonZeroRow = 2,
};
enum MvClass : u8 {
diff --git a/Userland/Libraries/LibVideo/VP9/LookupTables.h b/Userland/Libraries/LibVideo/VP9/LookupTables.h
index b0a3fcde6e..ff14b95275 100644
--- a/Userland/Libraries/LibVideo/VP9/LookupTables.h
+++ b/Userland/Libraries/LibVideo/VP9/LookupTables.h
@@ -142,9 +142,9 @@ static constexpr int interp_filter_tree[4] = {
-EightTapSmooth, -EightTapSharp
};
static constexpr int mv_joint_tree[6] = {
- -MvJointZero, 2,
- -MvJointHnzvz, 4,
- -MvJointHzvnz, -MvJointHnzvnz
+ -MotionVectorAllZero, 2,
+ -MotionVectorNonZeroColumn, 4,
+ -MotionVectorNonZeroRow, -(MotionVectorNonZeroColumn | MotionVectorNonZeroRow)
};
static constexpr int mv_class_tree[20] = {
-MvClass0, 2,
diff --git a/Userland/Libraries/LibVideo/VP9/Parser.cpp b/Userland/Libraries/LibVideo/VP9/Parser.cpp
index 8bd4a8d053..3da0601ef6 100644
--- a/Userland/Libraries/LibVideo/VP9/Parser.cpp
+++ b/Userland/Libraries/LibVideo/VP9/Parser.cpp
@@ -1276,14 +1276,14 @@ static bool should_use_high_precision_motion_vector(MotionVector const& delta_ve
DecoderErrorOr<MotionVector> Parser::read_motion_vector(BlockContext const& block_context, BlockMotionVectorCandidates const& candidates, ReferenceIndex reference_index)
{
m_use_hp = block_context.frame_context.high_precision_motion_vectors_allowed && should_use_high_precision_motion_vector(candidates[reference_index].best_vector);
- MotionVector diff_mv;
- auto mv_joint = TRY_READ(TreeParser::parse_motion_vector_joint(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter));
- if (mv_joint == MvJointHzvnz || mv_joint == MvJointHnzvnz)
- diff_mv.set_row(TRY(read_single_motion_vector_component(0)));
- if (mv_joint == MvJointHnzvz || mv_joint == MvJointHnzvnz)
- diff_mv.set_column(TRY(read_single_motion_vector_component(1)));
-
- return candidates[reference_index].best_vector + diff_mv;
+ MotionVector delta_vector;
+ auto joint = TRY_READ(TreeParser::parse_motion_vector_joint(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter));
+ if ((joint & MotionVectorNonZeroRow) != 0)
+ delta_vector.set_row(TRY(read_single_motion_vector_component(0)));
+ if ((joint & MotionVectorNonZeroColumn) != 0)
+ delta_vector.set_column(TRY(read_single_motion_vector_component(1)));
+
+ return candidates[reference_index].best_vector + delta_vector;
}
// read_mv_component( comp ) in the spec.