From cdec1b4d3aa35f5e1b785db19d94805eddba6049 Mon Sep 17 00:00:00 2001
From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Thu, 29 Nov 2007 06:18:44 +0000
Subject: [PATCH] swizzle RGBA to BGRA in png loader

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7735 d7cf8633-e32d-0410-b094-e92efae38249
---
 image_png.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/image_png.c b/image_png.c
index b53aee42..d7ee8595 100644
--- a/image_png.c
+++ b/image_png.c
@@ -231,6 +231,7 @@ extern int	image_height;
 
 unsigned char *PNG_LoadImage_BGRA (const unsigned char *raw, int filesize)
 {
+	unsigned int c;
 	unsigned int	y;
 	void *png, *pnginfo;
 	unsigned char *imagedata = NULL;
@@ -366,6 +367,14 @@ unsigned char *PNG_LoadImage_BGRA (const unsigned char *raw, int filesize)
 		imagedata = NULL;
 	}
 
+	// swizzle RGBA to BGRA
+	for (y = 0;y < (unsigned int)(image_width*image_height*4);y += 4)
+	{
+		c = imagedata[y+0];
+		imagedata[y+0] = imagedata[y+2];
+		imagedata[y+2] = c;
+	}
+
 	return imagedata;
 }
 
-- 
2.39.5