mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:57:44 +00:00
LibVideo/VP9: Use u32 to store the parsed value counts
There were rare cases in which u8 was not large enough for the total count of values read, and increasing this to u32 should have no real effect on performance (hopefully).
This commit is contained in:
parent
69e9f9ff63
commit
7b92eff4a6
5 changed files with 74 additions and 79 deletions
|
@ -67,11 +67,6 @@ inline ErrorOr<OutputType> parse_tree(BitStream& bit_stream, TreeSelection tree_
|
|||
return static_cast<OutputType>(-n);
|
||||
}
|
||||
|
||||
inline void increment_counter(u8& counter)
|
||||
{
|
||||
counter = min(static_cast<u32>(counter) + 1, 255);
|
||||
}
|
||||
|
||||
ErrorOr<Partition> TreeParser::parse_partition(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, bool has_rows, bool has_columns, BlockSubsize block_subsize, u8 num_8x8, PartitionContextView above_partition_context, PartitionContextView left_partition_context, u32 row, u32 column, bool frame_is_intra)
|
||||
{
|
||||
// Tree array
|
||||
|
@ -110,7 +105,7 @@ ErrorOr<Partition> TreeParser::parse_partition(BitStream& bit_stream, Probabilit
|
|||
};
|
||||
|
||||
auto value = TRY(parse_tree<Partition>(bit_stream, tree, probability_getter));
|
||||
increment_counter(counter.m_counts_partition[context][value]);
|
||||
counter.m_counts_partition[context][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -167,7 +162,7 @@ ErrorOr<PredictionMode> TreeParser::parse_intra_mode(BitStream& bit_stream, Prob
|
|||
u8 const* probabilities = probability_table.y_mode_probs()[context];
|
||||
|
||||
auto value = TRY(parse_tree<PredictionMode>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
|
||||
increment_counter(counter.m_counts_intra_mode[context][to_underlying(value)]);
|
||||
counter.m_counts_intra_mode[context][to_underlying(value)]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -180,7 +175,7 @@ ErrorOr<PredictionMode> TreeParser::parse_sub_intra_mode(BitStream& bit_stream,
|
|||
u8 const* probabilities = probability_table.y_mode_probs()[0];
|
||||
|
||||
auto value = TRY(parse_tree<PredictionMode>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
|
||||
increment_counter(counter.m_counts_intra_mode[0][to_underlying(value)]);
|
||||
counter.m_counts_intra_mode[0][to_underlying(value)]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -193,7 +188,7 @@ ErrorOr<PredictionMode> TreeParser::parse_uv_mode(BitStream& bit_stream, Probabi
|
|||
u8 const* probabilities = probability_table.uv_mode_probs()[to_underlying(y_mode)];
|
||||
|
||||
auto value = TRY(parse_tree<PredictionMode>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
|
||||
increment_counter(counter.m_counts_uv_mode[to_underlying(y_mode)][to_underlying(value)]);
|
||||
counter.m_counts_uv_mode[to_underlying(y_mode)][to_underlying(value)]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -221,7 +216,7 @@ ErrorOr<PredictionMode> TreeParser::parse_inter_mode(BitStream& bit_stream, Prob
|
|||
u8 const* probabilities = probability_table.inter_mode_probs()[mode_context_for_ref_frame_0];
|
||||
|
||||
auto value = TRY(parse_tree<PredictionMode>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
|
||||
increment_counter(counter.m_counts_inter_mode[mode_context_for_ref_frame_0][to_underlying(value) - to_underlying(PredictionMode::NearestMv)]);
|
||||
counter.m_counts_inter_mode[mode_context_for_ref_frame_0][to_underlying(value) - to_underlying(PredictionMode::NearestMv)]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -246,7 +241,7 @@ ErrorOr<InterpolationFilter> TreeParser::parse_interpolation_filter(BitStream& b
|
|||
u8 const* probabilities = probability_table.interp_filter_probs()[context];
|
||||
|
||||
auto value = TRY(parse_tree<InterpolationFilter>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
|
||||
increment_counter(counter.m_counts_interp_filter[context][to_underlying(value)]);
|
||||
counter.m_counts_interp_filter[context][to_underlying(value)]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -259,7 +254,7 @@ ErrorOr<bool> TreeParser::parse_skip(BitStream& bit_stream, ProbabilityTables co
|
|||
u8 probability = probability_table.skip_prob()[context];
|
||||
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
|
||||
increment_counter(counter.m_counts_skip[context][value]);
|
||||
counter.m_counts_skip[context][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -290,7 +285,7 @@ ErrorOr<TransformSize> TreeParser::parse_tx_size(BitStream& bit_stream, Probabil
|
|||
u8 const* probabilities = probability_table.tx_probs()[max_tx_size][context];
|
||||
|
||||
auto value = TRY(parse_tree<TransformSize>(bit_stream, tree, [&](u8 node) { return probabilities[node]; }));
|
||||
increment_counter(counter.m_counts_tx_size[max_tx_size][context][value]);
|
||||
counter.m_counts_tx_size[max_tx_size][context][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -307,7 +302,7 @@ ErrorOr<bool> TreeParser::parse_block_is_inter_predicted(BitStream& bit_stream,
|
|||
u8 probability = probability_table.is_inter_prob()[context];
|
||||
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
|
||||
increment_counter(counter.m_counts_is_inter[context][value]);
|
||||
counter.m_counts_is_inter[context][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -347,7 +342,7 @@ ErrorOr<ReferenceMode> TreeParser::parse_comp_mode(BitStream& bit_stream, Probab
|
|||
u8 probability = probability_table.comp_mode_prob()[context];
|
||||
|
||||
auto value = TRY(parse_tree<ReferenceMode>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
|
||||
increment_counter(counter.m_counts_comp_mode[context][value]);
|
||||
counter.m_counts_comp_mode[context][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -430,7 +425,7 @@ ErrorOr<ReferenceIndex> TreeParser::parse_comp_ref(BitStream& bit_stream, Probab
|
|||
u8 probability = probability_table.comp_ref_prob()[context];
|
||||
|
||||
auto value = TRY(parse_tree<ReferenceIndex>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
|
||||
increment_counter(counter.m_counts_comp_ref[context][to_underlying(value)]);
|
||||
counter.m_counts_comp_ref[context][to_underlying(value)]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -497,7 +492,7 @@ ErrorOr<bool> TreeParser::parse_single_ref_part_1(BitStream& bit_stream, Probabi
|
|||
u8 probability = probability_table.single_ref_prob()[context][0];
|
||||
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
|
||||
increment_counter(counter.m_counts_single_ref[context][0][value]);
|
||||
counter.m_counts_single_ref[context][0][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -583,21 +578,21 @@ ErrorOr<bool> TreeParser::parse_single_ref_part_2(BitStream& bit_stream, Probabi
|
|||
u8 probability = probability_table.single_ref_prob()[context][1];
|
||||
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
|
||||
increment_counter(counter.m_counts_single_ref[context][1][value]);
|
||||
counter.m_counts_single_ref[context][1][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
ErrorOr<MvJoint> TreeParser::parse_motion_vector_joint(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter)
|
||||
{
|
||||
auto value = TRY(parse_tree<MvJoint>(bit_stream, { mv_joint_tree }, [&](u8 node) { return probability_table.mv_joint_probs()[node]; }));
|
||||
increment_counter(counter.m_counts_mv_joint[value]);
|
||||
counter.m_counts_mv_joint[value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
ErrorOr<bool> TreeParser::parse_motion_vector_sign(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, u8 component)
|
||||
{
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, { binary_tree }, [&](u8) { return probability_table.mv_sign_prob()[component]; }));
|
||||
increment_counter(counter.m_counts_mv_sign[component][value]);
|
||||
counter.m_counts_mv_sign[component][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -606,21 +601,21 @@ ErrorOr<MvClass> TreeParser::parse_motion_vector_class(BitStream& bit_stream, Pr
|
|||
// Spec doesn't mention node, but the probabilities table has an extra dimension
|
||||
// so we will use node for that.
|
||||
auto value = TRY(parse_tree<MvClass>(bit_stream, { mv_class_tree }, [&](u8 node) { return probability_table.mv_class_probs()[component][node]; }));
|
||||
increment_counter(counter.m_counts_mv_class[component][value]);
|
||||
counter.m_counts_mv_class[component][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
ErrorOr<bool> TreeParser::parse_motion_vector_class0_bit(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, u8 component)
|
||||
{
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, { binary_tree }, [&](u8) { return probability_table.mv_class0_bit_prob()[component]; }));
|
||||
increment_counter(counter.m_counts_mv_class0_bit[component][value]);
|
||||
counter.m_counts_mv_class0_bit[component][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
ErrorOr<u8> TreeParser::parse_motion_vector_class0_fr(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, u8 component, bool class_0_bit)
|
||||
{
|
||||
auto value = TRY(parse_tree<u8>(bit_stream, { mv_fr_tree }, [&](u8 node) { return probability_table.mv_class0_fr_probs()[component][class_0_bit][node]; }));
|
||||
increment_counter(counter.m_counts_mv_class0_fr[component][class_0_bit][value]);
|
||||
counter.m_counts_mv_class0_fr[component][class_0_bit][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -630,21 +625,21 @@ ErrorOr<bool> TreeParser::parse_motion_vector_class0_hp(BitStream& bit_stream, P
|
|||
if (use_hp)
|
||||
tree = { binary_tree };
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, tree, [&](u8) { return probability_table.mv_class0_hp_prob()[component]; }));
|
||||
increment_counter(counter.m_counts_mv_class0_hp[component][value]);
|
||||
counter.m_counts_mv_class0_hp[component][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
ErrorOr<bool> TreeParser::parse_motion_vector_bit(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, u8 component, u8 bit_index)
|
||||
{
|
||||
auto value = TRY(parse_tree<bool>(bit_stream, { binary_tree }, [&](u8) { return probability_table.mv_bits_prob()[component][bit_index]; }));
|
||||
increment_counter(counter.m_counts_mv_bits[component][bit_index][value]);
|
||||
counter.m_counts_mv_bits[component][bit_index][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
ErrorOr<u8> TreeParser::parse_motion_vector_fr(BitStream& bit_stream, ProbabilityTables const& probability_table, SyntaxElementCounter& counter, u8 component)
|
||||
{
|
||||
auto value = TRY(parse_tree<u8>(bit_stream, { mv_fr_tree }, [&](u8 node) { return probability_table.mv_fr_probs()[component][node]; }));
|
||||
increment_counter(counter.m_counts_mv_fr[component][value]);
|
||||
counter.m_counts_mv_fr[component][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -654,7 +649,7 @@ ErrorOr<bool> TreeParser::parse_motion_vector_hp(BitStream& bit_stream, Probabil
|
|||
if (use_hp)
|
||||
tree = { binary_tree };
|
||||
auto value = TRY(parse_tree<u8>(bit_stream, tree, [&](u8) { return probability_table.mv_hp_prob()[component]; }));
|
||||
increment_counter(counter.m_counts_mv_hp[component][value]);
|
||||
counter.m_counts_mv_hp[component][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -717,7 +712,7 @@ ErrorOr<bool> TreeParser::parse_more_coefficients(BitStream& bit_stream, Probabi
|
|||
{
|
||||
auto probability = probability_table.coef_probs()[context.m_tx_size][context.m_is_uv_plane][context.m_is_inter][context.m_band][context.m_context_index][0];
|
||||
auto value = TRY(parse_tree<u8>(bit_stream, { binary_tree }, [&](u8) { return probability; }));
|
||||
increment_counter(counter.m_counts_more_coefs[context.m_tx_size][context.m_is_uv_plane][context.m_is_inter][context.m_band][context.m_context_index][value]);
|
||||
counter.m_counts_more_coefs[context.m_tx_size][context.m_is_uv_plane][context.m_is_inter][context.m_band][context.m_context_index][value]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -735,7 +730,7 @@ ErrorOr<Token> TreeParser::parse_token(BitStream& bit_stream, ProbabilityTables
|
|||
};
|
||||
|
||||
auto value = TRY(parse_tree<Token>(bit_stream, { token_tree }, probability_getter));
|
||||
increment_counter(counter.m_counts_token[context.m_tx_size][context.m_is_uv_plane][context.m_is_inter][context.m_band][context.m_context_index][min(2, value)]);
|
||||
counter.m_counts_token[context.m_tx_size][context.m_is_uv_plane][context.m_is_inter][context.m_band][context.m_context_index][min(2, value)]++;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue