]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/image.c
q3map2: dds/ prefix, print log at the right time, when image is found
[xonotic/netradiant.git] / tools / quake3 / q3map2 / image.c
index 91f4aae93ada5b7eba79eb5bc989daf51c87f182..20ad90ff99d59350b5b58cf34982c7bea2ec5220 100644 (file)
@@ -230,7 +230,8 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in
        /* create image pixel buffer */
        *width = w;
        *height = h;
-       *pixels = safe_malloc( w * h * 4 );
+       /* initialize with zeros, this memory area may not be entirely rewritten */
+       *pixels = safe_malloc0( w * h * 4 );
 
        /* create row pointers */
        rowPointers = safe_malloc( h * sizeof( byte* ) );
@@ -243,7 +244,6 @@ static void LoadPNGBuffer( byte *buffer, int size, byte **pixels, int *width, in
        /* clean up */
        free( rowPointers );
        png_destroy_read_struct( &png, &info, &end );
-
 }
 
 
@@ -255,7 +255,7 @@ static void LoadWEBPBuffer( byte *buffer, int size, byte **pixels, int *width, i
        
        if ( !WebPGetInfo( buffer, ( size_t) size, &image_width, &image_height ) )
        {
-               Sys_Printf( "WARNING: An error occurred reading WEBP image info\n" );
+               Sys_FPrintf( SYS_WRN, "WARNING: An error occurred reading WEBP image info\n" );
                return;
        }
 
@@ -461,6 +461,16 @@ image_t *ImageLoad( const char *filename ){
        StripExtension( name );
        strcat( name, ".dds" );
        size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+
+       /* also look for .dds image in dds/ prefix like Doom3 or DarkPlaces */
+       if ( size <= 0 ) {
+               strcpy( name, "dds/" );
+               strcat( name, image->name );
+               StripExtension( name );
+               strcat( name, ".dds" );
+               size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+       }
+
        if ( size > 0 ) {
                LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height );
                goto image_load_success;
@@ -509,6 +519,9 @@ image_t *ImageLoad( const char *filename ){
                return NULL;
        }
 
+       /* tell user which image file is found for the given texture path */
+       Sys_FPrintf( SYS_VRB, "Loaded image: \"%s\"\n", name );
+
        /* set filename */
        image->filename = safe_malloc( strlen( name ) + 1 );
        strcpy( image->filename, name );