mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:17:35 +00:00
LibVideo: Read multiple raw bits at once to refill the range decoder
This will allow BitStream::read_bool() to read more than one bit from the range-coded bitstream at a time if needed.
This commit is contained in:
parent
13ccde8637
commit
647472b716
1 changed files with 11 additions and 10 deletions
|
@ -5,6 +5,8 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/BuiltinWrappers.h>
|
||||||
|
|
||||||
#include "BitStream.h"
|
#include "BitStream.h"
|
||||||
|
|
||||||
namespace Video::VP9 {
|
namespace Video::VP9 {
|
||||||
|
@ -96,16 +98,15 @@ ErrorOr<bool> BitStream::read_bool(u8 probability)
|
||||||
return_bool = true;
|
return_bool = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (m_bool_range < 128) {
|
if (m_bool_range < 128) {
|
||||||
bool new_bit;
|
u8 bits_to_shift_into_range = count_leading_zeroes(m_bool_range);
|
||||||
if (m_bool_max_bits) {
|
|
||||||
new_bit = TRY(read_bit());
|
if (bits_to_shift_into_range > m_bool_max_bits)
|
||||||
m_bool_max_bits--;
|
return Error::from_string_literal("Range decoder is out of data");
|
||||||
} else {
|
|
||||||
new_bit = false;
|
m_bool_range <<= bits_to_shift_into_range;
|
||||||
}
|
m_bool_value = (m_bool_value << bits_to_shift_into_range) | TRY(read_bits(bits_to_shift_into_range));
|
||||||
m_bool_range *= 2;
|
m_bool_max_bits -= bits_to_shift_into_range;
|
||||||
m_bool_value = (m_bool_value << 1u) + new_bit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return return_bool;
|
return return_bool;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue