forked from wa-st/resizeobj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnlargeConverter.cpp
81 lines (70 loc) · 1.72 KB
/
EnlargeConverter.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "stdafx.h"
#include "EnlargeConverter.h"
#include "utils.h"
bool EnlargeConverter::convertNodeTree(PakNode *node) const
{
if (node->type() == "IMG")
{
convertImage(node);
return true;
}
else
{
bool result = false;
for (PakNode::iterator it = node->begin(); it != node->end(); it++)
result = convertNodeTree(*it) || result;
return result;
}
}
void EnlargeConverter::convertImage(PakNode *node) const
{
SimuImage image;
image.load(*node->data());
if (image.data.size() > 0)
{
if (image.zoomable)
{
enlargeImage(image);
image.save(*node->data());
}
else
{
if (addImageMargin(image))
image.save(*node->data());
}
}
}
bool EnlargeConverter::addImageMargin(SimuImage &image) const
{
// IMG ver2以降では右余白を記録しなくなったので、変換の必要性なし。
if (image.version >= 2)
return false;
int x, y, w, h;
image.getBounds(x, y, w, h);
MemoryBitmap<PIXVAL> bmp(w * 2, image.height);
bmp.clear(SIMU_TRANSPARENT);
image.drawTo(0, 0, bmp);
image.encodeFrom(bmp, x, y, false);
return true;
}
void EnlargeConverter::enlargeImage(SimuImage &data) const
{
int x, y, w, h;
data.getBounds(x, y, w, h);
MemoryBitmap<PIXVAL> bmp64(w, h);
MemoryBitmap<PIXVAL> bmp128(w * 2, h * 2);
bmp64.clear(SIMU_TRANSPARENT);
data.drawTo(0, 0, bmp64);
for (int iy = 0; iy < bmp64.height(); ++iy)
{
for (int ix = 0; ix < bmp64.width(); ++ix)
{
PIXVAL col = bmp64.pixel(ix, iy);
bmp128.pixel(ix * 2 , iy * 2 ) = col;
bmp128.pixel(ix * 2 + 1, iy * 2 ) = col;
bmp128.pixel(ix * 2 , iy * 2 + 1) = col;
bmp128.pixel(ix * 2 + 1, iy * 2 + 1) = col;
}
}
data.encodeFrom(bmp128, x * 2, y * 2, false);
}