From d539f3b80cb6a2a0451149c131afa5e4a38ac3ca Mon Sep 17 00:00:00 2001
From: Sam Hocevar <sam@hocevar.net>
Date: Sun, 8 Apr 2012 13:28:26 +0000
Subject: [PATCH] win32: shuffle bytes in GDI images to match what OpenGL
 supports.

---
 src/image/codec/gdiplus-image.cpp | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/image/codec/gdiplus-image.cpp b/src/image/codec/gdiplus-image.cpp
index 0182e579..2fa74d64 100644
--- a/src/image/codec/gdiplus-image.cpp
+++ b/src/image/codec/gdiplus-image.cpp
@@ -95,6 +95,20 @@ bool GdiPlusImageData::Open(char const *path)
         return false;
     }
 
+    /* FIXME: GDI+ doesn't know about RGBA, only ARGB. And OpenGL doesn't
+     * know about ARGB, only RGBA. So we swap bytes. We could also fix
+     * this in the shader. */
+    uint8_t *p = static_cast<uint8_t *>(bdata.Scan0);
+    for (int y = 0; y < size.y; y++)
+        for (int x = 0; x < size.x; x++)
+        {
+            uint8_t tmp = p[0];
+            *p++ = p[1];
+            *p++ = p[1];
+            *p++ = p[1];
+            *p++ = tmp;
+        }
+
     return true;
 }