X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fq3map2%2Fimage.c;h=c947085445def14e171f98983fe357a4213d11f5;hb=29f82a6d407b065749aa77b470a7f95b9a04e3ab;hp=4fb3f74e618b8efe731015d64df7e0f4c97557a4;hpb=75403940937c9ed569f870e03094e7a7297d0d75;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3map2/image.c b/tools/quake3/q3map2/image.c index 4fb3f74e..c9470854 100644 --- a/tools/quake3/q3map2/image.c +++ b/tools/quake3/q3map2/image.c @@ -36,7 +36,7 @@ /* dependencies */ #include "q3map2.h" - +#include "webp/decode.h" /* ------------------------------------------------------------------------------- @@ -248,6 +248,34 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in +static void LoadWEBPBuffer( byte *buffer, int size, byte **pixels, int *width, int *height ){ + + int image_width; + int image_height; + + if ( !WebPGetInfo( buffer, ( size_t) size, &image_width, &image_height ) ) + { + Sys_Printf( "WARNING: An error occurred reading WEBP image info\n" ); + return; + } + + /* create image pixel buffer */ + *pixels = safe_malloc( image_width * image_height * 4 ); + *width = image_width; + *height = image_height; + + int out_stride = image_width * 4; + int out_size = image_height * out_stride; + + if ( !WebPDecodeRGBAInto( buffer, (size_t) size, *pixels, out_size, out_stride ) ) + { + Sys_FPrintf( SYS_WRN, "WARNING: An error occurred reading WEBP image\n" ); + return; + } +} + + + /* ImageInit() implicitly called by every function to set up image list @@ -472,6 +500,15 @@ image_t *ImageLoad( const char *filename ){ break; } #endif // BUILD_CRUNCH + + /* attempt to load webp */ + StripExtension( name ); + strcat( name, ".webp" ); + size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); + if ( size > 0 ) { + LoadWEBPBuffer( buffer, size, &image->pixels, &image->width, &image->height ); + break; + } } while (qfalse); /* free file buffer */