From 1ec5172ce1c1edb4366fbc7ab596a26fcedd8602 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 14 Jun 2019 19:10:59 +0200 Subject: [PATCH] GraphicsBitmap: Add set_pixel(x, y, Color) This only works for RGB32 and RGBA32 formats. --- SharedGraphics/GraphicsBitmap.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/SharedGraphics/GraphicsBitmap.h b/SharedGraphics/GraphicsBitmap.h index 62e33a0e35..c73dca70dd 100644 --- a/SharedGraphics/GraphicsBitmap.h +++ b/SharedGraphics/GraphicsBitmap.h @@ -65,6 +65,32 @@ public: } } + Color get_pixel(const Point& position) const + { + return get_pixel(position.x(), position.y()); + } + + void set_pixel(int x, int y, Color color) + { + switch (m_format) { + case Format::RGB32: + scanline(y)[x] = color.value(); + break; + case Format::RGBA32: + scanline(y)[x] = color.value(); + break; + case Format::Indexed8: + ASSERT_NOT_REACHED(); + default: + ASSERT_NOT_REACHED(); + } + } + + void set_pixel(const Point& position, Color color) + { + set_pixel(position.x(), position.y(), color); + } + private: GraphicsBitmap(Format, const Size&); GraphicsBitmap(Format, const Size&, RGBA32*);