/* 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;
}
image->name = safe_malloc( strlen( name ) + 1 );
strcpy( image->name, name );
- do {
- /* attempt to load tga */
- StripExtension( name );
- strcat( name, ".tga" );
- size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
- if ( size > 0 ) {
- LoadTGABuffer( buffer, buffer + size, &image->pixels, &image->width, &image->height );
- break;
- }
+ /* attempt to load tga */
+ StripExtension( name );
+ strcat( name, ".tga" );
+ size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+ if ( size > 0 ) {
+ LoadTGABuffer( buffer, buffer + size, &image->pixels, &image->width, &image->height );
+ goto image_load_success;
+ }
- /* attempt to load png */
- StripExtension( name );
- strcat( name, ".png" );
- size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
- if ( size > 0 ) {
- LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height );
- break;
- }
+ /* attempt to load png */
+ StripExtension( name );
+ strcat( name, ".png" );
+ size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+ if ( size > 0 ) {
+ LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height );
+ goto image_load_success;
+ }
- /* attempt to load jpg */
- StripExtension( name );
- strcat( name, ".jpg" );
- size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
- if ( size > 0 ) {
- if ( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL ) {
- // On error, LoadJPGBuff might store a pointer to the error message in image->pixels
- Sys_FPrintf( SYS_WRN, "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
- }
- alphaHack = qtrue;
- break;
+ /* attempt to load jpg */
+ StripExtension( name );
+ strcat( name, ".jpg" );
+ size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+ if ( size > 0 ) {
+ if ( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL ) {
+ // On error, LoadJPGBuff might store a pointer to the error message in image->pixels
+ Sys_FPrintf( SYS_WRN, "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
}
+ alphaHack = qtrue;
+ goto image_load_success;
+ }
+
+ /* attempt to load dds */
+ StripExtension( name );
+ strcat( name, ".dds" );
+ size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
- /* attempt to load dds */
+ /* 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;
- }
+ }
- /* attempt to load ktx */
- StripExtension( name );
- strcat( name, ".ktx" );
- size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
- if ( size > 0 ) {
- LoadKTXBufferFirstImage( buffer, size, &image->pixels, &image->width, &image->height );
- break;
- }
+ if ( size > 0 ) {
+ LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height );
+ goto image_load_success;
+ }
- #ifdef BUILD_CRUNCH
- /* attempt to load crn */
- StripExtension( name );
- strcat( name, ".crn" );
- size = vfsLoadFile( ( const char* ) name, ( void** ) &buffer, 0 );
- if ( size > 0 ) {
- LoadCRNBuffer( buffer, size, &image->pixels, &image->width, &image->height );
- break;
- }
- #endif // BUILD_CRUNCH
+ /* attempt to load ktx */
+ StripExtension( name );
+ strcat( name, ".ktx" );
+ size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+ if ( size > 0 ) {
+ LoadKTXBufferFirstImage( buffer, size, &image->pixels, &image->width, &image->height );
+ goto image_load_success;
+ }
- /* 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);
+ #ifdef BUILD_CRUNCH
+ /* attempt to load crn */
+ StripExtension( name );
+ strcat( name, ".crn" );
+ size = vfsLoadFile( ( const char* ) name, ( void** ) &buffer, 0 );
+ if ( size > 0 ) {
+ LoadCRNBuffer( buffer, size, &image->pixels, &image->width, &image->height );
+ goto image_load_success;
+ }
+ #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 );
+ goto image_load_success;
+ }
+
+ image_load_success:
+
+ /* tell user which image file is found for the given texture path */
+ Sys_FPrintf( SYS_VRB, "Loaded image: \"%s\"\n", name );
/* free file buffer */
free( buffer );