diff options
author | Andreas Kling <kling@serenityos.org> | 2020-11-02 11:01:00 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-02 11:01:00 +0100 |
commit | ee21a724c75e5d398c9c227e2aec64452f550749 (patch) | |
tree | f7c7881a1f76b292c2e7b33830d6ab38fa3a708b /Libraries/LibGfx | |
parent | 23c4f1a3d41f2697a04e60ffa3cf678e6e1bb692 (diff) | |
download | serenity-ee21a724c75e5d398c9c227e2aec64452f550749.zip |
LibGfx: Add some more assertions to Gfx::Bitmap
Let's also be paranoid about get_pixel() since we started worrying
about set_pixel(). :^)
Diffstat (limited to 'Libraries/LibGfx')
-rw-r--r-- | Libraries/LibGfx/Bitmap.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Libraries/LibGfx/Bitmap.h b/Libraries/LibGfx/Bitmap.h index 24baa2281d..2aabb3e83e 100644 --- a/Libraries/LibGfx/Bitmap.h +++ b/Libraries/LibGfx/Bitmap.h @@ -247,11 +247,13 @@ private: inline u8* Bitmap::scanline_u8(int y) { + ASSERT(y >= 0 && y < height()); return reinterpret_cast<u8*>(m_data) + (y * m_pitch); } inline const u8* Bitmap::scanline_u8(int y) const { + ASSERT(y >= 0 && y < height()); return reinterpret_cast<const u8*>(m_data) + (y * m_pitch); } @@ -268,18 +270,21 @@ inline const RGBA32* Bitmap::scanline(int y) const template<> inline Color Bitmap::get_pixel<StorageFormat::RGB32>(int x, int y) const { + ASSERT(x >= 0 && x < width()); return Color::from_rgb(scanline(y)[x]); } template<> inline Color Bitmap::get_pixel<StorageFormat::RGBA32>(int x, int y) const { + ASSERT(x >= 0 && x < width()); return Color::from_rgba(scanline(y)[x]); } template<> inline Color Bitmap::get_pixel<StorageFormat::Indexed8>(int x, int y) const { + ASSERT(x >= 0 && x < width()); return Color::from_rgb(m_palette[scanline_u8(y)[x]]); } @@ -300,13 +305,13 @@ inline Color Bitmap::get_pixel(int x, int y) const template<> inline void Bitmap::set_pixel<StorageFormat::RGB32>(int x, int y, Color color) { - ASSERT(rect().contains(x, y)); + ASSERT(x >= 0 && x < width()); scanline(y)[x] = color.value(); } template<> inline void Bitmap::set_pixel<StorageFormat::RGBA32>(int x, int y, Color color) { - ASSERT(rect().contains(x, y)); + ASSERT(x >= 0 && x < width()); scanline(y)[x] = color.value(); // drop alpha } inline void Bitmap::set_pixel(int x, int y, Color color) |