mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
Fixes saveScaledImage to handle DDS format files, since DDS's go through a separate resource loader
This commit is contained in:
parent
5e26ce037b
commit
7fe85ab7d5
1 changed files with 38 additions and 14 deletions
|
|
@ -32,6 +32,7 @@
|
||||||
#include "console/console.h"
|
#include "console/console.h"
|
||||||
#include "platform/profiler.h"
|
#include "platform/profiler.h"
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
|
#include "gfx/bitmap/ddsFile.h"
|
||||||
|
|
||||||
using namespace Torque;
|
using namespace Torque;
|
||||||
|
|
||||||
|
|
@ -1362,30 +1363,48 @@ DefineEngineFunction( getBitmapInfo, String, ( const char *filename ),,
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineFunction(saveScaledImage, bool, (const char* bitmapSource, const char* bitmapDest, S32 resolutionSize), ("", "", 512),
|
DefineEngineFunction(saveScaledImage, bool, (const char* bitmapSource, const char* bitmapDest, S32 resolutionSize), ("", "", 512),
|
||||||
"Returns image info in the following format: width TAB height TAB bytesPerPixel TAB format. "
|
"Loads an image from the source path, and scales it down to the target resolution before"
|
||||||
"It will return an empty string if the file is not found.\n"
|
"Saving it out to the destination path.\n")
|
||||||
"@ingroup Rendering\n")
|
|
||||||
{
|
{
|
||||||
Resource<GBitmap> image = GBitmap::load(bitmapSource);
|
bool isDDS = false;
|
||||||
if (!image)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Torque::Path sourcePath = Torque::Path(bitmapSource);
|
//First, gotta check the extension, as we have some extra work to do if it's
|
||||||
|
//a DDS file
|
||||||
/*if (String("dds").equal(sourcePath.getExtension(), String::NoCase))
|
const char* ret = dStrrchr(bitmapSource, '.');
|
||||||
|
if (ret)
|
||||||
{
|
{
|
||||||
dds = DDSFile::load(correctPath, scalePower);
|
if (String::ToLower(ret) == String(".dds"))
|
||||||
|
isDDS = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false; //no extension? bail out
|
||||||
|
}
|
||||||
|
|
||||||
|
GBitmap* image;
|
||||||
|
if (isDDS)
|
||||||
|
{
|
||||||
|
Resource<DDSFile> dds = DDSFile::load(bitmapSource, 0);
|
||||||
if (dds != NULL)
|
if (dds != NULL)
|
||||||
{
|
{
|
||||||
|
image = new GBitmap();
|
||||||
if (!dds->decompressToGBitmap(image))
|
if (!dds->decompressToGBitmap(image))
|
||||||
{
|
{
|
||||||
delete image;
|
delete image;
|
||||||
image = NULL;
|
image = NULL;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
if (isPow2(image->getWidth())&& isPow2(image->getHeight()))
|
else
|
||||||
|
{
|
||||||
|
image = GBitmap::load(bitmapSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!image)
|
||||||
|
return false;
|
||||||
|
Torque::Path sourcePath = Torque::Path(bitmapSource);
|
||||||
|
|
||||||
|
if (isPow2(image->getWidth()) && isPow2(image->getHeight()))
|
||||||
image->extrudeMipLevels();
|
image->extrudeMipLevels();
|
||||||
|
|
||||||
U32 mipCount = image->getNumMipLevels();
|
U32 mipCount = image->getNumMipLevels();
|
||||||
|
|
@ -1396,9 +1415,14 @@ DefineEngineFunction(saveScaledImage, bool, (const char* bitmapSource, const cha
|
||||||
image->chopTopMips(mipCount - targetMips);
|
image->chopTopMips(mipCount - targetMips);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: support different format targets, for now we just force
|
||||||
|
//to png for simplicity
|
||||||
|
Torque::Path destinationPath = Torque::Path(bitmapDest);
|
||||||
|
destinationPath.setExtension("png");
|
||||||
|
|
||||||
// Open up the file on disk.
|
// Open up the file on disk.
|
||||||
FileStream fs;
|
FileStream fs;
|
||||||
if (!fs.open(bitmapDest, Torque::FS::File::Write))
|
if (!fs.open(destinationPath.getFullPath(), Torque::FS::File::Write))
|
||||||
{
|
{
|
||||||
Con::errorf("saveScaledImage() - Failed to open output file '%s'!", bitmapDest);
|
Con::errorf("saveScaledImage() - Failed to open output file '%s'!", bitmapDest);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue