Skip to content

Commit 0b93b9e

Browse files
authored
Merge pull request #335 from dimhotepus/fix_ktx_format_support
Fix KTX file format support and unify image reader logs
2 parents 393e182 + 9df5869 commit 0b93b9e

9 files changed

+375
-237
lines changed

src/engine/renderer/tr_bsp.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )
218218

219219
if ( !buffer )
220220
{
221-
Sys::Drop( "LoadRGBE: '%s' not found", name );
221+
Sys::Drop( "RGBE image '%s' is not found", name );
222222
}
223223

224224
buf_p = buffer;
@@ -257,22 +257,23 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )
257257
}
258258
else
259259
{
260-
Log::Warn("LoadRGBE: Expected 'bit_rle_rgbe' found instead '%s'", token );
260+
Log::Warn("RGBE image '%s' has expected 'bit_rle_rgbe' but found '%s' instead",
261+
name, token );
261262
}
262263
}
263264
else
264265
{
265-
Log::Warn("LoadRGBE: Expected '-' found instead '%s'", token );
266+
Log::Warn("RGBE image '%s' has expected '-' but found '%s' instead", name, token );
266267
}
267268
}
268269
else
269270
{
270-
Log::Warn("LoadRGBE: Expected '32' found instead '%s'", token );
271+
Log::Warn("RGBE image '%s' has expected '32' but found '%s' instead", name, token );
271272
}
272273
}
273274
else
274275
{
275-
Log::Warn("LoadRGBE: Expected '=' found instead '%s'", token );
276+
Log::Warn("RGBE image '%s' has expected '=' but found '%s' instead", name, token );
276277
}
277278
}
278279

@@ -299,17 +300,17 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )
299300
}
300301
else
301302
{
302-
Log::Warn("LoadRGBE: Expected 'X' found instead '%s'", token );
303+
Log::Warn("RGBE image '%s' has expected 'X' but found '%s' instead", name, token );
303304
}
304305
}
305306
else
306307
{
307-
Log::Warn("LoadRGBE: Expected '+' found instead '%s'", token );
308+
Log::Warn("RGBE image '%s' has expected '+' but found '%s' instead", name, token );
308309
}
309310
}
310311
else
311312
{
312-
Log::Warn("LoadRGBE: Expected 'Y' found instead '%s'", token );
313+
Log::Warn("RGBE image '%s' has expected 'Y' but found '%s' instead", name, token );
313314
}
314315
}
315316
}
@@ -336,13 +337,13 @@ void LoadRGBEToFloats( const char *name, float **pic, int *width, int *height )
336337
if ( !formatFound )
337338
{
338339
ri.FS_FreeFile( buffer );
339-
Sys::Drop( "LoadRGBE: %s has no format", name );
340+
Sys::Drop( "RGBE image '%s' has no format", name );
340341
}
341342

342343
if ( !w || !h )
343344
{
344345
ri.FS_FreeFile( buffer );
345-
Sys::Drop( "LoadRGBE: %s has an invalid image size", name );
346+
Sys::Drop( "RGBE image '%s' has an invalid image size", name );
346347
}
347348

348349
*pic = (float*) Com_Allocate( w * h * 3 * sizeof( float ) );

src/engine/renderer/tr_image.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,14 +1390,10 @@ image_t *R_AllocImage( const char *name, bool linkIntoHashTable )
13901390
static void R_ExportTexture( image_t *image )
13911391
{
13921392
char path[ 1024 ];
1393-
int i;
1394-
1395-
1396-
Com_sprintf( path, sizeof( path ), "texexp/%s.ktx",
1397-
image->name );
1393+
Com_sprintf( path, sizeof( path ), "texexp/%s.ktx", image->name );
13981394

13991395
// quick and dirty sanitize path name
1400-
for( i = strlen( path ) - 1; i >= 7; i-- ) {
1396+
for( size_t i = strlen( path ) - 1; i >= 7; i-- ) {
14011397
if( !Str::cisalnum( path[ i ] ) && path[ i ] != '.' && path[ i ] != '-' ) {
14021398
path[ i ] = 'z';
14031399
}

src/engine/renderer/tr_image_crn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void LoadCRN(const char* name, byte **data, int *width, int *height,
128128
ri.Free(*data);
129129
*data = nullptr; // This signals failure.
130130
}
131-
Log::Warn("Invalid CRN image: %s", name);
131+
Log::Warn("CRN image '%s' has an invalid format", name);
132132
}
133133
ri.FS_FreeFile(buff);
134134
}

src/engine/renderer/tr_image_dds.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
163163

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

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

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

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

195195
if ( *numMips > MAX_TEXTURE_MIPS )
196196
{
197-
Log::Warn("R_LoadDDSImage: dds image has too many mip levels \"%s\"", name );
197+
Log::Warn("DDS image '%s' has too many mip levels (%d > %d)", name, *numMips, MAX_TEXTURE_MIPS );
198198
return;
199199
}
200200

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

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

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

233234
if ( *numLayers > MAX_TEXTURE_LAYERS )
234235
{
235-
Log::Warn("R_LoadDDSImage: dds image has too many layers \"%s\"", name );
236+
Log::Warn("DDS image '%s' is volume and has too many layers (%d > %d)", name,
237+
*numLayers, MAX_TEXTURE_LAYERS );
236238
return;
237239
}
238240

239241
if ( *width & ( *width - 1 ) || *height & ( *height - 1 ) || *numLayers & ( *numLayers - 1 ) )
240242
{
241-
Log::Warn("R_LoadDDSImage: volume images must be power of two \"%s\"", name );
243+
Log::Warn("DDS image '%s' is volume and it's values are not power of two: "
244+
"width (%d), height (%d), layers (%d)", name, *width, *height, *numLayers );
242245
return;
243246
}
244247
}
@@ -254,7 +257,8 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
254257
//except for compressed images!
255258
if ( compressed && ( *width & ( *width - 1 ) || *height & ( *height - 1 ) ) )
256259
{
257-
Log::Warn("R_LoadDDSImage: compressed texture images must be power of two \"%s\"", name );
260+
Log::Warn("DDS image '%s' is 2D compressed texture and it's values are not power of two: "
261+
"width (%d), height (%d)", name, *width, *height );
258262
return;
259263
}
260264
}
@@ -265,7 +269,7 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
265269

266270
if ( *numLayers != 0 )
267271
{
268-
Log::Warn("R_LoadDDSImage: compressed volume textures are not supported \"%s\"", name );
272+
Log::Warn("DDS image '%s' is unsupported compressed volume texture", name );
269273
return;
270274
}
271275

@@ -300,8 +304,8 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
300304
break;
301305

302306
default:
303-
Log::Warn("R_LoadDDSImage: unsupported FOURCC 0x%08x, \"%s\"",
304-
ddsd->ddpfPixelFormat.dwFourCC, name );
307+
Log::Warn("DDS image '%s' is compressed, but FOURCC 0x%08x is unsupported",
308+
name, ddsd->ddpfPixelFormat.dwFourCC );
305309
return;
306310
}
307311
w = *width;
@@ -329,13 +333,14 @@ void R_LoadDDSImageData( void *pImageData, const char *name, byte **data,
329333
break;
330334

331335
default:
332-
Log::Warn("R_LoadDDSImage: unsupported RGB bit depth \"%s\"", name );
336+
Log::Warn("DDS image '%s' is not compressed, but RGB bit depth (%d) is unsupported", name,
337+
ddsd->ddpfPixelFormat.dwRGBBitCount );
333338
return;
334339
}
335340
}
336341
else
337342
{
338-
Log::Warn("R_LoadDDSImage: unsupported DDS image type \"%s\"", name );
343+
Log::Warn("DDS image '%s' is not compressed and has unsupported image type", name );
339344
return;
340345
}
341346
}

src/engine/renderer/tr_image_jpg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height
188188
fclose( jpegfd );
189189
#endif
190190

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

0 commit comments

Comments
 (0)