]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - image_png.c
fix crashes when recursing portals on maps with some bogus leafs (where
[xonotic/darkplaces.git] / image_png.c
index b53aee42ead27d9237509a030d654daef7db4d41..2dac76faddd5eedc2e28d8e764b75051e55667c1 100644 (file)
@@ -121,14 +121,7 @@ qboolean PNG_OpenLibrary (void)
                return true;
 
        // Load the DLL
-       if (! Sys_LoadLibrary (dllnames, &png_dll, pngfuncs))
-       {
-               Con_Printf ("PNG support disabled\n");
-               return false;
-       }
-
-       Con_Printf ("PNG support enabled\n");
-       return true;
+       return Sys_LoadLibrary (dllnames, &png_dll, pngfuncs);
 }
 
 
@@ -231,6 +224,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 +360,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;
 }