mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-04 21:10:32 +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
11 changed files with 39 additions and 111 deletions
|
|
@ -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()))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue