diff --git a/Userland/Libraries/LibVideo/VP9/Parser.cpp b/Userland/Libraries/LibVideo/VP9/Parser.cpp index 7a26b252b7..5d7c18617c 100644 --- a/Userland/Libraries/LibVideo/VP9/Parser.cpp +++ b/Userland/Libraries/LibVideo/VP9/Parser.cpp @@ -1200,7 +1200,7 @@ DecoderErrorOr Parser::intra_block_mode_info() } m_y_mode = sub_intra_mode; } - m_uv_mode = TRY_READ(m_tree_parser->parse_tree(SyntaxElementType::UVMode)); + m_uv_mode = TRY_READ(TreeParser::parse_uv_mode(*m_bit_stream, *m_probability_tables, *m_syntax_element_counter, m_y_mode)); return {}; } diff --git a/Userland/Libraries/LibVideo/VP9/TreeParser.cpp b/Userland/Libraries/LibVideo/VP9/TreeParser.cpp index ff6e565c66..a85291f7ec 100644 --- a/Userland/Libraries/LibVideo/VP9/TreeParser.cpp +++ b/Userland/Libraries/LibVideo/VP9/TreeParser.cpp @@ -174,14 +174,25 @@ ErrorOr TreeParser::parse_sub_intra_mode(BitStream& bit_stream, return value; } +ErrorOr TreeParser::parse_uv_mode(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, PredictionMode y_mode) +{ + // Tree + TreeParser::TreeSelection tree = { intra_mode_tree }; + + // Probabilities + u8 const* probabilities = probability_table.uv_mode_probs()[to_underlying(y_mode)]; + + auto value = TRY(parse_tree_new(bit_stream, tree, [&](u8 node) { return probabilities[node]; })); + increment_counter(counter.m_counts_uv_mode[to_underlying(y_mode)][to_underlying(value)]); + return value; +} + /* * Select a tree value based on the type of syntax element being parsed, as well as some parser state, as specified in section 9.3.1 */ TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type) { switch (type) { - case SyntaxElementType::UVMode: - return { intra_mode_tree }; case SyntaxElementType::SegmentID: return { segment_tree }; case SyntaxElementType::Skip: @@ -232,8 +243,6 @@ TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type) u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node) { switch (type) { - case SyntaxElementType::UVMode: - return calculate_uv_mode_probability(node); case SyntaxElementType::SegmentID: return calculate_segment_id_probability(node); case SyntaxElementType::Skip: @@ -299,12 +308,6 @@ u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node) #define ABOVE_SINGLE m_decoder.m_above_single #define LEFT_SINGLE m_decoder.m_left_single -u8 TreeParser::calculate_uv_mode_probability(u8 node) -{ - m_ctx = to_underlying(m_decoder.m_y_mode); - return m_decoder.m_probability_tables->uv_mode_probs()[m_ctx][node]; -} - u8 TreeParser::calculate_segment_id_probability(u8 node) { return m_decoder.m_segmentation_tree_probs[node]; @@ -712,9 +715,6 @@ void TreeParser::count_syntax_element(SyntaxElementType type, int value) increment_counter(count); }; switch (type) { - case SyntaxElementType::UVMode: - increment(m_decoder.m_syntax_element_counter->m_counts_uv_mode[m_ctx][value]); - return; case SyntaxElementType::Skip: increment(m_decoder.m_syntax_element_counter->m_counts_skip[m_ctx][value]); return; diff --git a/Userland/Libraries/LibVideo/VP9/TreeParser.h b/Userland/Libraries/LibVideo/VP9/TreeParser.h index 6a581b7fad..a7f6a83cce 100644 --- a/Userland/Libraries/LibVideo/VP9/TreeParser.h +++ b/Userland/Libraries/LibVideo/VP9/TreeParser.h @@ -67,6 +67,7 @@ public: static ErrorOr parse_default_uv_mode(BitStream&, ProbabilityTables const&, PredictionMode y_mode); static ErrorOr parse_intra_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, BlockSubsize mi_size); static ErrorOr parse_sub_intra_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&); + static ErrorOr parse_uv_mode(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, PredictionMode y_mode); void set_default_intra_mode_variables(u8 idx, u8 idy) { @@ -100,7 +101,6 @@ public: } private: - u8 calculate_uv_mode_probability(u8 node); u8 calculate_segment_id_probability(u8 node); u8 calculate_skip_probability(); u8 calculate_seg_id_predicted_probability();