]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/image.c
more warnings be gone
[xonotic/netradiant.git] / tools / quake3 / q3map2 / image.c
index 0ddcaf86bc59e556fa7d3e2cb5127a95dfdf1b00..7ce08aaaf88e5e3d621bf3b3e757f53e7e7f3546 100644 (file)
@@ -99,7 +99,7 @@ note: this function is a total hack, as it reads/writes the png struct directly!
 typedef struct pngBuffer_s
 {
        byte    *buffer;
-       int             size, offset;
+       png_size_t              size, offset;
 }
 pngBuffer_t;
 
@@ -127,8 +127,8 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in
        png_struct      *png;
        png_info        *info, *end;
        pngBuffer_t     pb;
-       int                     i, bitDepth, colorType, channels;
-       png_uint_32     w, h;
+       int                     bitDepth, colorType;
+       png_uint_32     w, h, i;
        byte            **rowPointers;
        
        
@@ -196,9 +196,6 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in
        png_get_IHDR( png, info,
                &w, &h, &bitDepth, &colorType, NULL, NULL, NULL );
        
-       /* read number of channels */
-       channels = png_get_channels( png, info );
-       
        /* the following will probably bork on certain types of png images, but hey... */
 
        /* force indexed/gray/trans chunk to rgb */
@@ -346,6 +343,7 @@ image_t *ImageLoad( const char *filename )
        char            name[ 1024 ];
        int                     size;
        byte            *buffer = NULL;
+       qboolean        alphaHack = qfalse;
 
        
        /* init */
@@ -410,6 +408,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 +459,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;