From 6aa4cb674011c7286492097d0403d3bcff8312da Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 10 Jun 2019 19:29:50 +0200 Subject: [PATCH] GraphicsBitmap: Add a fill(Color) helper. This only works for RGB32 and RGBA32 bitmaps at the moment, since it's not obvious what should happen in an Indexed8 bitmap. --- SharedGraphics/GraphicsBitmap.cpp | 9 +++++++++ SharedGraphics/GraphicsBitmap.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/SharedGraphics/GraphicsBitmap.cpp b/SharedGraphics/GraphicsBitmap.cpp index 8a7621e4e6d..5d9b85b382e 100644 --- a/SharedGraphics/GraphicsBitmap.cpp +++ b/SharedGraphics/GraphicsBitmap.cpp @@ -91,3 +91,12 @@ void GraphicsBitmap::set_mmap_name(const StringView& name) ASSERT(m_needs_munmap); ::set_mmap_name(m_data, size_in_bytes(), name.characters()); } + +void GraphicsBitmap::fill(Color color) +{ + ASSERT(m_format == GraphicsBitmap::Format::RGB32 || m_format == GraphicsBitmap::Format::RGBA32); + for (int y = 0; y < height(); ++y) { + auto* scanline = this->scanline(y); + fast_dword_fill(scanline, color.value(), width()); + } +} diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h index 9e0a24525a4..62e33a0e351 100644 --- a/SharedGraphics/GraphicsBitmap.h +++ b/SharedGraphics/GraphicsBitmap.h @@ -39,6 +39,8 @@ public: size_t pitch() const { return m_pitch; } int shared_buffer_id() const { return m_shared_buffer ? m_shared_buffer->shared_buffer_id() : -1; } + void fill(Color); + bool has_alpha_channel() const { return m_format == Format::RGBA32; } Format format() const { return m_format; }