From c24e4acd19406ac2ff302b173ee1310b112441ba Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 3 Apr 2023 14:29:11 -0400 Subject: LibGfx: Add Bitmap::begin() / Bitmap::end() Useful for accessing a bitmap like a linear container. --- Userland/Libraries/LibGfx/Bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Userland') diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index 7d71839554..786af81287 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -135,6 +135,9 @@ public: [[nodiscard]] ARGB32* scanline(int physical_y); [[nodiscard]] ARGB32 const* scanline(int physical_y) const; + [[nodiscard]] ARGB32* begin(); + [[nodiscard]] ARGB32* end(); + [[nodiscard]] IntRect rect() const { return { {}, m_size }; } [[nodiscard]] IntSize size() const { return m_size; } [[nodiscard]] int width() const { return m_size.width(); } @@ -293,6 +296,16 @@ ALWAYS_INLINE ARGB32 const* Bitmap::scanline(int y) const return reinterpret_cast(scanline_u8(y)); } +ALWAYS_INLINE ARGB32* Bitmap::begin() +{ + return scanline(0); +} + +ALWAYS_INLINE ARGB32* Bitmap::end() +{ + return reinterpret_cast(reinterpret_cast(m_data) + (m_size.height() * m_pitch)); +} + template<> ALWAYS_INLINE Color Bitmap::get_pixel(int x, int y) const { -- cgit v1.2.3