CCITTDecoder.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // Addition from the PDF specification
  36. enum class RequireEndOfLine : u8 {
  37. No = 0,
  38. Yes = 1,
  39. };
  40. enum class EncodedByteAligned : u8 {
  41. No = 0,
  42. Yes = 1,
  43. };
  44. Mode dimensions = Mode::OneDimension;
  45. Compression compression = Compression::Compressed;
  46. UseFillBits use_fill_bits = UseFillBits::No;
  47. // Default values are set to be compatible with the CCITT specification
  48. RequireEndOfLine require_end_of_line = RequireEndOfLine::Yes;
  49. EncodedByteAligned encoded_byte_aligned = EncodedByteAligned::No;
  50. };
  51. ErrorOr<ByteBuffer> decode_ccitt_group3(ReadonlyBytes bytes, u32 image_width, u32 image_height, Group3Options const& options);
  52. ErrorOr<ByteBuffer> decode_ccitt_group4(ReadonlyBytes bytes, u32 image_width, u32 image_height);
  53. }