From 93cf929f29dea490ed60e5300cacdd99886c988e Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 9 Sep 2023 20:09:50 -0400 Subject: Add the standalone portion of mapman. --- mapman/src/utils.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 mapman/src/utils.cpp (limited to 'mapman/src/utils.cpp') 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 +#include + +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 &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); +} + -- cgit v1.2.3