From 48d3db3c3d63736d829a255cc5a0dbce9e62bc30 Mon Sep 17 00:00:00 2001 From: MacDue Date: Mon, 9 May 2022 00:00:13 +0100 Subject: LibGfx: Add Bitmap::invert() Helper function to invert a bitmap in-place --- Userland/Libraries/LibGfx/Bitmap.cpp | 8 ++++++++ Userland/Libraries/LibGfx/Bitmap.h | 2 ++ 2 files changed, 10 insertions(+) (limited to 'Userland') diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 5a98512c8a..35ba62d702 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -469,6 +469,14 @@ ErrorOr> Bitmap::to_bitmap_backed_by_anonymous_buffer() co return bitmap; } +void Bitmap::invert() +{ + for (auto y = 0; y < height(); y++) { + for (auto x = 0; x < width(); x++) + set_pixel(x, y, get_pixel(x, y).inverted()); + } +} + Bitmap::~Bitmap() { if (m_needs_munmap) { diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index 89b3130acc..968ab77087 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -121,6 +121,8 @@ public: [[nodiscard]] ShareableBitmap to_shareable_bitmap() const; + void invert(); + ~Bitmap(); [[nodiscard]] u8* scanline_u8(int physical_y); -- cgit v1.2.3