diff options
author | 2023-09-09 20:09:50 -0400 | |
---|---|---|
committer | 2023-09-09 20:09:50 -0400 | |
commit | 93cf929f29dea490ed60e5300cacdd99886c988e (patch) | |
tree | 0f8669c56e22a287047ee20846b92f1580d7364f /mapman/src/utils.cpp | |
parent | 40432e083b11271cf3148b9c38156cf759436699 (diff) | |
download | meteor-trashy-addon-93cf929f29dea490ed60e5300cacdd99886c988e.tar.xz |
Add the standalone portion of mapman.
Diffstat (limited to 'mapman/src/utils.cpp')
-rw-r--r-- | mapman/src/utils.cpp | 40 |
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); +} + |