Browse Source

LibGfx: Support the RGBA8888 storage format in Bitmap::set_pixel()

Linus Groh 3 years ago
parent
commit
ca3c45cc1f
1 changed files with 12 additions and 0 deletions
  1. 12 0
      Userland/Libraries/LibGfx/Bitmap.h

+ 12 - 0
Userland/Libraries/LibGfx/Bitmap.h

@@ -325,6 +325,15 @@ inline void Bitmap::set_pixel<StorageFormat::BGRA8888>(int x, int y, Color color
     VERIFY(x >= 0 && x < physical_width());
     scanline(y)[x] = color.value(); // drop alpha
 }
+template<>
+inline void Bitmap::set_pixel<StorageFormat::RGBA8888>(int x, int y, Color color)
+{
+    VERIFY(x >= 0 && x < physical_width());
+    // FIXME: There's a lot of inaccurately named functions in the Color class right now (RGBA vs BGRA),
+    //        clear those up and then make this more convenient.
+    auto rgba = (color.alpha() << 24) | (color.blue() << 16) | (color.green() << 8) | color.red();
+    scanline(y)[x] = rgba;
+}
 inline void Bitmap::set_pixel(int x, int y, Color color)
 {
     switch (determine_storage_format(m_format)) {
@@ -334,6 +343,9 @@ inline void Bitmap::set_pixel(int x, int y, Color color)
     case StorageFormat::BGRA8888:
         set_pixel<StorageFormat::BGRA8888>(x, y, color);
         break;
+    case StorageFormat::RGBA8888:
+        set_pixel<StorageFormat::RGBA8888>(x, y, color);
+        break;
     case StorageFormat::Indexed8:
         VERIFY_NOT_REACHED();
     default: