-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtexturemerger.cpp
55 lines (45 loc) · 1.6 KB
/
texturemerger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "texturemerger.h"
#include "packentrymetadata.h"
#include <QImage>
#include <QPainter>
namespace ProjectZomboidPackManager
{
TextureMerger::TextureMerger(QObject *parent)
: ThreadableTask(parent)
{
}
TextureMerger::~TextureMerger()
{
}
void TextureMerger::DoTask()
{
QStringList filters;
filters << "*.png";
QDir currentDir = _folder;
for (PackFilePageMetaData data : _fileData->Pages())
{
emit SendMessage("Merging " + data.Name());
if (currentDir.exists(data.Name()) &&
currentDir.exists(data.Name() + ".png"))
{
QString imageFilePath = currentDir.absolutePath() + "/" + data.Name() + ".png";
QImage image(imageFilePath);
QImage newImage(image.width(), image.height(), image.format());
QPainter painter(&newImage);
currentDir.remove(imageFilePath);
currentDir.cd(data.Name());
for (PackEntryMetaData entry : data.Entries())
{
if (currentDir.exists(entry.Name() + ".png"))
{
QImage texture(currentDir.absolutePath() + "/" + entry.Name() + ".png");
painter.drawImage(entry.XPos(), entry.YPos(), texture);
}
}
newImage.save(imageFilePath);
currentDir.cdUp();
}
}
emit SendMessage("Finished merging all files.");
}
}