CCITTDecoder.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // The unidimensional scheme is originally described in:
  14. // 4.1 One-dimensional coding scheme
  15. // However, this function implements the TIFF variant (see TIFFLoader.h for a spec link),
  16. // differences are detailed in section:
  17. // Section 10: Modified Huffman Compression
  18. ErrorOr<ByteBuffer> decode_ccitt_rle(ReadonlyBytes bytes, u32 image_width, u32 image_height);
  19. // While this is named for a CCITT context, this struct holds data like TIFF's T4Options tag
  20. struct Group3Options {
  21. enum class Mode : u8 {
  22. OneDimension,
  23. TwoDimensions,
  24. };
  25. enum class Compression : u8 {
  26. Uncompressed,
  27. Compressed,
  28. };
  29. enum class UseFillBits : u8 {
  30. No = 0,
  31. Yes = 1,
  32. };
  33. Mode dimensions = Mode::OneDimension;
  34. Compression compression = Compression::Compressed;
  35. UseFillBits use_fill_bits = UseFillBits::No;
  36. };
  37. ErrorOr<ByteBuffer> decode_ccitt_group3(ReadonlyBytes bytes, u32 image_width, u32 image_height, Group3Options const& options);
  38. }