From fbc53c1ec3bc2f192901fb6c784a7f13ec2b586c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 26 May 2023 15:04:31 -0400 Subject: [PATCH] LibGfx+LibVideo: Move VP9/BooleanDecoder to LibGfx/ImageFormats ...and keep a forwarding header around in VP9, so we don't have to update all references to the class there. In time, we probably want to merge LibGfx/ImageDecoders and LibVideo into LibMedia, but for now I need just this class for the lossy webp decoder. So move just it over. No behvior change. --- Userland/Libraries/LibGfx/CMakeLists.txt | 1 + .../ImageFormats}/BooleanDecoder.cpp | 2 +- .../LibGfx/ImageFormats/BooleanDecoder.h | 40 +++++++++++++++++++ Userland/Libraries/LibVideo/CMakeLists.txt | 1 - .../Libraries/LibVideo/VP9/BooleanDecoder.h | 31 ++------------ 5 files changed, 45 insertions(+), 30 deletions(-) rename Userland/Libraries/{LibVideo/VP9 => LibGfx/ImageFormats}/BooleanDecoder.cpp (99%) create mode 100644 Userland/Libraries/LibGfx/ImageFormats/BooleanDecoder.h diff --git a/Userland/Libraries/LibGfx/CMakeLists.txt b/Userland/Libraries/LibGfx/CMakeLists.txt index 4e88d5f65f..ab64783da7 100644 --- a/Userland/Libraries/LibGfx/CMakeLists.txt +++ b/Userland/Libraries/LibGfx/CMakeLists.txt @@ -33,6 +33,7 @@ set(SOURCES ICC/WellKnownProfiles.cpp ImageFormats/BMPLoader.cpp ImageFormats/BMPWriter.cpp + ImageFormats/BooleanDecoder.cpp ImageFormats/DDSLoader.cpp ImageFormats/GIFLoader.cpp ImageFormats/ICOLoader.cpp diff --git a/Userland/Libraries/LibVideo/VP9/BooleanDecoder.cpp b/Userland/Libraries/LibGfx/ImageFormats/BooleanDecoder.cpp similarity index 99% rename from Userland/Libraries/LibVideo/VP9/BooleanDecoder.cpp rename to Userland/Libraries/LibGfx/ImageFormats/BooleanDecoder.cpp index facc4c6091..69b3a91d76 100644 --- a/Userland/Libraries/LibVideo/VP9/BooleanDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/BooleanDecoder.cpp @@ -9,7 +9,7 @@ #include "BooleanDecoder.h" -namespace Video::VP9 { +namespace Gfx { /* 9.2.1 */ ErrorOr BooleanDecoder::initialize(MaybeOwned bit_stream, size_t size_in_bytes) diff --git a/Userland/Libraries/LibGfx/ImageFormats/BooleanDecoder.h b/Userland/Libraries/LibGfx/ImageFormats/BooleanDecoder.h new file mode 100644 index 0000000000..d17a4ee2c7 --- /dev/null +++ b/Userland/Libraries/LibGfx/ImageFormats/BooleanDecoder.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021, Hunter Salyer + * Copyright (c) 2022, Gregory Bertilson + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Gfx { + +class BooleanDecoder { +public: + /* (9.2) */ + static ErrorOr initialize(MaybeOwned bit_stream, size_t size_in_bytes); + ErrorOr read_bool(u8 probability); + ErrorOr read_literal(u8 bits); + ErrorOr finish_decode(); + +private: + BooleanDecoder(MaybeOwned&& bit_stream, u8 value, u8 range, u64 bits_left) + : m_bit_stream(move(bit_stream)) + , m_value(value) + , m_range(range) + , m_bits_left(bits_left) + { + } + + MaybeOwned m_bit_stream; + u8 m_value { 0 }; + u8 m_range { 0 }; + u64 m_bits_left { 0 }; +}; + +} diff --git a/Userland/Libraries/LibVideo/CMakeLists.txt b/Userland/Libraries/LibVideo/CMakeLists.txt index 3d1dcb9854..2d52891ac8 100644 --- a/Userland/Libraries/LibVideo/CMakeLists.txt +++ b/Userland/Libraries/LibVideo/CMakeLists.txt @@ -6,7 +6,6 @@ set(SOURCES Containers/Matroska/Reader.cpp PlaybackManager.cpp VideoFrame.cpp - VP9/BooleanDecoder.cpp VP9/Decoder.cpp VP9/Parser.cpp VP9/ProbabilityTables.cpp diff --git a/Userland/Libraries/LibVideo/VP9/BooleanDecoder.h b/Userland/Libraries/LibVideo/VP9/BooleanDecoder.h index 5a72f76d70..2c53fc8701 100644 --- a/Userland/Libraries/LibVideo/VP9/BooleanDecoder.h +++ b/Userland/Libraries/LibVideo/VP9/BooleanDecoder.h @@ -1,40 +1,15 @@ /* - * Copyright (c) 2021, Hunter Salyer - * Copyright (c) 2022, Gregory Bertilson + * Copyright (c) 2023, Nico Weber * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include -#include -#include -#include +#include namespace Video::VP9 { -class BooleanDecoder { -public: - /* (9.2) */ - static ErrorOr initialize(MaybeOwned bit_stream, size_t size_in_bytes); - ErrorOr read_bool(u8 probability); - ErrorOr read_literal(u8 bits); - ErrorOr finish_decode(); - -private: - BooleanDecoder(MaybeOwned&& bit_stream, u8 value, u8 range, u64 bits_left) - : m_bit_stream(move(bit_stream)) - , m_value(value) - , m_range(range) - , m_bits_left(bits_left) - { - } - - MaybeOwned m_bit_stream; - u8 m_value { 0 }; - u8 m_range { 0 }; - u64 m_bits_left { 0 }; -}; +using BooleanDecoder = Gfx::BooleanDecoder; }