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
|
#include "utils.hpp"
#include "library.hpp"
#include "mapdump.hpp"
#include <QColor>
#include <QImage>
#include <QPainter>
rgb_t modify_color(rgb_t c, uint8_t variant)
{
int m;
switch (variant)
{
case 0: m = 180; break;
case 1: m = 200; break;
case 2: m = 255; break;
case 3: m = 135; break;
default: m = 0; break;
}
return {uint8_t(m * c.r / 255),
uint8_t(m * c.g / 255),
uint8_t(m * c.b / 255)};
}
QColor rgb2qcolor(rgb_t c) {return QColor(c.r, c.g, c.b);}
QPixmap pixmap_of_map_data(const map_data_t &map_data, double scaling)
{
QImage ret(128, 128, QImage::Format_ARGB32);
ret.setDevicePixelRatio(scaling);
for (size_t i = 0; i < 128; ++i)
for (size_t j = 0; j < 128; ++j)
{
uint8_t d = map_data[j * 128 + i];
uint8_t b = d >> 2;
uint8_t v = d & 3;
QColor color = Qt::GlobalColor::transparent;
if (b > 0 && b < 62)
color = rgb2qcolor(modify_color(MAP_COLORS[b], v));
ret.setPixelColor(i, j, color);
}
return QPixmap::fromImage(ret);
}
QImage image_of_map_group(const map_library *library, const map_group_t &group, double scaling)
{
QImage ret(group.hc * 128, group.vc * 128, QImage::Format_ARGB32);
ret.fill(0);
ret.setDevicePixelRatio(1.);
{
QPainter p(&ret);
for (int i = 0 ; i < group.vc; ++i)
for (int j = 0 ; j < group.hc; ++j)
if (group.populated[i * group.hc + j])
p.drawPixmap(128 * j, 128 * i, pixmap_of_map_data(library->get_map(group.ids[i * group.hc + j]).map_data, 1.));
}
ret.setDevicePixelRatio(scaling);
return ret;
}
|