GrayscaleBitmap.h 898 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2023, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "Size.h"
  8. #include <AK/RefCounted.h>
  9. #include <AK/RefPtr.h>
  10. #include <AK/StringView.h>
  11. namespace Gfx {
  12. class GrayscaleBitmap {
  13. public:
  14. GrayscaleBitmap() = delete;
  15. constexpr GrayscaleBitmap(ReadonlyBytes data, unsigned width, unsigned height)
  16. : m_data(data)
  17. , m_size(width, height)
  18. {
  19. VERIFY(width * height == data.size());
  20. }
  21. constexpr u8 pixel_at(unsigned x, unsigned y) const { return m_data[y * width() + x]; }
  22. constexpr ReadonlyBytes data() const { return m_data; }
  23. constexpr IntSize size() const { return m_size; }
  24. constexpr unsigned width() const { return m_size.width(); }
  25. constexpr unsigned height() const { return m_size.height(); }
  26. private:
  27. ReadonlyBytes m_data {};
  28. IntSize m_size {};
  29. };
  30. }