Browse Source

LibVideo/VP9: Convert token scan order indices to u16

They are directly taken from lookup tables that only need that bit
precision, so may as well shrink them.
Zaggy1024 2 years ago
parent
commit
062da60443

File diff suppressed because it is too large
+ 9 - 9
Userland/Libraries/LibVideo/VP9/LookupTables.h


+ 9 - 9
Userland/Libraries/LibVideo/VP9/Parser.cpp

@@ -1421,7 +1421,7 @@ DecoderErrorOr<bool> Parser::residual(BlockContext& block_context, bool has_bloc
     return had_residual_tokens;
 }
 
-static u32 const* get_scan(TXSize tx_size, u8 transform_type)
+static u16 const* get_scan(TXSize tx_size, u8 transform_type)
 {
     if (tx_size == TX_4x4) {
         if (transform_type == ADST_DCT)
@@ -1449,14 +1449,14 @@ static u32 const* get_scan(TXSize tx_size, u8 transform_type)
 
 DecoderErrorOr<bool> Parser::tokens(BlockContext& block_context, size_t plane, u32 start_x, u32 start_y, TXSize tx_size, u8 transform_type)
 {
-    u32 segment_eob = 16 << (tx_size << 1);
+    u16 segment_eob = 16 << (tx_size << 1);
     auto const* scan = get_scan(tx_size, transform_type);
     auto check_eob = true;
-    u32 c = 0;
-    for (; c < segment_eob; c++) {
-        auto pos = scan[c];
-        auto band = (tx_size == TX_4x4) ? coefband_4x4[c] : coefband_8x8plus[c];
-        auto tokens_context = TreeParser::get_tokens_context(block_context.frame_context.color_config.subsampling_x, block_context.frame_context.color_config.subsampling_y, block_context.frame_context.rows(), block_context.frame_context.columns(), m_above_nonzero_context, m_left_nonzero_context, m_token_cache, tx_size, transform_type, plane, start_x, start_y, pos, block_context.is_inter_predicted(), band, c);
+    u16 coef_index = 0;
+    for (; coef_index < segment_eob; coef_index++) {
+        auto pos = scan[coef_index];
+        auto band = (tx_size == TX_4x4) ? coefband_4x4[coef_index] : coefband_8x8plus[coef_index];
+        auto tokens_context = TreeParser::get_tokens_context(block_context.frame_context.color_config.subsampling_x, block_context.frame_context.color_config.subsampling_y, block_context.frame_context.rows(), block_context.frame_context.columns(), m_above_nonzero_context, m_left_nonzero_context, m_token_cache, tx_size, transform_type, plane, start_x, start_y, pos, block_context.is_inter_predicted(), band, coef_index);
         if (check_eob) {
             auto more_coefs = TRY_READ(TreeParser::parse_more_coefficients(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter, tokens_context));
             if (!more_coefs)
@@ -1474,9 +1474,9 @@ DecoderErrorOr<bool> Parser::tokens(BlockContext& block_context, size_t plane, u
             check_eob = true;
         }
     }
-    for (u32 i = c; i < segment_eob; i++)
+    for (u16 i = coef_index; i < segment_eob; i++)
         m_tokens[scan[i]] = 0;
-    return c > 0;
+    return coef_index > 0;
 }
 
 DecoderErrorOr<i32> Parser::read_coef(u8 bit_depth, Token token)

+ 2 - 2
Userland/Libraries/LibVideo/VP9/TreeParser.cpp

@@ -624,10 +624,10 @@ ErrorOr<bool> TreeParser::parse_motion_vector_hp(BitStream& bit_stream, Probabil
     return value;
 }
 
-TokensContext TreeParser::get_tokens_context(bool subsampling_x, bool subsampling_y, u32 rows, u32 columns, Array<Vector<bool>, 3> const& above_nonzero_context, Array<Vector<bool>, 3> const& left_nonzero_context, u8 token_cache[1024], TXSize tx_size, u8 tx_type, u8 plane, u32 start_x, u32 start_y, u32 position, bool is_inter, u8 band, u32 c)
+TokensContext TreeParser::get_tokens_context(bool subsampling_x, bool subsampling_y, u32 rows, u32 columns, Array<Vector<bool>, 3> const& above_nonzero_context, Array<Vector<bool>, 3> const& left_nonzero_context, u8 token_cache[1024], TXSize tx_size, u8 tx_type, u8 plane, u32 start_x, u32 start_y, u16 position, bool is_inter, u8 band, u16 coef_index)
 {
     u8 context;
-    if (c == 0) {
+    if (coef_index == 0) {
         auto sx = plane > 0 ? subsampling_x : false;
         auto sy = plane > 0 ? subsampling_y : false;
         auto max_x = (2 * columns) >> sx;

+ 1 - 1
Userland/Libraries/LibVideo/VP9/TreeParser.h

@@ -76,7 +76,7 @@ public:
     static ErrorOr<u8> parse_motion_vector_fr(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, u8 component);
     static ErrorOr<bool> parse_motion_vector_hp(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, u8 component, bool use_hp);
 
-    static TokensContext get_tokens_context(bool subsampling_x, bool subsampling_y, u32 rows, u32 columns, Array<Vector<bool>, 3> const& above_nonzero_context, Array<Vector<bool>, 3> const& left_nonzero_context, u8 token_cache[1024], TXSize tx_size, u8 tx_type, u8 plane, u32 start_x, u32 start_y, u32 position, bool is_inter, u8 band, u32 c);
+    static TokensContext get_tokens_context(bool subsampling_x, bool subsampling_y, u32 rows, u32 columns, Array<Vector<bool>, 3> const& above_nonzero_context, Array<Vector<bool>, 3> const& left_nonzero_context, u8 token_cache[1024], TXSize tx_size, u8 tx_type, u8 plane, u32 start_x, u32 start_y, u16 position, bool is_inter, u8 band, u16 coef_index);
     static ErrorOr<bool> parse_more_coefficients(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, TokensContext const& context);
     static ErrorOr<Token> parse_token(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, TokensContext const& context);
 };

Some files were not shown because too many files changed in this diff