mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-23 12:08:45 +02:00
Add debug code to save every loaded image to a file
This commit is contained in:
parent
612490712e
commit
4abd96dba4
@ -98,11 +98,15 @@ std::string ImageLocator::toString() const
|
||||
return "invalid";
|
||||
|
||||
if (image)
|
||||
{
|
||||
result += image->getOriginalName();
|
||||
assert(!result.empty());
|
||||
}
|
||||
|
||||
if (defFile)
|
||||
{
|
||||
result += defFile->getOriginalName();
|
||||
assert(!result.empty());
|
||||
result += "-" + std::to_string(defGroup);
|
||||
result += "-" + std::to_string(defFrame);
|
||||
}
|
||||
@ -120,7 +124,7 @@ std::string ImageLocator::toString() const
|
||||
result += "-player" + playerColored.toString();
|
||||
|
||||
if (layer != EImageLayer::ALL)
|
||||
result =+ "-layer" + std::to_string(static_cast<int>(layer));
|
||||
result += "-layer" + std::to_string(static_cast<int>(layer));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ class RenderHandler : public IRenderHandler
|
||||
|
||||
void addImageListEntry(size_t index, size_t group, const std::string & listName, const std::string & imageName);
|
||||
void addImageListEntries(const EntityService * service);
|
||||
void storeCachedImage(const ImageLocator & locator, std::shared_ptr<ISharedImage> image);
|
||||
|
||||
std::shared_ptr<ISharedImage> loadImageImpl(const ImageLocator & config);
|
||||
|
||||
|
@ -330,6 +330,9 @@ std::shared_ptr<ISharedImage> SDLImageShared::scaleTo(const Point & size, SDL_Pa
|
||||
|
||||
void SDLImageShared::exportBitmap(const boost::filesystem::path& path, SDL_Palette * palette) const
|
||||
{
|
||||
if (!surf)
|
||||
return;
|
||||
|
||||
if (palette && surf->format->palette)
|
||||
SDL_SetSurfacePalette(surf, palette);
|
||||
IMG_SavePNG(surf, path.string().c_str());
|
||||
|
Loading…
x
Reference in New Issue
Block a user