From b8ff139f9c25486b8b38ff703494d80fd84ad684 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 12 Jun 2026 13:14:40 +0100 Subject: [PATCH] LibCompress: Remove `PackBitsDecoder` This is no longer used. --- Libraries/LibCompress/CMakeLists.txt | 1 - Libraries/LibCompress/PackBitsDecoder.cpp | 46 ----------------------- Libraries/LibCompress/PackBitsDecoder.h | 27 ------------- Tests/LibCompress/CMakeLists.txt | 1 - Tests/LibCompress/TestPackBits.cpp | 25 ------------ 5 files changed, 100 deletions(-) delete mode 100644 Libraries/LibCompress/PackBitsDecoder.cpp delete mode 100644 Libraries/LibCompress/PackBitsDecoder.h delete mode 100644 Tests/LibCompress/TestPackBits.cpp diff --git a/Libraries/LibCompress/CMakeLists.txt b/Libraries/LibCompress/CMakeLists.txt index 6c593d6615..0e54758c1e 100644 --- a/Libraries/LibCompress/CMakeLists.txt +++ b/Libraries/LibCompress/CMakeLists.txt @@ -2,7 +2,6 @@ set(SOURCES Deflate.cpp GenericZlib.cpp Gzip.cpp - PackBitsDecoder.cpp Zlib.cpp ) diff --git a/Libraries/LibCompress/PackBitsDecoder.cpp b/Libraries/LibCompress/PackBitsDecoder.cpp deleted file mode 100644 index 1e5567ed6e..0000000000 --- a/Libraries/LibCompress/PackBitsDecoder.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023, Lucas Chollet - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "PackBitsDecoder.h" -#include -#include - -namespace Compress::PackBits { - -ErrorOr decode_all(ReadonlyBytes bytes, Optional expected_output_size, CompatibilityMode mode) -{ - // This implementation uses unsigned values for the selector, as described in the PDF spec. - // Note that this remains compatible with other implementations based on signed numbers. - - auto memory_stream = make(bytes); - - ByteBuffer decoded_bytes; - - if (expected_output_size.has_value()) - TRY(decoded_bytes.try_ensure_capacity(*expected_output_size)); - - while (memory_stream->remaining() > 0 && decoded_bytes.size() < expected_output_size.value_or(NumericLimits::max())) { - auto const length = TRY(memory_stream->read_value()); - - if (length < 128) { - for (u8 i = 0; i <= length; ++i) - TRY(decoded_bytes.try_append(TRY(memory_stream->read_value()))); - } else if (length > 128) { - auto const next_byte = TRY(memory_stream->read_value()); - - for (u8 i = 0; i < 257 - length; ++i) - TRY(decoded_bytes.try_append(next_byte)); - } else { - VERIFY(length == 128); - if (mode == CompatibilityMode::PDF) - break; - } - } - - return decoded_bytes; -} - -} diff --git a/Libraries/LibCompress/PackBitsDecoder.h b/Libraries/LibCompress/PackBitsDecoder.h deleted file mode 100644 index 1badb8dc60..0000000000 --- a/Libraries/LibCompress/PackBitsDecoder.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2023, Lucas Chollet - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace Compress::PackBits { - -// This implements the PackBits compression scheme, aka run-length compression -// It is fairly simple and described here: https://web.archive.org/web/20080705155158/http://developer.apple.com/technotes/tn/tn1023.html -// But also in section: -// - 7.4.5 RunLengthDecode Filter of the PDF specification -// - Section 9: PackBits Compression of the TIFF specification - -enum class CompatibilityMode { - Original, // 128 is defined as no-op - PDF, // 128 is defined as end of stream -}; - -ErrorOr decode_all(ReadonlyBytes bytes, Optional expected_output_size = {}, CompatibilityMode mode = CompatibilityMode::Original); - -} diff --git a/Tests/LibCompress/CMakeLists.txt b/Tests/LibCompress/CMakeLists.txt index 258f185eb5..75b3d0b8cd 100644 --- a/Tests/LibCompress/CMakeLists.txt +++ b/Tests/LibCompress/CMakeLists.txt @@ -2,7 +2,6 @@ set(TEST_SOURCES TestDeflate.cpp TestGzip.cpp TestLzw.cpp - TestPackBits.cpp TestZlib.cpp ) diff --git a/Tests/LibCompress/TestPackBits.cpp b/Tests/LibCompress/TestPackBits.cpp deleted file mode 100644 index cd32339cc8..0000000000 --- a/Tests/LibCompress/TestPackBits.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2023, Lucas Chollet - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#include -#include - -TEST_CASE(pack_bits) -{ - Array const compressed { - 0xFE, 0xAA, 0x02, 0x80, 0x00, 0x2A, 0xFD, 0xAA, 0x03, 0x80, 0x00, 0x2A, 0x22, 0xF7, 0xAA - }; - - Array const raw { - 0xAA, 0xAA, 0xAA, 0x80, 0x00, 0x2A, 0xAA, 0xAA, 0xAA, 0xAA, 0x80, 0x00, - 0x2A, 0x22, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA - }; - - auto unpacked = TRY_OR_FAIL(Compress::PackBits::decode_all(compressed)); - EXPECT_EQ(unpacked.bytes(), raw); -}