X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=image_png.c;h=593bb59419b63a2c495694a7f9780010ff1d7de5;hb=a737a50df4004443459e818e1e463141ef246280;hp=b53aee42ead27d9237509a030d654daef7db4d41;hpb=fd091d66e2673b19eb9c7d73d95160ef874de5e6;p=xonotic%2Fdarkplaces.git diff --git a/image_png.c b/image_png.c index b53aee42..593bb594 100644 --- a/image_png.c +++ b/image_png.c @@ -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; @@ -346,12 +340,21 @@ unsigned char *PNG_LoadImage_BGRA (const unsigned char *raw, int filesize) qpng_read_image(png, my_png.FRowPtrs); } else - Con_DPrintf("PNG_LoadImage : not enough memory\n"); + { + Con_Printf("PNG_LoadImage : not enough memory\n"); + qpng_destroy_read_struct(&png, &pnginfo, 0); + Mem_Free(my_png.FRowPtrs); + return NULL; + } Mem_Free(my_png.FRowPtrs); my_png.FRowPtrs = NULL; } else - Con_DPrintf("PNG_LoadImage : not enough memory\n"); + { + Con_Printf("PNG_LoadImage : not enough memory\n"); + qpng_destroy_read_struct(&png, &pnginfo, 0); + return NULL; + } qpng_read_end(png, pnginfo); qpng_destroy_read_struct(&png, &pnginfo, 0); @@ -363,7 +366,15 @@ unsigned char *PNG_LoadImage_BGRA (const unsigned char *raw, int filesize) { Con_Printf ("PNG_LoadImage : bad color depth\n"); Mem_Free(imagedata); - imagedata = NULL; + return 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;