Skip to content

Commit

Permalink
Use common schema for image load logs
Browse files Browse the repository at this point in the history
<Image type> image '%s' <log message>
  • Loading branch information
dimhotepus committed Apr 27, 2020
1 parent e916683 commit a9bcd14
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 38 deletions.
21 changes: 11 additions & 10 deletions src/engine/renderer/tr_bsp.cpp
Expand Up @@ -218,7 +218,7 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )

if ( !buffer )
{
Sys::Drop( "LoadRGBE: '%s' not found", name );
Sys::Drop( "RGBE image '%s' is not found", name );
}

buf_p = buffer;
Expand Down Expand Up @@ -257,22 +257,23 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )
}
else
{
Log::Warn("LoadRGBE: Expected 'bit_rle_rgbe' found instead '%s'", token );
Log::Warn("RGBE image '%s' has expected 'bit_rle_rgbe' but found '%s' instead",
name, token );
}
}
else
{
Log::Warn("LoadRGBE: Expected '-' found instead '%s'", token );
Log::Warn("RGBE image '%s' has expected '-' but found '%s' instead", name, token );
}
}
else
{
Log::Warn("LoadRGBE: Expected '32' found instead '%s'", token );
Log::Warn("RGBE image '%s' has expected '32' but found '%s' instead", name, token );
}
}
else
{
Log::Warn("LoadRGBE: Expected '=' found instead '%s'", token );
Log::Warn("RGBE image '%s' has expected '=' but found '%s' instead", name, token );
}
}

Expand All @@ -299,17 +300,17 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )
}
else
{
Log::Warn("LoadRGBE: Expected 'X' found instead '%s'", token );
Log::Warn("RGBE image '%s' has expected 'X' but found '%s' instead", name, token );
}
}
else
{
Log::Warn("LoadRGBE: Expected '+' found instead '%s'", token );
Log::Warn("RGBE image '%s' has expected '+' but found '%s' instead", name, token );
}
}
else
{
Log::Warn("LoadRGBE: Expected 'Y' found instead '%s'", token );
Log::Warn("RGBE image '%s' has expected 'Y' but found '%s' instead", name, token );
}
}
}
Expand All @@ -336,13 +337,13 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )
if ( !formatFound )
{
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadRGBE: %s has no format", name );
Sys::Drop( "RGBE image '%s' has no format", name );
}

if ( !w || !h )
{
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadRGBE: %s has an invalid image size", name );
Sys::Drop( "RGBE image '%s' has an invalid image size", name );
}

*pic = (float*) Com_Allocate( w * h * 3 * sizeof( float ) );
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_image_crn.cpp
Expand Up @@ -128,7 +128,7 @@ void LoadCRN(const char* name, byte **data, int *width, int *height,
ri.Free(*data);
*data = nullptr; // This signals failure.
}
Log::Warn("Invalid CRN image: %s", name);
Log::Warn("CRN image '%s' has an invalid format", name);
}
ri.FS_FreeFile(buff);
}
31 changes: 18 additions & 13 deletions src/engine/renderer/tr_image_dds.cpp
Expand Up @@ -163,7 +163,7 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,

if ( strncmp( ( const char * ) buff, "DDS ", 4 ) != 0 )
{
Log::Warn("R_LoadDDSImage: invalid dds header \"%s\"", name );
Log::Warn("DDS image '%s' has invalid DDS id", name );
return;
}

Expand All @@ -186,15 +186,15 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,

if ( ddsd->dwSize != sizeof( DDSHEADER_t ) || ddsd->ddpfPixelFormat.dwSize != sizeof( DDS_PIXELFORMAT_t ) )
{
Log::Warn("R_LoadDDSImage: invalid dds header \"%s\"", name );
Log::Warn("DDS image '%s' has invalid DDS header", name );
return;
}

*numMips = ( ( ddsd->dwFlags & DDSD_MIPMAPCOUNT ) && ( ddsd->dwMipMapCount > 1 ) ) ? ddsd->dwMipMapCount : 1;

if ( *numMips > MAX_TEXTURE_MIPS )
{
Log::Warn("R_LoadDDSImage: dds image has too many mip levels \"%s\"", name );
Log::Warn("DDS image '%s' has too many mip levels (%d > %d)", name, *numMips, MAX_TEXTURE_MIPS );
return;
}

Expand All @@ -207,7 +207,8 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,

if ( ddsd->dwWidth != ddsd->dwHeight )
{
Log::Warn("R_LoadDDSImage: invalid dds image \"%s\"", name );
Log::Warn("DDS image '%s' is cube map and height (%d) != width (%d)", name,
ddsd->dwWidth, ddsd->dwHeight );
return;
}

Expand All @@ -218,7 +219,7 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
if ( *width & ( *width - 1 ) )
{
//cubes must be a power of two
Log::Warn("R_LoadDDSImage: cube images must be power of two \"%s\"", name );
Log::Warn("DDS image '%s' is cube map and width (%d) is not power of two", name, *width );
return;
}
}
Expand All @@ -232,13 +233,15 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,

if ( *numLayers > MAX_TEXTURE_LAYERS )
{
Log::Warn("R_LoadDDSImage: dds image has too many layers \"%s\"", name );
Log::Warn("DDS image '%s' is volume and has too many layers (%d > %d)", name,
*numLayers, MAX_TEXTURE_LAYERS );
return;
}

if ( *width & ( *width - 1 ) || *height & ( *height - 1 ) || *numLayers & ( *numLayers - 1 ) )
{
Log::Warn("R_LoadDDSImage: volume images must be power of two \"%s\"", name );
Log::Warn("DDS image '%s' is volume and it's values are not power of two: "
"width (%d), height (%d), layers (%d)", name, *width, *height, *numLayers );
return;
}
}
Expand All @@ -254,7 +257,8 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
//except for compressed images!
if ( compressed && ( *width & ( *width - 1 ) || *height & ( *height - 1 ) ) )
{
Log::Warn("R_LoadDDSImage: compressed texture images must be power of two \"%s\"", name );
Log::Warn("DDS image '%s' is 2D compressed texture and it's values are not power of two: "
"width (%d), height (%d)", name, *width, *height );
return;
}
}
Expand All @@ -265,7 +269,7 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,

if ( *numLayers != 0 )
{
Log::Warn("R_LoadDDSImage: compressed volume textures are not supported \"%s\"", name );
Log::Warn("DDS image '%s' is unsupported compressed volume texture", name );
return;
}

Expand Down Expand Up @@ -300,8 +304,8 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
break;

default:
Log::Warn("R_LoadDDSImage: unsupported FOURCC 0x%08x, \"%s\"",
ddsd->ddpfPixelFormat.dwFourCC, name );
Log::Warn("DDS image '%s' is compressed, but FOURCC 0x%08x is unsupported",
name, ddsd->ddpfPixelFormat.dwFourCC );
return;
}
w = *width;
Expand Down Expand Up @@ -329,13 +333,14 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
break;

default:
Log::Warn("R_LoadDDSImage: unsupported RGB bit depth \"%s\"", name );
Log::Warn("DDS image '%s' is not compressed, but RGB bit depth (%d) is unsupported", name,
ddsd->ddpfPixelFormat.dwRGBBitCount );
return;
}
}
else
{
Log::Warn("R_LoadDDSImage: unsupported DDS image type \"%s\"", name );
Log::Warn("DDS image '%s' is not compressed and has unsupported image type", name );
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_image_jpg.cpp
Expand Up @@ -188,7 +188,7 @@ void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height
fclose( jpegfd );
#endif

Sys::Drop( "LoadJPG: %s has an invalid image format: %dx%d*4=%d, components: %d", filename,
Sys::Drop( "JPG image '%s' has an invalid format: %dx%d*4=%d, components: %d", filename,
cinfo.output_width, cinfo.output_height, pixelcount * 4, cinfo.output_components );
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_image_ktx.cpp
Expand Up @@ -136,7 +136,7 @@ bool LoadInMemoryKTX( const char *name, void *ktxData, size_t ktxSize,
auto *hdr{ static_cast<KTX_header_t *>(ktxData) };

if( !IsValidKTXHeader( hdr, ktxSize ) ) {
Log::Warn("KTX image '%s' is not in KTX format", name);
Log::Warn("KTX image '%s' has an invalid format", name);
return false;
}

Expand Down
12 changes: 8 additions & 4 deletions src/engine/renderer/tr_image_png.cpp
Expand Up @@ -78,7 +78,8 @@ void LoadPNG( const char *name, byte **pic, int *width, int *height,

if ( !png )
{
Log::Warn("LoadPNG: png_create_write_struct() failed for (%s)", name );
Log::Warn("PNG image '%s' has failed png_create_write_struct() [libpng v.'%s']",
name, PNG_LIBPNG_VER_STRING );
ri.FS_FreeFile( data );
return;
}
Expand All @@ -88,7 +89,8 @@ void LoadPNG( const char *name, byte **pic, int *width, int *height,

if ( !info )
{
Log::Warn("LoadPNG: png_create_info_struct() failed for (%s)", name );
Log::Warn("PNG image '%s' has failed png_create_info_struct() [libpng v.'%s']",
name, PNG_LIBPNG_VER_STRING );
ri.FS_FreeFile( data );
png_destroy_read_struct( &png, ( png_infopp ) nullptr, ( png_infopp ) nullptr );
return;
Expand All @@ -102,7 +104,8 @@ void LoadPNG( const char *name, byte **pic, int *width, int *height,
if ( setjmp( png_jmpbuf( png ) ) )
{
// if we get here, we had a problem reading the file
Log::Warn("LoadPNG: first exception handler called for (%s)", name );
Log::Warn("PNG image '%s' has first exception handler called [libpng v.'%s']",
name, PNG_LIBPNG_VER_STRING );
ri.FS_FreeFile( data );
png_destroy_read_struct( &png, ( png_infopp ) & info, ( png_infopp ) nullptr );
return;
Expand Down Expand Up @@ -170,7 +173,8 @@ void LoadPNG( const char *name, byte **pic, int *width, int *height,
// set a new exception handler
if ( setjmp( png_jmpbuf( png ) ) )
{
Log::Warn("LoadPNG: second exception handler called for (%s)", name );
Log::Warn("PNG image '%s' has second exception handler called [libpng v.'%s']",
name, PNG_LIBPNG_VER_STRING );
ri.Hunk_FreeTempMemory( row_pointers );
ri.FS_FreeFile( data );
png_destroy_read_struct( &png, ( png_infopp ) & info, ( png_infopp ) nullptr );
Expand Down
17 changes: 10 additions & 7 deletions src/engine/renderer/tr_image_tga.cpp
Expand Up @@ -76,19 +76,22 @@ void LoadTGA( const char *name, byte **pic, int *width, int *height,
if ( targa_header.image_type != 2 && targa_header.image_type != 10 && targa_header.image_type != 3 )
{
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadTGA: Only type 2 (RGB), 3 (gray), and 10 (RGB) TGA images supported (%s)", name );
Sys::Drop( "TGA image '%s' has unsupported image type (%d). "
"Only type 2 (uncompressed RGB), 3 (gray), and 10 (compressed RGB) TGA images supported",
name, targa_header.image_type );
}

if ( targa_header.colormap_type != 0 )
{
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadTGA: colormaps not supported (%s)", name );
Sys::Drop( "TGA image '%s' has color map and not supported", name );
}

if ( ( targa_header.pixel_size != 32 && targa_header.pixel_size != 24 ) && targa_header.image_type != 3 )
{
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadTGA: Only 32 or 24 bit images supported (no colormaps) (%s)", name );
Sys::Drop( "TGA image '%s' has unsupported pixel size (%d). "
"Only 32 or 24 bit images supported (except gray ones)", name, targa_header.pixel_size );
}

columns = targa_header.width;
Expand All @@ -108,7 +111,7 @@ void LoadTGA( const char *name, byte **pic, int *width, int *height,
if ( !columns || !rows || numPixels > 0x7FFFFFFF || numPixels / columns / 4 != rows )
{
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadTGA: %s has an invalid image size", name );
Sys::Drop( "TGA image '%s' has an invalid image size", name );
}

targa_rgba = (byte*) ri.Z_Malloc( numPixels );
Expand Down Expand Up @@ -167,7 +170,7 @@ void LoadTGA( const char *name, byte **pic, int *width, int *height,
default:
ri.Free( targa_rgba );
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadTGA: illegal pixel_size '%d' in file '%s'", targa_header.pixel_size, name );
Sys::Drop( "TGA image '%s' has illegal pixel_size (%d)", name, targa_header.pixel_size );
}
}
}
Expand Down Expand Up @@ -213,7 +216,7 @@ void LoadTGA( const char *name, byte **pic, int *width, int *height,
default:
ri.Free( targa_rgba );
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadTGA: illegal pixel_size '%d' in file '%s'", targa_header.pixel_size, name );
Sys::Drop( "TGA image '%s' has illegal pixel_size (%d)", name, targa_header.pixel_size );
}

for ( j = 0; j < packetSize; j++ )
Expand Down Expand Up @@ -273,7 +276,7 @@ void LoadTGA( const char *name, byte **pic, int *width, int *height,
default:
ri.Free( targa_rgba );
ri.FS_FreeFile( buffer );
Sys::Drop( "LoadTGA: illegal pixel_size '%d' in file '%s'", targa_header.pixel_size, name );
Sys::Drop( "TGA image '%s' has illegal pixel_size (%d)", name, targa_header.pixel_size );
}

column++;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_image_webp.cpp
Expand Up @@ -29,7 +29,7 @@ bool LoadInMemoryWEBP( const char *path, const uint8_t* webpData, size_t webpSiz
// Validate data and query image size.
if ( !WebPGetInfo( webpData, webpSize, width, height ) )
{
Log::Warn( "WebP image '%s' is not in WebP format", path );
Log::Warn( "WebP image '%s' has an invalid format", path );
return false;
}

Expand Down

0 comments on commit a9bcd14

Please sign in to comment.