1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

exportBitmaps now uses QT libs

This commit is contained in:
krs 2022-11-24 00:11:27 +02:00
parent ec1a995218
commit 14b031118c
3 changed files with 9 additions and 17 deletions

View File

@ -21,8 +21,6 @@
#include "../lib/CRandomGenerator.h"
#include "../lib/VCMIDirs.h"
#include <boost/filesystem.hpp>
typedef std::map<size_t, std::vector<JsonNode>> source_map;
/// Class for def loading
@ -688,7 +686,7 @@ std::shared_ptr<QImage> Animation::getImage(size_t frame, size_t group, bool ver
return nullptr;
}
void Animation::exportBitmaps(const bfs::path & path) const
void Animation::exportBitmaps(const QDir & path) const
{
if(images.empty())
{
@ -696,8 +694,8 @@ void Animation::exportBitmaps(const bfs::path & path) const
return;
}
bfs::path actualPath = path / "SPRITES" / name;
bfs::create_directories(actualPath);
QString actualPath = path.absolutePath() + "/SPRITES/" + QString::fromStdString(name);
QDir().mkdir(actualPath);
size_t counter = 0;
@ -710,19 +708,15 @@ void Animation::exportBitmaps(const bfs::path & path) const
size_t frame = imagePair.first;
const auto img = imagePair.second;
boost::format fmt("%d_%d.png");
fmt % group % frame;
std::string fileName = fmt.str();
fileName = name + "_" + fileName;
auto s = img->size();
img->save(pathToQString(actualPath / fileName), "PNG");
QString filename = QString("%1_%2_%3.png").arg(QString::fromStdString(name)).arg(group).arg(frame);
QString filePath = actualPath + "/" + filename;
img->save(filePath, "PNG");
counter++;
}
}
logGlobal->info("Exported %d frames to %s", counter, actualPath.string());
logGlobal->info("Exported %d frames to %s", counter, actualPath.toStdString());
}
void Animation::load()

View File

@ -15,8 +15,6 @@
#include <QRgb>
#include <QImage>
namespace bfs = boost::filesystem;
/*
* Base class for images, can be used for non-animation pictures as well
*/
@ -85,7 +83,7 @@ public:
void load (size_t frame, size_t group = 0);
void unload(size_t frame, size_t group = 0);
void exportBitmaps(const bfs::path & path) const;
void exportBitmaps(const QDir & path) const;
//total count of frames in group (including not loaded)
size_t size(size_t group = 0) const;

View File

@ -68,7 +68,7 @@ void splitDefFile(const std::string & fileName, const bfs::path & spritesPath, b
{
std::unique_ptr<Animation> anim = make_unique<Animation>(fileName);
anim->preload();
anim->exportBitmaps(VCMIDirs::get().userCachePath() / "extracted");
anim->exportBitmaps(pathToQString(VCMIDirs::get().userCachePath() / "extracted"));
if(deleteOriginals)
bfs::remove(spritesPath / fileName);