Sfoglia il codice sorgente

LibGfx: Add Bitmap::invert()

Helper function to invert a bitmap in-place
MacDue 3 anni fa
parent
commit
48d3db3c3d

+ 8 - 0
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) {

+ 2 - 0
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);