From 2470dd3bb5f437658ec2f95ff3e7f0bb2e0b5448 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 25 Jan 2023 20:06:16 +0100 Subject: [PATCH] AK: Move bit streams from `LibCore` --- .../Libraries/LibCore => AK}/BitStream.h | 19 +-- AK/Forward.h | 8 ++ Tests/AK/CMakeLists.txt | 1 + Tests/AK/TestBitStream.cpp | 121 ++++++++++++++++++ Tests/LibCompress/TestDeflate.cpp | 6 +- Tests/LibCore/TestLibCoreStream.cpp | 115 ----------------- Userland/Libraries/LibAudio/FlacLoader.h | 4 +- .../Libraries/LibAudio/MP3HuffmanTables.h | 3 +- Userland/Libraries/LibAudio/MP3Loader.cpp | 8 +- Userland/Libraries/LibAudio/MP3Loader.h | 8 +- Userland/Libraries/LibCompress/Brotli.h | 4 +- Userland/Libraries/LibCompress/Deflate.cpp | 11 +- Userland/Libraries/LibCompress/Deflate.h | 13 +- Userland/Libraries/LibPDF/DocumentParser.cpp | 4 +- 14 files changed, 167 insertions(+), 158 deletions(-) rename {Userland/Libraries/LibCore => AK}/BitStream.h (96%) create mode 100644 Tests/AK/TestBitStream.cpp diff --git a/Userland/Libraries/LibCore/BitStream.h b/AK/BitStream.h similarity index 96% rename from Userland/Libraries/LibCore/BitStream.h rename to AK/BitStream.h index 4610df32e7..922e86da17 100644 --- a/Userland/Libraries/LibCore/BitStream.h +++ b/AK/BitStream.h @@ -7,22 +7,15 @@ #pragma once #include -#include -#include #include -#include -#include #include -#include -#include -#include -#include +#include -namespace Core::Stream { +namespace AK { /// A stream wrapper class that allows you to read arbitrary amounts of bits /// in big-endian order from another stream. -class BigEndianInputBitStream : public AK::Stream { +class BigEndianInputBitStream : public Stream { public: static ErrorOr> construct(MaybeOwned stream) { @@ -131,7 +124,7 @@ private: /// A stream wrapper class that allows you to read arbitrary amounts of bits /// in little-endian order from another stream. -class LittleEndianInputBitStream : public AK::Stream { +class LittleEndianInputBitStream : public Stream { public: static ErrorOr> construct(MaybeOwned stream) { @@ -240,7 +233,7 @@ private: /// A stream wrapper class that allows you to write arbitrary amounts of bits /// in big-endian order to another stream. -class BigEndianOutputBitStream : public AK::Stream { +class BigEndianOutputBitStream : public Stream { public: static ErrorOr> construct(MaybeOwned stream) { @@ -323,7 +316,7 @@ private: /// A stream wrapper class that allows you to write arbitrary amounts of bits /// in little-endian order to another stream. -class LittleEndianOutputBitStream : public AK::Stream { +class LittleEndianOutputBitStream : public Stream { public: static ErrorOr> construct(MaybeOwned stream) { diff --git a/AK/Forward.h b/AK/Forward.h index d94e7a6fd6..e258449ffd 100644 --- a/AK/Forward.h +++ b/AK/Forward.h @@ -18,6 +18,8 @@ class ByteBuffer; } class Bitmap; +class BigEndianInputBitStream; +class BigEndianOutputBitStream; using ByteBuffer = Detail::ByteBuffer<32>; class CircularBuffer; class DeprecatedInputStream; @@ -31,6 +33,8 @@ class IPv4Address; class JsonArray; class JsonObject; class JsonValue; +class LittleEndianInputBitStream; +class LittleEndianOutputBitStream; class StackInfo; class DeprecatedFlyString; class DeprecatedString; @@ -152,6 +156,8 @@ class [[nodiscard]] ErrorOr; using AK::Array; using AK::Atomic; using AK::Badge; +using AK::BigEndianInputBitStream; +using AK::BigEndianOutputBitStream; using AK::Bitmap; using AK::ByteBuffer; using AK::Bytes; @@ -177,6 +183,8 @@ using AK::IPv4Address; using AK::JsonArray; using AK::JsonObject; using AK::JsonValue; +using AK::LittleEndianInputBitStream; +using AK::LittleEndianOutputBitStream; using AK::NonnullOwnPtr; using AK::NonnullOwnPtrVector; using AK::NonnullRefPtr; diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index 588997d53b..fae14c43d6 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -10,6 +10,7 @@ set(AK_TEST_SOURCES TestBinarySearch.cpp TestBitCast.cpp TestBitmap.cpp + TestBitStream.cpp TestBuiltinWrappers.cpp TestByteBuffer.cpp TestCharacterTypes.cpp diff --git a/Tests/AK/TestBitStream.cpp b/Tests/AK/TestBitStream.cpp new file mode 100644 index 0000000000..0316ae863e --- /dev/null +++ b/Tests/AK/TestBitStream.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2023, Tim Schumacher + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. +TEST_CASE(little_endian_bit_stream_input_output_match) +{ + auto memory_stream = make(); + + // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, + // so testing with sizes that will not trigger a write will yield unexpected results. + auto bit_write_stream = MUST(LittleEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); + auto bit_read_stream = MUST(LittleEndianInputBitStream::construct(MaybeOwned(*memory_stream))); + + // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits. + { + MUST(bit_write_stream->write_bits(0b1111u, 4)); + MUST(bit_write_stream->write_bits(0b1111u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1111u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1111u, result); + } + { + MUST(bit_write_stream->write_bits(0b0000u, 4)); + MUST(bit_write_stream->write_bits(0b0000u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b0000u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b0000u, result); + } + + // Test two mirrored chunks of a non-mirrored pattern to check that we are writing bits within a pattern in the correct order. + { + MUST(bit_write_stream->write_bits(0b1000u, 4)); + MUST(bit_write_stream->write_bits(0b1000u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1000u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1000u, result); + } + + // Test two different chunks to check that we are not confusing their order. + { + MUST(bit_write_stream->write_bits(0b1000u, 4)); + MUST(bit_write_stream->write_bits(0b0100u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1000u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b0100u, result); + } + + // Test a pattern that spans multiple bytes. + { + MUST(bit_write_stream->write_bits(0b1101001000100001u, 16)); + auto result = MUST(bit_read_stream->read_bits(16)); + EXPECT_EQ(0b1101001000100001u, result); + } +} + +// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. +TEST_CASE(big_endian_bit_stream_input_output_match) +{ + auto memory_stream = make(); + + // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, + // so testing with sizes that will not trigger a write will yield unexpected results. + auto bit_write_stream = MUST(BigEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); + auto bit_read_stream = MUST(BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); + + // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits. + { + MUST(bit_write_stream->write_bits(0b1111u, 4)); + MUST(bit_write_stream->write_bits(0b1111u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1111u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1111u, result); + } + { + MUST(bit_write_stream->write_bits(0b0000u, 4)); + MUST(bit_write_stream->write_bits(0b0000u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b0000u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b0000u, result); + } + + // Test two mirrored chunks of a non-mirrored pattern to check that we are writing bits within a pattern in the correct order. + { + MUST(bit_write_stream->write_bits(0b1000u, 4)); + MUST(bit_write_stream->write_bits(0b1000u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1000u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1000u, result); + } + + // Test two different chunks to check that we are not confusing their order. + { + MUST(bit_write_stream->write_bits(0b1000u, 4)); + MUST(bit_write_stream->write_bits(0b0100u, 4)); + auto result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b1000u, result); + result = MUST(bit_read_stream->read_bits(4)); + EXPECT_EQ(0b0100u, result); + } + + // Test a pattern that spans multiple bytes. + { + MUST(bit_write_stream->write_bits(0b1101001000100001u, 16)); + auto result = MUST(bit_read_stream->read_bits(16)); + EXPECT_EQ(0b1101001000100001u, result); + } +} diff --git a/Tests/LibCompress/TestDeflate.cpp b/Tests/LibCompress/TestDeflate.cpp index 56fd34b733..bdeeabd9b0 100644 --- a/Tests/LibCompress/TestDeflate.cpp +++ b/Tests/LibCompress/TestDeflate.cpp @@ -7,9 +7,9 @@ #include #include +#include #include #include -#include #include #include @@ -29,7 +29,7 @@ TEST_CASE(canonical_code_simple) auto const huffman = Compress::CanonicalCode::from_bytes(code).value(); auto memory_stream = MUST(Core::Stream::FixedMemoryStream::construct(input)); - auto bit_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(move(memory_stream))); + auto bit_stream = MUST(LittleEndianInputBitStream::construct(move(memory_stream))); for (size_t idx = 0; idx < 9; ++idx) EXPECT_EQ(MUST(huffman.read_symbol(*bit_stream)), output[idx]); @@ -49,7 +49,7 @@ TEST_CASE(canonical_code_complex) auto const huffman = Compress::CanonicalCode::from_bytes(code).value(); auto memory_stream = MUST(Core::Stream::FixedMemoryStream::construct(input)); - auto bit_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(move(memory_stream))); + auto bit_stream = MUST(LittleEndianInputBitStream::construct(move(memory_stream))); for (size_t idx = 0; idx < 12; ++idx) EXPECT_EQ(MUST(huffman.read_symbol(*bit_stream)), output[idx]); diff --git a/Tests/LibCore/TestLibCoreStream.cpp b/Tests/LibCore/TestLibCoreStream.cpp index 0549a35518..c7c87aff85 100644 --- a/Tests/LibCore/TestLibCoreStream.cpp +++ b/Tests/LibCore/TestLibCoreStream.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -717,117 +716,3 @@ TEST_CASE(allocating_memory_stream_10kb) offset += file_span.size(); } } - -// Bit stream tests - -// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. -TEST_CASE(little_endian_bit_stream_input_output_match) -{ - auto memory_stream = make(); - - // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, - // so testing with sizes that will not trigger a write will yield unexpected results. - auto bit_write_stream = MUST(Core::Stream::LittleEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); - auto bit_read_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(MaybeOwned(*memory_stream))); - - // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits. - { - MUST(bit_write_stream->write_bits(0b1111u, 4)); - MUST(bit_write_stream->write_bits(0b1111u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - } - { - MUST(bit_write_stream->write_bits(0b0000u, 4)); - MUST(bit_write_stream->write_bits(0b0000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - } - - // Test two mirrored chunks of a non-mirrored pattern to check that we are writing bits within a pattern in the correct order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b1000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - } - - // Test two different chunks to check that we are not confusing their order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b0100u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0100u, result); - } - - // Test a pattern that spans multiple bytes. - { - MUST(bit_write_stream->write_bits(0b1101001000100001u, 16)); - auto result = MUST(bit_read_stream->read_bits(16)); - EXPECT_EQ(0b1101001000100001u, result); - } -} - -// Note: This does not do any checks on the internal representation, it just ensures that the behavior of the input and output streams match. -TEST_CASE(big_endian_bit_stream_input_output_match) -{ - auto memory_stream = make(); - - // Note: The bit stream only ever reads from/writes to the underlying stream in one byte chunks, - // so testing with sizes that will not trigger a write will yield unexpected results. - auto bit_write_stream = MUST(Core::Stream::BigEndianOutputBitStream::construct(MaybeOwned(*memory_stream))); - auto bit_read_stream = MUST(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(*memory_stream))); - - // Test two mirrored chunks of a fully mirrored pattern to check that we are not dropping bits. - { - MUST(bit_write_stream->write_bits(0b1111u, 4)); - MUST(bit_write_stream->write_bits(0b1111u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1111u, result); - } - { - MUST(bit_write_stream->write_bits(0b0000u, 4)); - MUST(bit_write_stream->write_bits(0b0000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0000u, result); - } - - // Test two mirrored chunks of a non-mirrored pattern to check that we are writing bits within a pattern in the correct order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b1000u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - } - - // Test two different chunks to check that we are not confusing their order. - { - MUST(bit_write_stream->write_bits(0b1000u, 4)); - MUST(bit_write_stream->write_bits(0b0100u, 4)); - auto result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b1000u, result); - result = MUST(bit_read_stream->read_bits(4)); - EXPECT_EQ(0b0100u, result); - } - - // Test a pattern that spans multiple bytes. - { - MUST(bit_write_stream->write_bits(0b1101001000100001u, 16)); - auto result = MUST(bit_read_stream->read_bits(16)); - EXPECT_EQ(0b1101001000100001u, result); - } -} diff --git a/Userland/Libraries/LibAudio/FlacLoader.h b/Userland/Libraries/LibAudio/FlacLoader.h index cfc9170134..cc7a9703bb 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.h +++ b/Userland/Libraries/LibAudio/FlacLoader.h @@ -8,17 +8,15 @@ #include "FlacTypes.h" #include "Loader.h" +#include #include #include #include -#include #include #include namespace Audio { -using Core::Stream::BigEndianInputBitStream; - // Experimentally determined to be a decent buffer size on i686: // 4K (the default) is slightly worse, and 64K is much worse. // At sufficiently large buffer sizes, the advantage of infrequent read() calls is outweighed by the memmove() overhead. diff --git a/Userland/Libraries/LibAudio/MP3HuffmanTables.h b/Userland/Libraries/LibAudio/MP3HuffmanTables.h index ff1a0fc21f..3c54000506 100644 --- a/Userland/Libraries/LibAudio/MP3HuffmanTables.h +++ b/Userland/Libraries/LibAudio/MP3HuffmanTables.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include namespace Audio::MP3::Tables::Huffman { @@ -105,7 +106,7 @@ struct HuffmanDecodeResult { }; template -HuffmanDecodeResult huffman_decode(Core::Stream::BigEndianInputBitStream& bitstream, Span const> tree, size_t max_bits_to_read) +HuffmanDecodeResult huffman_decode(BigEndianInputBitStream& bitstream, Span const> tree, size_t max_bits_to_read) { HuffmanNode const* node = &tree[0]; size_t bits_read = 0; diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp index 59eb0dff0d..62e534d6de 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.cpp +++ b/Userland/Libraries/LibAudio/MP3Loader.cpp @@ -41,7 +41,7 @@ Result, LoaderError> MP3LoaderPlugin::create(Byte MaybeLoaderError MP3LoaderPlugin::initialize() { - m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); + m_bitstream = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned(*m_stream))); TRY(synchronize()); @@ -242,7 +242,7 @@ ErrorOr MP3LoaderPlugin::read_frame_data(MP3::Header TRY(m_bit_reservoir.discard(old_reservoir_size - frame.main_data_begin)); - auto reservoir_stream = TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned(m_bit_reservoir))); + auto reservoir_stream = TRY(BigEndianInputBitStream::construct(MaybeOwned(m_bit_reservoir))); for (size_t granule_index = 0; granule_index < 2; granule_index++) { for (size_t channel_index = 0; channel_index < header.channel_count(); channel_index++) { @@ -418,7 +418,7 @@ Array MP3LoaderPlugin::calculate_frame_exponents(MP3::MP3Frame const return exponents; } -ErrorOr MP3LoaderPlugin::read_scale_factors(MP3::MP3Frame& frame, Core::Stream::BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index) +ErrorOr MP3LoaderPlugin::read_scale_factors(MP3::MP3Frame& frame, BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index) { auto& channel = frame.channels[channel_index]; auto const& granule = channel.granules[granule_index]; @@ -486,7 +486,7 @@ ErrorOr MP3LoaderPlugin::read_scale_factors(MP3::MP3Frame& return bits_read; } -MaybeLoaderError MP3LoaderPlugin::read_huffman_data(MP3::MP3Frame& frame, Core::Stream::BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index, size_t granule_bits_read) +MaybeLoaderError MP3LoaderPlugin::read_huffman_data(MP3::MP3Frame& frame, BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index, size_t granule_bits_read) { auto const exponents = calculate_frame_exponents(frame, granule_index, channel_index); auto& granule = frame.channels[channel_index].granules[granule_index]; diff --git a/Userland/Libraries/LibAudio/MP3Loader.h b/Userland/Libraries/LibAudio/MP3Loader.h index 48d5ab1440..1af97b0ce2 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.h +++ b/Userland/Libraries/LibAudio/MP3Loader.h @@ -8,8 +8,8 @@ #include "Loader.h" #include "MP3Types.h" +#include #include -#include #include #include #include @@ -48,8 +48,8 @@ private: ErrorOr read_next_frame(); ErrorOr read_frame_data(MP3::Header const&); MaybeLoaderError read_side_information(MP3::MP3Frame&); - ErrorOr read_scale_factors(MP3::MP3Frame&, Core::Stream::BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index); - MaybeLoaderError read_huffman_data(MP3::MP3Frame&, Core::Stream::BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index, size_t granule_bits_read); + ErrorOr read_scale_factors(MP3::MP3Frame&, BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index); + MaybeLoaderError read_huffman_data(MP3::MP3Frame&, BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index, size_t granule_bits_read); static AK::Array calculate_frame_exponents(MP3::MP3Frame const&, size_t granule_index, size_t channel_index); static void reorder_samples(MP3::Granule&, u32 sample_rate); static void reduce_alias(MP3::Granule&, size_t max_subband_index = 576); @@ -72,7 +72,7 @@ private: AK::Optional m_current_frame; u32 m_current_frame_read; - OwnPtr m_bitstream; + OwnPtr m_bitstream; Core::Stream::AllocatingMemoryStream m_bit_reservoir; }; diff --git a/Userland/Libraries/LibCompress/Brotli.h b/Userland/Libraries/LibCompress/Brotli.h index ee8fa7fa11..2df3c9c68b 100644 --- a/Userland/Libraries/LibCompress/Brotli.h +++ b/Userland/Libraries/LibCompress/Brotli.h @@ -6,15 +6,15 @@ #pragma once +#include #include #include -#include #include namespace Compress { +using AK::LittleEndianInputBitStream; using AK::Stream; -using Core::Stream::LittleEndianInputBitStream; class BrotliDecompressionStream : public Stream { public: diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index 48bbd41c59..74a4354295 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -98,7 +99,7 @@ Optional CanonicalCode::from_bytes(ReadonlyBytes bytes) return code; } -ErrorOr CanonicalCode::read_symbol(Core::Stream::LittleEndianInputBitStream& stream) const +ErrorOr CanonicalCode::read_symbol(LittleEndianInputBitStream& stream) const { u32 code_bits = 1; @@ -115,7 +116,7 @@ ErrorOr CanonicalCode::read_symbol(Core::Stream::LittleEndianInputBitStream } } -ErrorOr CanonicalCode::write_symbol(Core::Stream::LittleEndianOutputBitStream& stream, u32 symbol) const +ErrorOr CanonicalCode::write_symbol(LittleEndianOutputBitStream& stream, u32 symbol) const { TRY(stream.write_bits(m_bit_codes[symbol], m_bit_code_lengths[symbol])); return {}; @@ -195,7 +196,7 @@ ErrorOr> DeflateDecompressor::construct(Maybe } DeflateDecompressor::DeflateDecompressor(MaybeOwned stream, CircularBuffer output_buffer) - : m_input_stream(make(move(stream))) + : m_input_stream(make(move(stream))) , m_output_buffer(move(output_buffer)) { } @@ -448,12 +449,12 @@ ErrorOr DeflateDecompressor::decode_codes(CanonicalCode& literal_code, Opt ErrorOr> DeflateCompressor::construct(MaybeOwned stream, CompressionLevel compression_level) { - auto bit_stream = TRY(Core::Stream::LittleEndianOutputBitStream::construct(move(stream))); + auto bit_stream = TRY(LittleEndianOutputBitStream::construct(move(stream))); auto deflate_compressor = TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateCompressor(move(bit_stream), compression_level))); return deflate_compressor; } -DeflateCompressor::DeflateCompressor(NonnullOwnPtr stream, CompressionLevel compression_level) +DeflateCompressor::DeflateCompressor(NonnullOwnPtr stream, CompressionLevel compression_level) : m_compression_level(compression_level) , m_compression_constants(compression_constants[static_cast(m_compression_level)]) , m_output_stream(move(stream)) diff --git a/Userland/Libraries/LibCompress/Deflate.h b/Userland/Libraries/LibCompress/Deflate.h index a709e00a6a..454560891f 100644 --- a/Userland/Libraries/LibCompress/Deflate.h +++ b/Userland/Libraries/LibCompress/Deflate.h @@ -9,9 +9,10 @@ #include #include +#include +#include #include #include -#include #include namespace Compress { @@ -19,8 +20,8 @@ namespace Compress { class CanonicalCode { public: CanonicalCode() = default; - ErrorOr read_symbol(Core::Stream::LittleEndianInputBitStream&) const; - ErrorOr write_symbol(Core::Stream::LittleEndianOutputBitStream&, u32) const; + ErrorOr read_symbol(LittleEndianInputBitStream&) const; + ErrorOr write_symbol(LittleEndianOutputBitStream&, u32) const; static CanonicalCode const& fixed_literal_codes(); static CanonicalCode const& fixed_distance_codes(); @@ -100,7 +101,7 @@ private: UncompressedBlock m_uncompressed_block; }; - MaybeOwned m_input_stream; + MaybeOwned m_input_stream; CircularBuffer m_output_buffer; }; @@ -152,7 +153,7 @@ public: static ErrorOr compress_all(ReadonlyBytes bytes, CompressionLevel = CompressionLevel::GOOD); private: - DeflateCompressor(NonnullOwnPtr, CompressionLevel = CompressionLevel::GOOD); + DeflateCompressor(NonnullOwnPtr, CompressionLevel = CompressionLevel::GOOD); Bytes pending_block() { return { m_rolling_window + block_size, block_size }; } @@ -184,7 +185,7 @@ private: bool m_finished { false }; CompressionLevel m_compression_level; CompressionConstants m_compression_constants; - NonnullOwnPtr m_output_stream; + NonnullOwnPtr m_output_stream; u8 m_rolling_window[window_size]; size_t m_pending_block_size { 0 }; diff --git a/Userland/Libraries/LibPDF/DocumentParser.cpp b/Userland/Libraries/LibPDF/DocumentParser.cpp index 3f592cf4a1..507b0e1c33 100644 --- a/Userland/Libraries/LibPDF/DocumentParser.cpp +++ b/Userland/Libraries/LibPDF/DocumentParser.cpp @@ -5,8 +5,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include -#include #include #include #include @@ -598,7 +598,7 @@ PDFErrorOr> DocumentParser::par auto input_stream = TRY(Core::Stream::FixedMemoryStream::construct(hint_stream_bytes)); TRY(input_stream->seek(sizeof(PageOffsetHintTable))); - auto bit_stream = TRY(Core::Stream::LittleEndianInputBitStream::construct(move(input_stream))); + auto bit_stream = TRY(LittleEndianInputBitStream::construct(move(input_stream))); auto number_of_pages = m_linearization_dictionary.value().number_of_pages; Vector entries;