1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Add debug code to save every loaded image to a file

This commit is contained in:
Ivan Savenko
2024-09-13 12:26:31 +00:00
parent 612490712e
commit 4abd96dba4
4 changed files with 26 additions and 4 deletions

View File

@@ -23,6 +23,7 @@
#include "../../lib/json/JsonUtils.h"
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/VCMIDirs.h"
#include <vcmi/ArtifactService.h>
#include <vcmi/CreatureService.h>
@@ -188,13 +189,26 @@ std::shared_ptr<ISharedImage> RenderHandler::loadImageFromFileUncached(const Ima
throw std::runtime_error("Invalid image locator received!");
}
void RenderHandler::storeCachedImage(const ImageLocator & locator, std::shared_ptr<ISharedImage> image)
{
imageFiles[locator] = image;
#if 0
const boost::filesystem::path outPath = VCMIDirs::get().userExtractedPath() / "imageCache" / (locator.toString() + ".png");
boost::filesystem::path outDir = outPath;
outDir.remove_filename();
boost::filesystem::create_directories(outDir);
image->exportBitmap(outPath , nullptr);
#endif
}
std::shared_ptr<ISharedImage> RenderHandler::loadImageFromFile(const ImageLocator & locator)
{
if (imageFiles.count(locator))
return imageFiles.at(locator);
auto result = loadImageFromFileUncached(locator);
imageFiles[locator] = result;
storeCachedImage(locator, result);
return result;
}
@@ -211,7 +225,7 @@ std::shared_ptr<ISharedImage> RenderHandler::transformImage(const ImageLocator &
if (locator.horizontalFlip)
result = result->horizontalFlip();
imageFiles[locator] = result;
storeCachedImage(locator, result);
return result;
}
@@ -234,7 +248,7 @@ std::shared_ptr<ISharedImage> RenderHandler::scaleImage(const ImageLocator & loc
// TODO: try to optimize image size (possibly even before scaling?) - trim image borders if they are completely transparent
auto result = handle->getSharedImage();
imageFiles[locator] = result;
storeCachedImage(locator, result);
return result;
}