From 7568ea31605c0b53c144ee72e31cc0841a1f5a1e Mon Sep 17 00:00:00 2001 From: InvalidUsernameException Date: Sat, 19 Apr 2025 17:26:57 +0200 Subject: [PATCH] LibGfx: Simplify get_pixel() There appears to be no reason for Bitmap::get_pixel() to be split into three layers of methods. Make the code simpler by inlining everything into a single method. --- Libraries/LibGfx/Bitmap.h | 44 +++++---------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/Libraries/LibGfx/Bitmap.h b/Libraries/LibGfx/Bitmap.h index b5cd59a2eb2..904fa8db34a 100644 --- a/Libraries/LibGfx/Bitmap.h +++ b/Libraries/LibGfx/Bitmap.h @@ -120,11 +120,6 @@ public: [[nodiscard]] static constexpr size_t size_in_bytes(size_t pitch, int height) { return pitch * height; } [[nodiscard]] size_t size_in_bytes() const { return size_in_bytes(m_pitch, height()); } - template - [[nodiscard]] Color unchecked_get_pixel(int physical_x, int physical_y) const; - - template - [[nodiscard]] Color get_pixel(int physical_x, int physical_y) const; [[nodiscard]] Color get_pixel(int physical_x, int physical_y) const; [[nodiscard]] Color get_pixel(IntPoint physical_position) const { @@ -232,49 +227,20 @@ ALWAYS_INLINE size_t Bitmap::data_size() const return m_size.height() * m_pitch; } -template<> -ALWAYS_INLINE Color Bitmap::unchecked_get_pixel(int x, int y) const -{ - return Color::from_rgb(unchecked_scanline(y)[x]); -} - -template<> -ALWAYS_INLINE Color Bitmap::unchecked_get_pixel(int x, int y) const -{ - return Color::from_argb(unchecked_scanline(y)[x]); -} - -template<> -ALWAYS_INLINE Color Bitmap::unchecked_get_pixel(int x, int y) const -{ - return Color::from_bgr(unchecked_scanline(y)[x]); -} - -template<> -ALWAYS_INLINE Color Bitmap::unchecked_get_pixel(int x, int y) const -{ - return Color::from_abgr(unchecked_scanline(y)[x]); -} - -template ALWAYS_INLINE Color Bitmap::get_pixel(int x, int y) const { VERIFY(x >= 0); VERIFY(x < width()); - return unchecked_get_pixel(x, y); -} - -ALWAYS_INLINE Color Bitmap::get_pixel(int x, int y) const -{ + auto pixel = unchecked_scanline(y)[x]; switch (determine_storage_format(m_format)) { case StorageFormat::BGRx8888: - return get_pixel(x, y); + return Color::from_rgb(pixel); case StorageFormat::BGRA8888: - return get_pixel(x, y); + return Color::from_argb(pixel); case StorageFormat::RGBA8888: - return get_pixel(x, y); + return Color::from_abgr(pixel); case StorageFormat::RGBx8888: - return get_pixel(x, y); + return Color::from_bgr(pixel); default: VERIFY_NOT_REACHED(); }