/* 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* ) );
/* clean up */
free( rowPointers );
png_destroy_read_struct( &png, &info, &end );
-
}
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;
}
return NULL;
}
- /* strip file extension off name */
- strcpy( name, filename );
- StripExtension( name );
+ /* try with extension then without extension
+ so light.blend will be unfortunately first
+ tried as light.tga like it always did, but
+ then, light.blend.tga will be tried as well */
+ for ( i = 0; i < 2; i++ )
+ {
+ strcpy( name, filename );
- /* try to find existing image */
- image = ImageFind( name );
- if ( image != NULL ) {
- image->refCount++;
- return image;
- }
+ if ( i == 0 )
+ {
+ /* strip file extension off name */
+ StripExtension( name );
+ }
- /* none found, so find first non-null image */
- image = NULL;
- for ( i = 0; i < MAX_IMAGES; i++ )
- {
- if ( images[ i ].name == NULL ) {
- image = &images[ i ];
- break;
+ /* try to find existing image */
+ image = ImageFind( name );
+ if ( image != NULL ) {
+ image->refCount++;
+ return image;
}
- }
- /* too many images? */
- if ( image == NULL ) {
- Error( "MAX_IMAGES (%d) exceeded, there are too many image files referenced by the map.", MAX_IMAGES );
- }
+ /* none found, so find first non-null image */
+ image = NULL;
+ for ( i = 0; i < MAX_IMAGES; i++ )
+ {
+ if ( images[ i ].name == NULL ) {
+ image = &images[ i ];
+ break;
+ }
+ }
+
+ /* too many images? */
+ if ( image == NULL ) {
+ Error( "MAX_IMAGES (%d) exceeded, there are too many image files referenced by the map.", MAX_IMAGES );
+ }
- /* set it up */
- image->name = safe_malloc( strlen( name ) + 1 );
- strcpy( image->name, name );
+ /* set it up */
+ image->name = safe_malloc( strlen( name ) + 1 );
+ strcpy( image->name, name );
+
+ /* add a dummy extension that can be removed */
+ strcat( name, ".tga" );
+
+ /* Sys_FPrintf( SYS_WRN, "==> Looking for %s\n", name ); */
- do {
/* attempt to load tga */
StripExtension( name );
strcat( name, ".tga" );
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 );
-
- /* debug code */
- #if 1
- {
- ddsPF_t pf;
- DDSGetInfo( (ddsBuffer_t*) buffer, NULL, NULL, &pf );
- Sys_Printf( "pf = %d\n", pf );
- if ( image->width > 0 ) {
- StripExtension( name );
- strcat( name, "_converted.tga" );
- WriteTGA( "C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width, image->height );
- }
- }
- #endif // debug
break;
}
LoadWEBPBuffer( buffer, size, &image->pixels, &image->width, &image->height );
break;
}
- } while (qfalse);
+ }
/* free file buffer */
free( buffer );
/* make sure everything's kosher */
if ( size <= 0 || image->width <= 0 || image->height <= 0 || image->pixels == NULL ) {
+ // Sys_FPrintf( SYS_WRN, "WARNING: Image not found: \"%s\"\n", filename );
//% Sys_Printf( "size = %d width = %d height = %d pixels = 0x%08x (%s)\n",
//% size, image->width, image->height, image->pixels, name );
free( image->name );
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 );