CCITTDecoder.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. namespace Gfx::CCITT {
  9. // You can find a great overview of CCITT compression schemes here:
  10. // https://www.fileformat.info/mirror/egff/ch09_05.htm
  11. // The CCITT3 specification is accessible at this page:
  12. // https://www.itu.int/rec/T-REC-T.4/en
  13. // And CCITT4's specification is available here:
  14. // https://www.itu.int/rec/T-REC-T.6/en
  15. // The unidimensional scheme is originally described in:
  16. // 4.1 One-dimensional coding scheme
  17. // However, this function implements the TIFF variant (see TIFFLoader.h for a spec link),
  18. // differences are detailed in section:
  19. // Section 10: Modified Huffman Compression
  20. ErrorOr<ByteBuffer> decode_ccitt_rle(ReadonlyBytes bytes, u32 image_width, u32 image_height);
  21. // While this is named for a CCITT context, this struct holds data like TIFF's T4Options tag
  22. struct Group3Options {
  23. enum class Mode : u8 {
  24. OneDimension,
  25. TwoDimensions,
  26. };
  27. enum class Compression : u8 {
  28. Uncompressed,
  29. Compressed,
  30. };
  31. enum class UseFillBits : u8 {
  32. No = 0,
  33. Yes = 1,
  34. };
  35. Mode dimensions = Mode::OneDimension;
  36. Compression compression = Compression::Compressed;
  37. UseFillBits use_fill_bits = UseFillBits::No;
  38. };
  39. ErrorOr<ByteBuffer> decode_ccitt_group3(ReadonlyBytes bytes, u32 image_width, u32 image_height, Group3Options const& options);
  40. ErrorOr<ByteBuffer> decode_ccitt_group4(ReadonlyBytes bytes, u32 image_width, u32 image_height);
  41. }