mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-04-24 10:38:53 +00:00
Moved makeImageHeader to Image_intrinsic.cpp
This commit is contained in:
parent
e51b41cc66
commit
cd6c804508
2 changed files with 89 additions and 86 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
Doom 3 BFG Edition GPL Source Code
|
||||
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
||||
Copyright (C) 2013-2021 Robert Beckebans
|
||||
Copyright (C) 2013-2023 Robert Beckebans
|
||||
Copyright (C) 2022 Stephen Pridham
|
||||
|
||||
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
||||
|
@ -1148,3 +1148,91 @@ void idImageManager::CreateIntrinsicImages()
|
|||
release_assert( loadingIconImage->referencedOutsideLevelLoad );
|
||||
release_assert( hellLoadingIconImage->referencedOutsideLevelLoad );
|
||||
}
|
||||
|
||||
|
||||
CONSOLE_COMMAND( makeImageHeader, "load an image and turn it into a .h file", NULL )
|
||||
{
|
||||
byte* buffer;
|
||||
int width = 0, height = 0;
|
||||
|
||||
if( args.Argc() < 2 )
|
||||
{
|
||||
common->Printf( "USAGE: makeImageHeader filename [exportname]\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
idStr filename = args.Argv( 1 );
|
||||
|
||||
R_LoadImage( filename, &buffer, &width, &height, NULL, true, NULL );
|
||||
if( !buffer )
|
||||
{
|
||||
common->Printf( "loading %s failed.\n", filename.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
filename.StripFileExtension();
|
||||
|
||||
idStr exportname;
|
||||
|
||||
if( args.Argc() == 3 )
|
||||
{
|
||||
exportname.Format( "Image_%s.h", args.Argv( 2 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
exportname.Format( "Image_%s.h", filename.c_str() );
|
||||
}
|
||||
|
||||
for( int i = 0; i < exportname.Length(); i++ )
|
||||
{
|
||||
if( exportname[ i ] == '/' )
|
||||
{
|
||||
exportname[ i ] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
idFileLocal headerFile( fileSystem->OpenFileWrite( exportname, "fs_basepath" ) );
|
||||
|
||||
idStr uppername = exportname;
|
||||
uppername.ToUpper();
|
||||
|
||||
for( int i = 0; i < uppername.Length(); i++ )
|
||||
{
|
||||
if( uppername[ i ] == '.' )
|
||||
{
|
||||
uppername[ i ] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
headerFile->Printf( "#ifndef %s_TEX_H\n", uppername.c_str() );
|
||||
headerFile->Printf( "#define %s_TEX_H\n\n", uppername.c_str() );
|
||||
|
||||
headerFile->Printf( "#define %s_TEX_WIDTH %i\n", uppername.c_str(), width );
|
||||
headerFile->Printf( "#define %s_TEX_HEIGHT %i\n\n", uppername.c_str(), height );
|
||||
|
||||
headerFile->Printf( "static const unsigned char %s_Bytes[] = {\n", uppername.c_str() );
|
||||
|
||||
int bufferSize = width * height * 4;
|
||||
|
||||
for( int i = 0; i < bufferSize; i++ )
|
||||
{
|
||||
byte b = buffer[i];
|
||||
|
||||
if( i < ( bufferSize - 1 ) )
|
||||
{
|
||||
headerFile->Printf( "0x%02hhx, ", b );
|
||||
}
|
||||
else
|
||||
{
|
||||
headerFile->Printf( "0x%02hhx", b );
|
||||
}
|
||||
|
||||
if( i % 12 == 0 )
|
||||
{
|
||||
headerFile->Printf( "\n" );
|
||||
}
|
||||
}
|
||||
headerFile->Printf( "\n};\n#endif\n" );
|
||||
|
||||
Mem_Free( buffer );
|
||||
}
|
|
@ -1264,89 +1264,4 @@ static const unsigned char brfLutTexBytes[] =
|
|||
Mem_Free( hdrBuffer );
|
||||
}
|
||||
|
||||
CONSOLE_COMMAND( makeImageHeader, "load an image and turn it into a .h file", NULL )
|
||||
{
|
||||
byte* buffer;
|
||||
int width = 0, height = 0;
|
||||
|
||||
if( args.Argc() < 2 )
|
||||
{
|
||||
common->Printf( "USAGE: makeImageHeader filename [exportname]\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
idStr filename = args.Argv( 1 );
|
||||
|
||||
R_LoadImage( filename, &buffer, &width, &height, NULL, true, NULL );
|
||||
if( !buffer )
|
||||
{
|
||||
common->Printf( "loading %s failed.\n", filename.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
filename.StripFileExtension();
|
||||
|
||||
idStr exportname;
|
||||
|
||||
if( args.Argc() == 3 )
|
||||
{
|
||||
exportname.Format( "Image_%s.h", args.Argv( 2 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
exportname.Format( "Image_%s.h", filename.c_str() );
|
||||
}
|
||||
|
||||
for( int i = 0; i < exportname.Length(); i++ )
|
||||
{
|
||||
if( exportname[ i ] == '/' )
|
||||
{
|
||||
exportname[ i ] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
idFileLocal headerFile( fileSystem->OpenFileWrite( exportname, "fs_basepath" ) );
|
||||
|
||||
idStr uppername = exportname;
|
||||
uppername.ToUpper();
|
||||
|
||||
for( int i = 0; i < uppername.Length(); i++ )
|
||||
{
|
||||
if( uppername[ i ] == '.' )
|
||||
{
|
||||
uppername[ i ] = '_';
|
||||
}
|
||||
}
|
||||
|
||||
headerFile->Printf( "#ifndef %s_TEX_H\n", uppername.c_str() );
|
||||
headerFile->Printf( "#define %s_TEX_H\n\n", uppername.c_str() );
|
||||
|
||||
headerFile->Printf( "#define %s_TEX_WIDTH %i\n", uppername.c_str(), width );
|
||||
headerFile->Printf( "#define %s_TEX_HEIGHT %i\n\n", uppername.c_str(), height );
|
||||
|
||||
headerFile->Printf( "static const unsigned char %s_Bytes[] = {\n", uppername.c_str() );
|
||||
|
||||
int bufferSize = width * height * 4;
|
||||
|
||||
for( int i = 0; i < bufferSize; i++ )
|
||||
{
|
||||
byte b = buffer[i];
|
||||
|
||||
if( i < ( bufferSize - 1 ) )
|
||||
{
|
||||
headerFile->Printf( "0x%02hhx, ", b );
|
||||
}
|
||||
else
|
||||
{
|
||||
headerFile->Printf( "0x%02hhx", b );
|
||||
}
|
||||
|
||||
if( i % 12 == 0 )
|
||||
{
|
||||
headerFile->Printf( "\n" );
|
||||
}
|
||||
}
|
||||
headerFile->Printf( "\n};\n#endif\n" );
|
||||
|
||||
Mem_Free( buffer );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue