diff options
author | Zaggy1024 <zaggy1024@gmail.com> | 2022-10-08 22:50:35 -0500 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-10-09 20:32:40 -0600 |
commit | 6c648329c4ebb767a52d4cc1367743b18ac49e21 (patch) | |
tree | bcdb21a7eb59705a8fe028a996aed56a94810bd8 /Userland/Libraries | |
parent | 1dc46526832861715e020bafcbdae877a64a036a (diff) | |
download | serenity-6c648329c4ebb767a52d4cc1367743b18ac49e21.zip |
LibVideo: Add MotionVector lookup tables as constant expressions
This changes MotionVector by removing the cpp file and moving all
functions to the header, where they are now declared as constexpr
so that they can be compile-time evaluated in LookupTables.h.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibVideo/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibVideo/VP9/LookupTables.h | 42 | ||||
-rw-r--r-- | Userland/Libraries/LibVideo/VP9/MotionVector.cpp | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibVideo/VP9/MotionVector.h | 57 | ||||
-rw-r--r-- | Userland/Libraries/LibVideo/VP9/Parser.cpp | 6 |
5 files changed, 89 insertions, 46 deletions
diff --git a/Userland/Libraries/LibVideo/CMakeLists.txt b/Userland/Libraries/LibVideo/CMakeLists.txt index 0d18a82a27..5da617f954 100644 --- a/Userland/Libraries/LibVideo/CMakeLists.txt +++ b/Userland/Libraries/LibVideo/CMakeLists.txt @@ -2,7 +2,6 @@ set(SOURCES MatroskaReader.cpp VP9/BitStream.cpp VP9/Decoder.cpp - VP9/MotionVector.cpp VP9/Parser.cpp VP9/ProbabilityTables.cpp VP9/SyntaxElementCounter.cpp diff --git a/Userland/Libraries/LibVideo/VP9/LookupTables.h b/Userland/Libraries/LibVideo/VP9/LookupTables.h index 9dc6966f2e..3d384e5f55 100644 --- a/Userland/Libraries/LibVideo/VP9/LookupTables.h +++ b/Userland/Libraries/LibVideo/VP9/LookupTables.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com> + * Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,6 +8,7 @@ #pragma once #include "Enums.h" +#include "MotionVector.h" #include "Symbols.h" namespace Video::VP9 { @@ -289,4 +291,44 @@ static constexpr u8 cat_probs[7][14] = { { 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129 } }; +static constexpr MotionVector mv_ref_blocks[BLOCK_SIZES][MVREF_NEIGHBOURS] = { + { { -1, 0 }, { 0, -1 }, { -1, -1 }, { -2, 0 }, { 0, -2 }, { -2, -1 }, { -1, -2 }, { -2, -2 } }, + { { -1, 0 }, { 0, -1 }, { -1, -1 }, { -2, 0 }, { 0, -2 }, { -2, -1 }, { -1, -2 }, { -2, -2 } }, + { { -1, 0 }, { 0, -1 }, { -1, -1 }, { -2, 0 }, { 0, -2 }, { -2, -1 }, { -1, -2 }, { -2, -2 } }, + { { -1, 0 }, { 0, -1 }, { -1, -1 }, { -2, 0 }, { 0, -2 }, { -2, -1 }, { -1, -2 }, { -2, -2 } }, + { { 0, -1 }, { -1, 0 }, { 1, -1 }, { -1, -1 }, { 0, -2 }, { -2, 0 }, { -2, -1 }, { -1, -2 } }, + { { -1, 0 }, { 0, -1 }, { -1, 1 }, { -1, -1 }, { -2, 0 }, { 0, -2 }, { -1, -2 }, { -2, -1 } }, + { { -1, 0 }, { 0, -1 }, { -1, 1 }, { 1, -1 }, { -1, -1 }, { -3, 0 }, { 0, -3 }, { -3, -3 } }, + { { 0, -1 }, { -1, 0 }, { 2, -1 }, { -1, -1 }, { -1, 1 }, { 0, -3 }, { -3, 0 }, { -3, -3 } }, + { { -1, 0 }, { 0, -1 }, { -1, 2 }, { -1, -1 }, { 1, -1 }, { -3, 0 }, { 0, -3 }, { -3, -3 } }, + { { -1, 1 }, { 1, -1 }, { -1, 2 }, { 2, -1 }, { -1, -1 }, { -3, 0 }, { 0, -3 }, { -3, -3 } }, + { { 0, -1 }, { -1, 0 }, { 4, -1 }, { -1, 2 }, { -1, -1 }, { 0, -3 }, { -3, 0 }, { 2, -1 } }, + { { -1, 0 }, { 0, -1 }, { -1, 4 }, { 2, -1 }, { -1, -1 }, { -3, 0 }, { 0, -3 }, { -1, 2 } }, + { { -1, 3 }, { 3, -1 }, { -1, 4 }, { 4, -1 }, { -1, -1 }, { -1, 0 }, { 0, -1 }, { -1, 6 } } +}; + +static constexpr u8 mode_2_counter[MB_MODE_COUNT] = { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 3, 1 }; + +static constexpr u8 counter_to_context[19] = { + BOTH_PREDICTED, + NEW_PLUS_NON_INTRA, + BOTH_NEW, + ZERO_PLUS_PREDICTED, + NEW_PLUS_NON_INTRA, + INVALID_CASE, + BOTH_ZERO, + INVALID_CASE, + INVALID_CASE, + INTRA_PLUS_NON_INTRA, + INTRA_PLUS_NON_INTRA, + INVALID_CASE, + INTRA_PLUS_NON_INTRA, + INVALID_CASE, + INVALID_CASE, + INVALID_CASE, + INVALID_CASE, + INVALID_CASE, + BOTH_INTRA +}; + } diff --git a/Userland/Libraries/LibVideo/VP9/MotionVector.cpp b/Userland/Libraries/LibVideo/VP9/MotionVector.cpp deleted file mode 100644 index e4e7b21698..0000000000 --- a/Userland/Libraries/LibVideo/VP9/MotionVector.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "MotionVector.h" - -namespace Video::VP9 { - -MotionVector::MotionVector(u32 row, u32 col) - : m_row(row) - , m_col(col) -{ -} - -MotionVector& MotionVector::operator=(i32 value) -{ - m_row = value; - m_col = value; - return *this; -} - -MotionVector MotionVector::operator+(MotionVector const& other) const -{ - return MotionVector(this->row() + other.row(), this->col() + other.col()); -} - -} diff --git a/Userland/Libraries/LibVideo/VP9/MotionVector.h b/Userland/Libraries/LibVideo/VP9/MotionVector.h index 6c13300dd7..dac793aa4d 100644 --- a/Userland/Libraries/LibVideo/VP9/MotionVector.h +++ b/Userland/Libraries/LibVideo/VP9/MotionVector.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Hunter Salyer <thefalsehonesty@gmail.com> + * Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,22 +11,52 @@ namespace Video::VP9 { -class MotionVector { +struct MotionVector { public: - MotionVector() = default; - MotionVector(u32 row, u32 col); - - u32 row() const { return m_row; } - void set_row(u32 row) { m_row = row; } - u32 col() const { return m_col; } - void set_col(u32 col) { m_col = col; } - - MotionVector& operator=(i32 value); - MotionVector operator+(MotionVector const& other) const; + constexpr MotionVector() = default; + constexpr MotionVector(MotionVector const& other) = default; + constexpr MotionVector(i32 row, i32 col) + : m_row(row) + , m_column(col) + { + } + + constexpr MotionVector& operator=(MotionVector const& other) = default; + constexpr MotionVector& operator=(MotionVector&& other) = default; + + constexpr i32 row() const { return m_row; } + constexpr void set_row(i32 row) { m_row = row; } + constexpr i32 column() const { return m_column; } + constexpr void set_column(i32 col) { m_column = col; } + + constexpr MotionVector operator+(MotionVector const& other) const + { + return MotionVector(this->row() + other.row(), this->column() + other.column()); + } + constexpr MotionVector& operator+=(MotionVector const& other) + { + *this = *this + other; + return *this; + } + + constexpr MotionVector operator*(i32 scalar) const + { + return MotionVector(this->row() * scalar, this->column() * scalar); + } + constexpr MotionVector& operator*=(i32 scalar) + { + *this = *this * scalar; + return *this; + } + + constexpr bool operator==(MotionVector const& other) const + { + return this->row() == other.row() && this->column() == other.column(); + } private: - u32 m_row { 0 }; - u32 m_col { 0 }; + i32 m_row { 0 }; + i32 m_column { 0 }; }; } diff --git a/Userland/Libraries/LibVideo/VP9/Parser.cpp b/Userland/Libraries/LibVideo/VP9/Parser.cpp index fb02e14ffe..ff22ce5d60 100644 --- a/Userland/Libraries/LibVideo/VP9/Parser.cpp +++ b/Userland/Libraries/LibVideo/VP9/Parser.cpp @@ -1190,7 +1190,7 @@ DecoderErrorOr<void> Parser::read_ref_frames() DecoderErrorOr<void> Parser::assign_mv(bool is_compound) { - m_mv[1] = 0; + m_mv[1] = {}; for (auto i = 0; i < 1 + is_compound; i++) { if (m_y_mode == NewMv) { TRY(read_mv(i)); @@ -1199,7 +1199,7 @@ DecoderErrorOr<void> Parser::assign_mv(bool is_compound) } else if (m_y_mode == NearMv) { m_mv[i] = m_near_mv[i]; } else { - m_mv[i] = 0; + m_mv[i] = {}; } } return {}; @@ -1213,7 +1213,7 @@ DecoderErrorOr<void> Parser::read_mv(u8 ref) if (mv_joint == MvJointHzvnz || mv_joint == MvJointHnzvnz) diff_mv.set_row(TRY(read_mv_component(0))); if (mv_joint == MvJointHnzvz || mv_joint == MvJointHnzvnz) - diff_mv.set_col(TRY(read_mv_component(1))); + diff_mv.set_column(TRY(read_mv_component(1))); m_mv[ref] = m_best_mv[ref] + diff_mv; return {}; } |