From 971ba323380b91d8403f89af8f0a99c1181e09ff Mon Sep 17 00:00:00 2001 From: Joshua Ogunyinka Date: Sat, 28 Aug 2021 09:51:13 +0400 Subject: [PATCH] added support for loading/saving alpha channels in palette files --- src/doc/file/pal_file.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/doc/file/pal_file.cpp b/src/doc/file/pal_file.cpp index f9a165442..b16d753cb 100644 --- a/src/doc/file/pal_file.cpp +++ b/src/doc/file/pal_file.cpp @@ -59,10 +59,10 @@ Palette* load_pal_file(const char *filename) if (line.empty()) continue; - int r, g, b; + int r, g, b, a=255; std::istringstream lineIn(line); - lineIn >> r >> g >> b; - pal->addEntry(rgba(r, g, b, 255)); + lineIn >> r >> g >> b >> a; + pal->addEntry(rgba(r, g, b, a)); } return pal.release(); @@ -77,11 +77,16 @@ bool save_pal_file(const Palette *pal, const char *filename) << "0100\n" << pal->size() << "\n"; + const bool hasAlpha = pal->hasAlpha(); for (int i=0; isize(); ++i) { uint32_t col = pal->getEntry(i); f << ((int)rgba_getr(col)) << " " << ((int)rgba_getg(col)) << " " - << ((int)rgba_getb(col)) << "\n"; + << ((int)rgba_getb(col)); + if (hasAlpha) { + f << " " << ((int)rgba_geta(col)); + } + f << "\n"; } return true;