summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-01-25 20:06:16 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-01-29 19:16:44 -0700
commit2470dd3bb5f437658ec2f95ff3e7f0bb2e0b5448 (patch)
tree647f8b75f2248efbb8d732098e0cad3c2fe0f037
parent94f139c1117e2870c45df27085b004723b5b86ca (diff)
downloadserenity-2470dd3bb5f437658ec2f95ff3e7f0bb2e0b5448.zip
AK: Move bit streams from `LibCore`
-rw-r--r--AK/BitStream.h (renamed from Userland/Libraries/LibCore/BitStream.h)19
-rw-r--r--AK/Forward.h8
-rw-r--r--Tests/AK/CMakeLists.txt1
-rw-r--r--Tests/AK/TestBitStream.cpp121
-rw-r--r--Tests/LibCompress/TestDeflate.cpp6
-rw-r--r--Tests/LibCore/TestLibCoreStream.cpp115
-rw-r--r--Userland/Libraries/LibAudio/FlacLoader.h4
-rw-r--r--Userland/Libraries/LibAudio/MP3HuffmanTables.h3
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.cpp8
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.h8
-rw-r--r--Userland/Libraries/LibCompress/Brotli.h4
-rw-r--r--Userland/Libraries/LibCompress/Deflate.cpp11
-rw-r--r--Userland/Libraries/LibCompress/Deflate.h13
-rw-r--r--Userland/Libraries/LibPDF/DocumentParser.cpp4
14 files changed, 167 insertions, 158 deletions
diff --git a/Userland/Libraries/LibCore/BitStream.h b/AK/BitStream.h
index 4610df32e7..922e86da17 100644
--- a/Userland/Libraries/LibCore/BitStream.h
+++ b/AK/BitStream.h
@@ -7,22 +7,15 @@
#pragma once
#include <AK/ByteBuffer.h>
-#include <AK/Concepts.h>
-#include <AK/Error.h>
#include <AK/MaybeOwned.h>
-#include <AK/NonnullOwnPtr.h>
-#include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h>
-#include <AK/Span.h>
-#include <AK/StdLibExtraDetails.h>
-#include <AK/Types.h>
-#include <LibCore/Stream.h>
+#include <AK/Stream.h>
-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<NonnullOwnPtr<BigEndianInputBitStream>> construct(MaybeOwned<Stream> 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<NonnullOwnPtr<LittleEndianInputBitStream>> construct(MaybeOwned<Stream> 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<NonnullOwnPtr<BigEndianOutputBitStream>> construct(MaybeOwned<Stream> 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<NonnullOwnPtr<LittleEndianOutputBitStream>> construct(MaybeOwned<Stream> 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 <timschumi@gmx.de>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/BitStream.h>
+#include <LibCore/MemoryStream.h>
+#include <LibTest/TestCase.h>
+
+// 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<Core::Stream::AllocatingMemoryStream>();
+
+ // 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<AK::Stream>(*memory_stream)));
+ auto bit_read_stream = MUST(LittleEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*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<Core::Stream::AllocatingMemoryStream>();
+
+ // 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<AK::Stream>(*memory_stream)));
+ auto bit_read_stream = MUST(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*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 <LibTest/TestCase.h>
#include <AK/Array.h>
+#include <AK/BitStream.h>
#include <AK/Random.h>
#include <LibCompress/Deflate.h>
-#include <LibCore/BitStream.h>
#include <LibCore/MemoryStream.h>
#include <cstring>
@@ -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 <AK/Format.h>
#include <AK/MaybeOwned.h>
#include <AK/String.h>
-#include <LibCore/BitStream.h>
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <LibCore/MemoryStream.h>
@@ -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<Core::Stream::AllocatingMemoryStream>();
-
- // 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<AK::Stream>(*memory_stream)));
- auto bit_read_stream = MUST(Core::Stream::LittleEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*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<Core::Stream::AllocatingMemoryStream>();
-
- // 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<AK::Stream>(*memory_stream)));
- auto bit_read_stream = MUST(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*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 <AK/BitStream.h>
#include <AK/Error.h>
#include <AK/Span.h>
#include <AK/Types.h>
-#include <LibCore/BitStream.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
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 <AK/Array.h>
+#include <AK/BitStream.h>
#include <AK/Span.h>
namespace Audio::MP3::Tables::Huffman {
@@ -105,7 +106,7 @@ struct HuffmanDecodeResult {
};
template<typename T>
-HuffmanDecodeResult<T> huffman_decode(Core::Stream::BigEndianInputBitStream& bitstream, Span<HuffmanNode<T> const> tree, size_t max_bits_to_read)
+HuffmanDecodeResult<T> huffman_decode(BigEndianInputBitStream& bitstream, Span<HuffmanNode<T> const> tree, size_t max_bits_to_read)
{
HuffmanNode<T> 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<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(Byte
MaybeLoaderError MP3LoaderPlugin::initialize()
{
- m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*m_stream)));
+ m_bitstream = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(*m_stream)));
TRY(synchronize());
@@ -242,7 +242,7 @@ ErrorOr<MP3::MP3Frame, LoaderError> 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<AK::Stream>(m_bit_reservoir)));
+ auto reservoir_stream = TRY(BigEndianInputBitStream::construct(MaybeOwned<AK::Stream>(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<float, 576> MP3LoaderPlugin::calculate_frame_exponents(MP3::MP3Frame const
return exponents;
}
-ErrorOr<size_t, LoaderError> MP3LoaderPlugin::read_scale_factors(MP3::MP3Frame& frame, Core::Stream::BigEndianInputBitStream& reservoir, size_t granule_index, size_t channel_index)
+ErrorOr<size_t, LoaderError> 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<size_t, LoaderError> 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 <AK/BitStream.h>
#include <AK/Tuple.h>
-#include <LibCore/BitStream.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
#include <LibDSP/MDCT.h>
@@ -48,8 +48,8 @@ private:
ErrorOr<MP3::MP3Frame, LoaderError> read_next_frame();
ErrorOr<MP3::MP3Frame, LoaderError> read_frame_data(MP3::Header const&);
MaybeLoaderError read_side_information(MP3::MP3Frame&);
- ErrorOr<size_t, LoaderError> 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<size_t, LoaderError> 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<float, 576> 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<MP3::MP3Frame> m_current_frame;
u32 m_current_frame_read;
- OwnPtr<Core::Stream::BigEndianInputBitStream> m_bitstream;
+ OwnPtr<BigEndianInputBitStream> 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 <AK/BitStream.h>
#include <AK/CircularQueue.h>
#include <AK/FixedArray.h>
-#include <LibCore/BitStream.h>
#include <LibCore/Stream.h>
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 <AK/Assertions.h>
#include <AK/BinaryHeap.h>
#include <AK/BinarySearch.h>
+#include <AK/BitStream.h>
#include <LibCore/MemoryStream.h>
#include <string.h>
@@ -98,7 +99,7 @@ Optional<CanonicalCode> CanonicalCode::from_bytes(ReadonlyBytes bytes)
return code;
}
-ErrorOr<u32> CanonicalCode::read_symbol(Core::Stream::LittleEndianInputBitStream& stream) const
+ErrorOr<u32> CanonicalCode::read_symbol(LittleEndianInputBitStream& stream) const
{
u32 code_bits = 1;
@@ -115,7 +116,7 @@ ErrorOr<u32> CanonicalCode::read_symbol(Core::Stream::LittleEndianInputBitStream
}
}
-ErrorOr<void> CanonicalCode::write_symbol(Core::Stream::LittleEndianOutputBitStream& stream, u32 symbol) const
+ErrorOr<void> 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<NonnullOwnPtr<DeflateDecompressor>> DeflateDecompressor::construct(Maybe
}
DeflateDecompressor::DeflateDecompressor(MaybeOwned<AK::Stream> stream, CircularBuffer output_buffer)
- : m_input_stream(make<Core::Stream::LittleEndianInputBitStream>(move(stream)))
+ : m_input_stream(make<LittleEndianInputBitStream>(move(stream)))
, m_output_buffer(move(output_buffer))
{
}
@@ -448,12 +449,12 @@ ErrorOr<void> DeflateDecompressor::decode_codes(CanonicalCode& literal_code, Opt
ErrorOr<NonnullOwnPtr<DeflateCompressor>> DeflateCompressor::construct(MaybeOwned<AK::Stream> 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<Core::Stream::LittleEndianOutputBitStream> stream, CompressionLevel compression_level)
+DeflateCompressor::DeflateCompressor(NonnullOwnPtr<LittleEndianOutputBitStream> stream, CompressionLevel compression_level)
: m_compression_level(compression_level)
, m_compression_constants(compression_constants[static_cast<int>(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 <AK/ByteBuffer.h>
#include <AK/Endian.h>
+#include <AK/Forward.h>
+#include <AK/MaybeOwned.h>
#include <AK/Vector.h>
#include <LibCompress/DeflateTables.h>
-#include <LibCore/BitStream.h>
#include <LibCore/Stream.h>
namespace Compress {
@@ -19,8 +20,8 @@ namespace Compress {
class CanonicalCode {
public:
CanonicalCode() = default;
- ErrorOr<u32> read_symbol(Core::Stream::LittleEndianInputBitStream&) const;
- ErrorOr<void> write_symbol(Core::Stream::LittleEndianOutputBitStream&, u32) const;
+ ErrorOr<u32> read_symbol(LittleEndianInputBitStream&) const;
+ ErrorOr<void> 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<Core::Stream::LittleEndianInputBitStream> m_input_stream;
+ MaybeOwned<LittleEndianInputBitStream> m_input_stream;
CircularBuffer m_output_buffer;
};
@@ -152,7 +153,7 @@ public:
static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes, CompressionLevel = CompressionLevel::GOOD);
private:
- DeflateCompressor(NonnullOwnPtr<Core::Stream::LittleEndianOutputBitStream>, CompressionLevel = CompressionLevel::GOOD);
+ DeflateCompressor(NonnullOwnPtr<LittleEndianOutputBitStream>, 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<Core::Stream::LittleEndianOutputBitStream> m_output_stream;
+ NonnullOwnPtr<LittleEndianOutputBitStream> 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 <AK/BitStream.h>
#include <AK/Tuple.h>
-#include <LibCore/BitStream.h>
#include <LibCore/MemoryStream.h>
#include <LibPDF/CommonNames.h>
#include <LibPDF/Document.h>
@@ -598,7 +598,7 @@ PDFErrorOr<Vector<DocumentParser::PageOffsetHintTableEntry>> 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<PageOffsetHintTableEntry> entries;