BMPWriter.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2020, Ben Jilks <benjyjilks@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. namespace Gfx {
  9. class Bitmap;
  10. // This is not a nested struct to work around https://llvm.org/PR36684
  11. struct BMPWriterOptions {
  12. enum class DibHeader : u32 {
  13. Info = 40,
  14. V3 = 56,
  15. V4 = 108,
  16. V5 = 124,
  17. };
  18. DibHeader dib_header = DibHeader::V5;
  19. Optional<ReadonlyBytes> icc_data;
  20. };
  21. class BMPWriter {
  22. public:
  23. using Options = BMPWriterOptions;
  24. static ErrorOr<ByteBuffer> encode(Bitmap const&, Options options = Options {});
  25. private:
  26. BMPWriter() = default;
  27. ErrorOr<ByteBuffer> dump(Bitmap const&, Options options);
  28. enum class Compression : u32 {
  29. BI_RGB = 0,
  30. BI_BITFIELDS = 3,
  31. };
  32. static ByteBuffer compress_pixel_data(ByteBuffer, Compression);
  33. Compression m_compression { Compression::BI_BITFIELDS };
  34. int m_bytes_per_pixel { 4 };
  35. bool m_include_alpha_channel { true };
  36. };
  37. }