From 4d276901a6a64a1878865526b347c8e890124994 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 23 Feb 2011 13:22:07 +0100 Subject: [PATCH] also support the alpha channel hack for JPEG that DarkPlaces supports (foo.jpg + foo_alpha.jpg) --- tools/quake3/q3map2/image.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/quake3/q3map2/image.c b/tools/quake3/q3map2/image.c index 0289e77..929b15d 100644 --- a/tools/quake3/q3map2/image.c +++ b/tools/quake3/q3map2/image.c @@ -346,6 +346,7 @@ image_t *ImageLoad( const char *filename ) char name[ 1024 ]; int size; byte *buffer = NULL; + qboolean alphaHack = qfalse; /* init */ @@ -410,6 +411,7 @@ image_t *ImageLoad( const char *filename ) { if( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL ) Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels ); + alphaHack = qtrue; } else { @@ -460,6 +462,28 @@ image_t *ImageLoad( const char *filename ) /* set count */ image->refCount = 1; numImages++; + + if(alphaHack) + { + StripExtension( name ); + strcat( name, "_alpha.jpg" ); + size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 ); + if( size > 0 ) + { + unsigned char *pixels; + int width, height; + if( LoadJPGBuff( buffer, size, &pixels, &width, &height ) == -1 && pixels != NULL ) + Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels ); + if(pixels && width == image->width && height == image->height) + { + int i; + for(i = 0; i < width*height; ++i) + image->pixels[4*i+3] = pixels[4*i+2]; // copy alpha from blue channel + } + free(pixels); + free(buffer); + } + } /* return the image */ return image; -- 2.39.2