diff --git a/Userland/Libraries/LibVideo/VP9/Decoder.cpp b/Userland/Libraries/LibVideo/VP9/Decoder.cpp index 4aec4df7b8..09fb9058d3 100644 --- a/Userland/Libraries/LibVideo/VP9/Decoder.cpp +++ b/Userland/Libraries/LibVideo/VP9/Decoder.cpp @@ -216,16 +216,19 @@ DecoderErrorOr> Decoder::get_decoded_frame() return m_video_frame_queue.dequeue(); } -u8 Decoder::merge_prob(u8 pre_prob, u8 count_0, u8 count_1, u8 count_sat, u8 max_update_factor) +u8 Decoder::merge_prob(u8 pre_prob, u32 count_0, u32 count_1, u8 count_sat, u8 max_update_factor) { auto total_decode_count = count_0 + count_1; - auto prob = (total_decode_count == 0) ? 128 : clip_3(1, 255, (count_0 * 256 + (total_decode_count >> 1)) / total_decode_count); + u8 prob = 128; + if (total_decode_count != 0) { + prob = static_cast(clip_3(1u, 255u, (count_0 * 256 + (total_decode_count >> 1)) / total_decode_count)); + } auto count = min(total_decode_count, count_sat); auto factor = (max_update_factor * count) / count_sat; return round_2(pre_prob * (256 - factor) + (prob * factor), 8); } -u8 Decoder::merge_probs(int const* tree, int index, u8* probs, u8* counts, u8 count_sat, u8 max_update_factor) +u32 Decoder::merge_probs(int const* tree, int index, u8* probs, u8* counts, u8 count_sat, u8 max_update_factor) { auto s = tree[index]; auto left_count = (s <= 0) ? counts[-s] : merge_probs(tree, s, probs, counts, count_sat, max_update_factor); diff --git a/Userland/Libraries/LibVideo/VP9/Decoder.h b/Userland/Libraries/LibVideo/VP9/Decoder.h index aeda7de660..0e65746c99 100644 --- a/Userland/Libraries/LibVideo/VP9/Decoder.h +++ b/Userland/Libraries/LibVideo/VP9/Decoder.h @@ -48,8 +48,8 @@ private: Vector& get_output_buffer(u8 plane); /* (8.4) Probability Adaptation Process */ - u8 merge_prob(u8 pre_prob, u8 count_0, u8 count_1, u8 count_sat, u8 max_update_factor); - u8 merge_probs(int const* tree, int index, u8* probs, u8* counts, u8 count_sat, u8 max_update_factor); + u8 merge_prob(u8 pre_prob, u32 count_0, u32 count_1, u8 count_sat, u8 max_update_factor); + u32 merge_probs(int const* tree, int index, u8* probs, u8* counts, u8 count_sat, u8 max_update_factor); DecoderErrorOr adapt_coef_probs(bool is_inter_predicted_frame); DecoderErrorOr adapt_non_coef_probs(FrameContext const&); void adapt_probs(int const* tree, u8* probs, u8* counts);