mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-20 04:34:48 +00:00
Bug fixes:
Generating image previews of image assets was failing DDS remove redundant check for stream status. STB requires the file to be free before being written to, move check to make sure we can open the path into gBitmap and remove FileStream checks from everywhere else.
This commit is contained in:
parent
0b451aa7b5
commit
63682c43ec
|
|
@ -568,12 +568,14 @@ void DDSFile::SurfaceData::dumpImage(DDSFile *dds, U32 mip, const char *file)
|
|||
|
||||
FileStream stream;
|
||||
|
||||
stream.open( file, Torque::FS::File::Write );
|
||||
|
||||
if ( stream.getStatus() == Stream::Ok )
|
||||
if (!stream.open(file, Torque::FS::File::Write))
|
||||
{
|
||||
// Write it out.
|
||||
foo->writeBitmap("png", file);
|
||||
Con::errorf("DDSFile::SurfaceData::dumpImage() - Error opening file for writing: %s !", file);
|
||||
}
|
||||
|
||||
if(!foo->writeBitmap("png", file))
|
||||
{
|
||||
Con::errorf("DDSFile::SurfaceData::dumpImage() - Error writing %s !", file);
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
|
|
|
|||
|
|
@ -1208,6 +1208,17 @@ bool GBitmap::readBitmap(const String& bmType, const Torque::Path& path)
|
|||
|
||||
bool GBitmap::writeBitmap( const String &bmType, const Torque::Path& path, U32 compressionLevel )
|
||||
{
|
||||
FileStream stream;
|
||||
if (!stream.open(path, Torque::FS::File::Write))
|
||||
{
|
||||
Con::errorf("GBitmap::writeBitmap failed to open path %s", path);
|
||||
stream.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
// free file for stb
|
||||
stream.close();
|
||||
|
||||
const GBitmap::Registration *regInfo = GBitmap::sFindRegInfo( bmType );
|
||||
|
||||
if ( regInfo == NULL )
|
||||
|
|
@ -1431,21 +1442,14 @@ DefineEngineFunction(saveScaledImage, bool, (const char* bitmapSource, const cha
|
|||
Torque::Path destinationPath = Torque::Path(bitmapDest);
|
||||
destinationPath.setExtension("png");
|
||||
|
||||
// Open up the file on disk.
|
||||
FileStream fs;
|
||||
if (!fs.open(destinationPath.getFullPath(), Torque::FS::File::Write))
|
||||
if(!image->writeBitmap("png", destinationPath.getFullPath()))
|
||||
{
|
||||
Con::errorf("saveScaledImage() - Failed to open output file '%s'!", bitmapDest);
|
||||
Con::errorf("saveScaledImage() - Error writing %s !", bitmapDest);
|
||||
delete image;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
image->writeBitmap("png", destinationPath.getFullPath());
|
||||
|
||||
fs.close();
|
||||
delete image;
|
||||
}
|
||||
|
||||
|
||||
delete image;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,13 @@
|
|||
#define STBIWDEF static inline
|
||||
#endif
|
||||
|
||||
#ifndef STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_STATIC
|
||||
#include "stb_image.h"
|
||||
#endif
|
||||
|
||||
#ifndef STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_STATIC
|
||||
#include "stb_image_write.h"
|
||||
#endif
|
||||
|
||||
static bool sReadSTB(const Torque::Path& path, GBitmap* bitmap);
|
||||
static bool sWriteSTB(const Torque::Path& path, GBitmap* bitmap, U32 compressionLevel);
|
||||
|
|
@ -89,9 +85,9 @@ bool sReadSTB(const Torque::Path& path, GBitmap* bitmap)
|
|||
return false;
|
||||
}
|
||||
|
||||
// do this to map one channel to 3 and 2 channels to 4
|
||||
if (channels == 2)
|
||||
channels = 4;
|
||||
//// do this to map one channel to 3 and 2 channels to 4
|
||||
//if (channels == 2)
|
||||
// channels = 4;
|
||||
|
||||
if (stbi_is_16_bit(path.getFullPath().c_str()))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -869,17 +869,6 @@ void GFont::exportStrip(const char *fileName, U32 padding, U32 kerning)
|
|||
// Advance.
|
||||
curWidth += mCharInfoList[i].width + kerning + 2*padding;
|
||||
}
|
||||
|
||||
// Write the image!
|
||||
FileStream fs;
|
||||
|
||||
fs.open( fileName, Torque::FS::File::Write );
|
||||
|
||||
if(fs.getStatus() != Stream::Ok)
|
||||
{
|
||||
Con::errorf("GFont::exportStrip - failed to open '%s' for writing.", fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
// Done!
|
||||
gb.writeBitmap("png", fileName);
|
||||
|
|
|
|||
|
|
@ -246,10 +246,6 @@ U32 GFXTextureObject::getEstimatedSizeInBytes() const
|
|||
|
||||
bool GFXTextureObject::dumpToDisk( const String &bmType, const String &path )
|
||||
{
|
||||
FileStream stream;
|
||||
if ( !stream.open( path, Torque::FS::File::Write ) )
|
||||
return false;
|
||||
|
||||
if ( mBitmap )
|
||||
return mBitmap->writeBitmap( bmType, path);
|
||||
|
||||
|
|
|
|||
|
|
@ -234,20 +234,11 @@ void ScreenShot::_singleCapture( GuiCanvas *canvas )
|
|||
char filename[256];
|
||||
dSprintf( filename, 256, "%s.%s", mFilename, mWriteJPG ? "jpg" : "png" );
|
||||
|
||||
// Open up the file on disk.
|
||||
FileStream fs;
|
||||
if ( !fs.open( filename, Torque::FS::File::Write ) )
|
||||
Con::errorf( "ScreenShot::_singleCapture() - Failed to open output file '%s'!", filename );
|
||||
// Write it and close.
|
||||
if ( mWriteJPG )
|
||||
bitmap->writeBitmap( "jpg", filename);
|
||||
else
|
||||
{
|
||||
// Write it and close.
|
||||
if ( mWriteJPG )
|
||||
bitmap->writeBitmap( "jpg", filename);
|
||||
else
|
||||
bitmap->writeBitmap( "png", filename);
|
||||
|
||||
fs.close();
|
||||
}
|
||||
bitmap->writeBitmap( "png", filename);
|
||||
|
||||
// Cleanup.
|
||||
delete bitmap;
|
||||
|
|
|
|||
|
|
@ -44,13 +44,7 @@ public:
|
|||
/// Pushes a new frame into the video stream
|
||||
bool pushFrame( GBitmap * bitmap )
|
||||
{
|
||||
FileStream fs;
|
||||
String framePath = mPath + String::ToString("%.6u.png", mCurrentFrame);
|
||||
if ( !fs.open( framePath, Torque::FS::File::Write ) )
|
||||
{
|
||||
Con::errorf( "VideoEncoderPNG::pushFrame() - Failed to open output file '%s'!", framePath.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
//Increment
|
||||
mCurrentFrame++;
|
||||
|
|
|
|||
|
|
@ -67,13 +67,6 @@ bool TerrainBlock::exportHeightMap( const UTF8 *filePath, const String &format )
|
|||
}
|
||||
}
|
||||
|
||||
FileStream stream;
|
||||
if ( !stream.open( filePath, Torque::FS::File::Write ) )
|
||||
{
|
||||
Con::errorf( "TerrainBlock::exportHeightMap() - Error opening file for writing: %s !", filePath );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !output.writeBitmap( format, filePath) )
|
||||
{
|
||||
Con::errorf( "TerrainBlock::exportHeightMap() - Error writing %s: %s !", format.c_str(), filePath );
|
||||
|
|
@ -120,13 +113,6 @@ bool TerrainBlock::exportLayerMaps( const UTF8 *filePrefix, const String &format
|
|||
UTF8 filePath[1024];
|
||||
dSprintf( filePath, 1024, "%s_%d_%s.%s", filePrefix, i, mFile->mMaterials[i]->getInternalName(), format.c_str() );
|
||||
|
||||
FileStream stream;
|
||||
if ( !stream.open( filePath, Torque::FS::File::Write ) )
|
||||
{
|
||||
Con::errorf( "TerrainBlock::exportLayerMaps() - Error opening file for writing: %s !", filePath );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !output.writeBitmap( format, filePath) )
|
||||
{
|
||||
Con::errorf( "TerrainBlock::exportLayerMaps() - Error writing %s: %s !", format.c_str(), filePath );
|
||||
|
|
|
|||
|
|
@ -477,13 +477,6 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache)
|
|||
}
|
||||
else
|
||||
{
|
||||
FileStream stream;
|
||||
if (!stream.open(_getBaseTexCacheFileName(), Torque::FS::File::Write))
|
||||
{
|
||||
mBaseTex = blendTex;
|
||||
return;
|
||||
}
|
||||
|
||||
GBitmap bitmap(blendTex->getWidth(), blendTex->getHeight(), false, GFXFormatR8G8B8A8);
|
||||
blendTex->copyToBmp(&bitmap);
|
||||
bitmap.writeBitmap(formatToExtension(mBaseTexFormat), _getBaseTexCacheFileName());
|
||||
|
|
|
|||
|
|
@ -505,13 +505,10 @@ void TSLastDetail::_update()
|
|||
String normalsPath = _getNormalMapPath();
|
||||
|
||||
FileStream stream;
|
||||
if ( stream.open( imposterPath, Torque::FS::File::Write ) )
|
||||
destBmp.writeBitmap( "png", imposterPath);
|
||||
stream.close();
|
||||
|
||||
if ( stream.open( normalsPath, Torque::FS::File::Write ) )
|
||||
destNormal.writeBitmap( "png", normalsPath);
|
||||
stream.close();
|
||||
if (!destBmp.writeBitmap("png", imposterPath))
|
||||
Con::errorf("TSLastDetail::_update() - failed to write imposter %s", imposterPath);
|
||||
if (!destNormal.writeBitmap("png", normalsPath))
|
||||
Con::errorf("TSLastDetail::_update() - failed to write normal %s", normalsPath);
|
||||
}
|
||||
|
||||
// DEBUG: Some code to force usage of a test image.
|
||||
|
|
|
|||
|
|
@ -316,16 +316,9 @@ void ImposterCapture::_separateAlpha( GBitmap *imposterOut )
|
|||
|
||||
if ( 0 )
|
||||
{
|
||||
FileStream fs;
|
||||
if ( fs.open( "./imposterout.png", Torque::FS::File::Write ) )
|
||||
imposterOut->writeBitmap( "png", "./imposterout.png" );
|
||||
imposterOut->writeBitmap("png", "./imposterout.png");
|
||||
|
||||
fs.close();
|
||||
|
||||
if ( fs.open( "./temp.png", Torque::FS::File::Write ) )
|
||||
bmp->writeBitmap( "png", "./temp.png" );
|
||||
|
||||
fs.close();
|
||||
bmp->writeBitmap("png", "./temp.png");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -482,26 +475,13 @@ void ImposterCapture::capture( const MatrixF &rotMatrix,
|
|||
if ( 0 )
|
||||
{
|
||||
// Render out the bitmaps for debug purposes.
|
||||
FileStream fs;
|
||||
if ( fs.open( "./blackbmp.png", Torque::FS::File::Write ) )
|
||||
mBlackBmp->writeBitmap( "png", "./blackbmp.png" );
|
||||
mBlackBmp->writeBitmap( "png", "./blackbmp.png" );
|
||||
|
||||
fs.close();
|
||||
mWhiteBmp->writeBitmap( "png", "./whitebmp.png" );
|
||||
|
||||
if ( fs.open( "./whitebmp.png", Torque::FS::File::Write ) )
|
||||
mWhiteBmp->writeBitmap( "png", "./whitebmp.png" );
|
||||
(*normalMapOut)->writeBitmap( "png", "./normalbmp.png" );
|
||||
|
||||
fs.close();
|
||||
|
||||
if ( fs.open( "./normalbmp.png", Torque::FS::File::Write ) )
|
||||
(*normalMapOut)->writeBitmap( "png", "./normalbmp.png" );
|
||||
|
||||
fs.close();
|
||||
|
||||
if ( fs.open( "./finalimposter.png", Torque::FS::File::Write ) )
|
||||
(*imposterOut)->writeBitmap( "png", "./finalimposter.png" );
|
||||
|
||||
fs.close();
|
||||
(*imposterOut)->writeBitmap( "png", "./finalimposter.png" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue