PackBitsDecoder.h 861 B

123456789101112131415161718192021222324252627
  1. /*
  2. * Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/Optional.h>
  9. namespace Compress::PackBits {
  10. // This implements the PackBits compression scheme, aka run-length compression
  11. // It is fairly simple and described here: https://web.archive.org/web/20080705155158/http://developer.apple.com/technotes/tn/tn1023.html
  12. // But also in section:
  13. // - 7.4.5 RunLengthDecode Filter of the PDF specification
  14. // - Section 9: PackBits Compression of the TIFF specification
  15. enum class CompatibilityMode {
  16. Original, // 128 is defined as no-op
  17. PDF, // 128 is defined as end of stream
  18. };
  19. ErrorOr<ByteBuffer> decode_all(ReadonlyBytes bytes, Optional<u64> expected_output_size = {}, CompatibilityMode mode = CompatibilityMode::Original);
  20. }