]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - image_png.c
Made Q1 face loading faster by using a faster lightmap packing algorithm.
[xonotic/darkplaces.git] / image_png.c
index 6cf182a1e94a958f2491754940c60d1bed702ecc..d7ee8595cca680a98736a8ac3047b82be1252667 100644 (file)
@@ -229,8 +229,9 @@ void PNG_warning_fn(void *png, const char *message)
 extern int     image_width;
 extern int     image_height;
 
-unsigned char *PNG_LoadImage (const unsigned char *raw, int filesize, int matchwidth, int matchheight)
+unsigned char *PNG_LoadImage_BGRA (const unsigned char *raw, int filesize)
 {
+       unsigned int c;
        unsigned int    y;
        void *png, *pnginfo;
        unsigned char *imagedata = NULL;
@@ -311,11 +312,6 @@ unsigned char *PNG_LoadImage (const unsigned char *raw, int filesize, int matchw
        }
 #endif
 
-       if ((matchwidth && my_png.Width != (unsigned long)matchwidth) || (matchheight && my_png.Height != (unsigned long)matchheight))
-       {
-               qpng_destroy_read_struct(&png, &pnginfo, 0);
-               return NULL;
-       }
        if (my_png.ColorType == PNG_COLOR_TYPE_PALETTE)
                qpng_set_palette_to_rgb(png);
        if (my_png.ColorType == PNG_COLOR_TYPE_GRAY || my_png.ColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
@@ -371,6 +367,14 @@ unsigned char *PNG_LoadImage (const unsigned char *raw, int filesize, int matchw
                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;
 }