mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:48:14 +00:00
LibGfx+LibVideo: Make BooleanDecoder usable for both VP8 and VP9
The marker bit is VP9-only, so move that into a new initialize_vp9() function. finish_decode() is VP9-only, so rename that to finish_decode_vp9().
This commit is contained in:
parent
fbc53c1ec3
commit
1dfb065a9c
4 changed files with 19 additions and 9 deletions
|
@ -11,14 +11,19 @@
|
|||
|
||||
namespace Gfx {
|
||||
|
||||
/* 9.2.1 */
|
||||
ErrorOr<BooleanDecoder> BooleanDecoder::initialize(MaybeOwned<BigEndianInputBitStream> bit_stream, size_t size_in_bytes)
|
||||
{
|
||||
VERIFY(bit_stream->is_aligned_to_byte_boundary());
|
||||
auto value = TRY(bit_stream->read_value<u8>());
|
||||
u8 range = 255;
|
||||
u64 bits_left = (8 * size_in_bytes) - 8;
|
||||
BooleanDecoder decoder { move(bit_stream), value, range, bits_left };
|
||||
return BooleanDecoder { move(bit_stream), value, range, bits_left };
|
||||
}
|
||||
|
||||
/* 9.2.1 */
|
||||
ErrorOr<BooleanDecoder> BooleanDecoder::initialize_vp9(MaybeOwned<BigEndianInputBitStream> bit_stream, size_t size_in_bytes)
|
||||
{
|
||||
BooleanDecoder decoder = TRY(initialize(move(bit_stream), size_in_bytes));
|
||||
if (TRY(decoder.read_bool(128)))
|
||||
return Error::from_string_literal("Range decoder marker was non-zero");
|
||||
return decoder;
|
||||
|
@ -63,7 +68,7 @@ ErrorOr<u8> BooleanDecoder::read_literal(u8 bits)
|
|||
}
|
||||
|
||||
/* 9.2.3 */
|
||||
ErrorOr<void> BooleanDecoder::finish_decode()
|
||||
ErrorOr<void> BooleanDecoder::finish_decode_vp9()
|
||||
{
|
||||
while (m_bits_left > 0) {
|
||||
auto padding_read_size = min(m_bits_left, 64);
|
||||
|
|
|
@ -14,13 +14,18 @@
|
|||
|
||||
namespace Gfx {
|
||||
|
||||
// Can decode bitstreams encoded with VP8's and VP9's arithmetic boolean encoder.
|
||||
class BooleanDecoder {
|
||||
public:
|
||||
/* (9.2) */
|
||||
static ErrorOr<BooleanDecoder> initialize(MaybeOwned<BigEndianInputBitStream> bit_stream, size_t size_in_bytes);
|
||||
|
||||
/* (9.2) */
|
||||
static ErrorOr<BooleanDecoder> initialize_vp9(MaybeOwned<BigEndianInputBitStream> bit_stream, size_t size_in_bytes);
|
||||
|
||||
ErrorOr<bool> read_bool(u8 probability);
|
||||
ErrorOr<u8> read_literal(u8 bits);
|
||||
ErrorOr<void> finish_decode();
|
||||
|
||||
ErrorOr<void> finish_decode_vp9();
|
||||
|
||||
private:
|
||||
BooleanDecoder(MaybeOwned<BigEndianInputBitStream>&& bit_stream, u8 value, u8 range, u64 bits_left)
|
||||
|
|
|
@ -229,7 +229,7 @@ public:
|
|||
auto context_view = frame_context.m_block_contexts.view(rows_start, columns_start, height, width);
|
||||
|
||||
auto bit_stream = DECODER_TRY_ALLOC(try_make<BigEndianInputBitStream>(DECODER_TRY_ALLOC(try_make<FixedMemoryStream>(*frame_context.stream))));
|
||||
auto decoder = DECODER_TRY(DecoderErrorCategory::Corrupted, BooleanDecoder::initialize(move(bit_stream), tile_size));
|
||||
auto decoder = DECODER_TRY(DecoderErrorCategory::Corrupted, BooleanDecoder::initialize_vp9(move(bit_stream), tile_size));
|
||||
|
||||
return TileContext {
|
||||
frame_context,
|
||||
|
|
|
@ -593,7 +593,7 @@ void Parser::setup_past_independence()
|
|||
|
||||
DecoderErrorOr<void> Parser::compressed_header(FrameContext& frame_context)
|
||||
{
|
||||
auto decoder = TRY_READ(BooleanDecoder::initialize(MaybeOwned(frame_context.bit_stream), frame_context.header_size_in_bytes));
|
||||
auto decoder = TRY_READ(BooleanDecoder::initialize_vp9(MaybeOwned(frame_context.bit_stream), frame_context.header_size_in_bytes));
|
||||
frame_context.transform_mode = TRY(read_tx_mode(decoder, frame_context));
|
||||
if (frame_context.transform_mode == TransformMode::Select)
|
||||
TRY(tx_mode_probs(decoder));
|
||||
|
@ -610,7 +610,7 @@ DecoderErrorOr<void> Parser::compressed_header(FrameContext& frame_context)
|
|||
TRY(read_partition_probs(decoder));
|
||||
TRY(mv_probs(decoder, frame_context));
|
||||
}
|
||||
TRY_READ(decoder.finish_decode());
|
||||
TRY_READ(decoder.finish_decode_vp9());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -1002,7 +1002,7 @@ DecoderErrorOr<void> Parser::decode_tile(TileContext& tile_context)
|
|||
TRY(decode_partition(tile_context, row, col, Block_64x64));
|
||||
}
|
||||
}
|
||||
TRY_READ(tile_context.decoder.finish_decode());
|
||||
TRY_READ(tile_context.decoder.finish_decode_vp9());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue