PortableFormatWriter.h 898 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 <LibGfx/Bitmap.h>
  9. namespace Gfx {
  10. // This is not a nested struct to work around https://llvm.org/PR36684
  11. struct PortableFormatWriterOptions {
  12. enum class Format {
  13. ASCII,
  14. Raw,
  15. };
  16. Format format = Format::Raw;
  17. StringView comment = "Generated with SerenityOS - LibGfx."sv;
  18. };
  19. class PortableFormatWriter {
  20. public:
  21. using Options = PortableFormatWriterOptions;
  22. static ErrorOr<void> encode(Stream&, Bitmap const&, Options options = Options {});
  23. private:
  24. PortableFormatWriter() = delete;
  25. static ErrorOr<void> add_header(Stream&, Options const& options, u32 width, u32 height, u32 max_value);
  26. static ErrorOr<void> add_pixels(Stream&, Options const& options, Bitmap const&);
  27. };
  28. }