CharacterBitmap.h 969 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include "Size.h"
  9. #include <AK/RefCounted.h>
  10. #include <AK/RefPtr.h>
  11. #include <AK/StringView.h>
  12. namespace Gfx {
  13. class CharacterBitmap {
  14. public:
  15. CharacterBitmap() = delete;
  16. constexpr CharacterBitmap(StringView ascii_data, unsigned width, unsigned height)
  17. : m_bits(ascii_data)
  18. , m_size(width, height)
  19. {
  20. }
  21. constexpr ~CharacterBitmap() = default;
  22. constexpr bool bit_at(unsigned x, unsigned y) const { return m_bits[y * width() + x] == '#'; }
  23. constexpr StringView bits() const { return m_bits; }
  24. constexpr IntSize size() const { return m_size; }
  25. constexpr unsigned width() const { return m_size.width(); }
  26. constexpr unsigned height() const { return m_size.height(); }
  27. private:
  28. StringView m_bits {};
  29. IntSize m_size {};
  30. };
  31. }