LibGfx: Add Bitmap::begin() / Bitmap::end()

Useful for accessing a bitmap like a linear container.
This commit is contained in:
Nico Weber 2023-04-03 14:29:11 -04:00 committed by Jelle Raaijmakers
parent 830fd0d5b2
commit c24e4acd19
Notes: sideshowbarker 2024-07-17 01:51:00 +09:00

View file

@ -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<ARGB32 const*>(scanline_u8(y));
}
ALWAYS_INLINE ARGB32* Bitmap::begin()
{
return scanline(0);
}
ALWAYS_INLINE ARGB32* Bitmap::end()
{
return reinterpret_cast<ARGB32*>(reinterpret_cast<u8*>(m_data) + (m_size.height() * m_pitch));
}
template<>
ALWAYS_INLINE Color Bitmap::get_pixel<StorageFormat::BGRx8888>(int x, int y) const
{