aboutsummaryrefslogtreecommitdiff
path: root/mapman/src/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mapman/src/utils.cpp')
-rw-r--r--mapman/src/utils.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/mapman/src/utils.cpp b/mapman/src/utils.cpp
new file mode 100644
index 0000000..f01d946
--- /dev/null
+++ b/mapman/src/utils.cpp
@@ -0,0 +1,40 @@
+#include "utils.hpp"
+
+#include <QColor>
+#include <QImage>
+
+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 std::array<uint8_t, 128 * 128> &map_data)
+{
+ QImage ret(128, 128, QImage::Format_ARGB32);
+ 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);
+}
+