summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-05-09 00:00:13 +0100
committerLinus Groh <mail@linusgroh.de>2022-05-26 00:07:24 +0100
commit48d3db3c3d63736d829a255cc5a0dbce9e62bc30 (patch)
tree0657c745439fb866d19d50658015a5ea00080ae9
parent59598ded15a489e9103eade3f9f4d263dd75390f (diff)
downloadserenity-48d3db3c3d63736d829a255cc5a0dbce9e62bc30.zip
LibGfx: Add Bitmap::invert()
Helper function to invert a bitmap in-place
-rw-r--r--Userland/Libraries/LibGfx/Bitmap.cpp8
-rw-r--r--Userland/Libraries/LibGfx/Bitmap.h2
2 files changed, 10 insertions, 0 deletions
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<NonnullRefPtr<Bitmap>> 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);