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

LibVideo: Parameterize parsing the default UV prediction mode for VP9

This commit is contained in:
Zaggy1024 2022-11-06 19:37:06 -06:00 committed by Andrew Kaster
parent c6ecad63d0
commit 1b66aa3cad
3 changed files with 15 additions and 9 deletions

View file

@ -1057,7 +1057,7 @@ DecoderErrorOr<void> Parser::intra_frame_mode_info()
}
m_y_mode = m_default_intra_mode;
}
m_uv_mode = TRY_READ(m_tree_parser->parse_tree<PredictionMode>(SyntaxElementType::DefaultUVMode));
m_uv_mode = TRY_READ(TreeParser::parse_default_uv_mode(*m_bit_stream, *m_probability_tables, m_y_mode));
return {};
}

View file

@ -134,6 +134,19 @@ ErrorOr<PredictionMode> TreeParser::parse_default_intra_mode(BitStream& bit_stre
return value;
}
ErrorOr<PredictionMode> TreeParser::parse_default_uv_mode(BitStream& bit_stream, ProbabilityTables const& probability_table, PredictionMode y_mode)
{
// Tree
TreeParser::TreeSelection tree = { intra_mode_tree };
// Probabilities
u8 const* probabilities = probability_table.kf_uv_mode_prob()[to_underlying(y_mode)];
auto value = TRY(parse_tree_new<PredictionMode>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
// Default UV mode is not counted.
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
*/
@ -195,8 +208,6 @@ TreeParser::TreeSelection TreeParser::select_tree(SyntaxElementType type)
u8 TreeParser::select_tree_probability(SyntaxElementType type, u8 node)
{
switch (type) {
case SyntaxElementType::DefaultUVMode:
return calculate_default_uv_mode_probability(node);
case SyntaxElementType::IntraMode:
return calculate_intra_mode_probability(node);
case SyntaxElementType::SubIntraMode:
@ -268,11 +279,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_default_uv_mode_probability(u8 node)
{
return m_decoder.m_probability_tables->kf_uv_mode_prob()[to_underlying(m_decoder.m_y_mode)][node];
}
u8 TreeParser::calculate_intra_mode_probability(u8 node)
{
m_ctx = size_group_lookup[m_decoder.m_mi_size];

View file

@ -64,6 +64,7 @@ public:
static ErrorOr<Partition> parse_partition(BitStream&, ProbabilityTables const&, SyntaxElementCounter&, bool has_rows, bool has_columns, BlockSubsize block_subsize, u8 num_8x8, Vector<u8> const& above_partition_context, Vector<u8> const& left_partition_context, u32 row, u32 column, bool frame_is_intra);
static ErrorOr<PredictionMode> parse_default_intra_mode(BitStream&, ProbabilityTables const&, BlockSubsize mi_size, Optional<Array<PredictionMode, 4> const&> above_context, Optional<Array<PredictionMode, 4> const&> left_context, PredictionMode block_sub_modes[4], u8 index_x, u8 index_y);
static ErrorOr<PredictionMode> parse_default_uv_mode(BitStream&, ProbabilityTables const&, PredictionMode y_mode);
void set_default_intra_mode_variables(u8 idx, u8 idy)
{
@ -97,7 +98,6 @@ public:
}
private:
u8 calculate_default_uv_mode_probability(u8 node);
u8 calculate_intra_mode_probability(u8 node);
u8 calculate_sub_intra_mode_probability(u8 node);
u8 calculate_uv_mode_probability(u8 node);