From 18350dc9a2876145bf9b73e05c4f042dd0f0c2ad Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Sun, 22 May 2022 23:19:33 +0200 Subject: [PATCH] VOXEL: allow to save the palette glow color to png --- src/modules/voxel/Palette.cpp | 15 +++++++++++++++ src/modules/voxel/Palette.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/modules/voxel/Palette.cpp b/src/modules/voxel/Palette.cpp index 090078611..f0f4baf8f 100644 --- a/src/modules/voxel/Palette.cpp +++ b/src/modules/voxel/Palette.cpp @@ -132,6 +132,21 @@ bool Palette::save(const char *name) const { return true; } +bool Palette::saveGlow(const char *name) const { + if (name == nullptr || name[0] == '\0') { + return false; + } + image::Image img(name); + Log::info("Save glow palette colors to %s", name); + // must be voxel::PaletteMaxColors - otherwise the exporter uv coordinates must get adopted + img.loadRGBA((const uint8_t *)glowColors, sizeof(glowColors), lengthof(glowColors), 1); + if (!img.writePng()) { + Log::warn("Failed to write the glow palette colors file '%s'", name); + return false; + } + return true; +} + bool Palette::load(const uint8_t *rgbaBuf, size_t bufsize) { if (bufsize % 4 != 0) { Log::warn("Buf size doesn't match expectation: %i", (int)bufsize); diff --git a/src/modules/voxel/Palette.h b/src/modules/voxel/Palette.h index c24a027d4..faa941511 100644 --- a/src/modules/voxel/Palette.h +++ b/src/modules/voxel/Palette.h @@ -41,6 +41,7 @@ public: } bool load(const char *name); bool save(const char *name = nullptr) const; + bool saveGlow(const char *name = nullptr) const; bool load(const uint8_t *rgbaBuf, size_t bufsize); bool minecraft();