From f4463b1708f0492e90557ab08915f35fe3ad3eb9 Mon Sep 17 00:00:00 2001 From: Eldred Habert Date: Fri, 24 Nov 2023 19:19:04 +0100 Subject: [PATCH] Honor `-c` with `rgbgfx -r` (#1254) Fixes #1166 --- include/gfx/rgba.hpp | 1 + src/gfx/reverse.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/gfx/rgba.hpp b/include/gfx/rgba.hpp index ae41d163..65e49218 100644 --- a/include/gfx/rgba.hpp +++ b/include/gfx/rgba.hpp @@ -37,6 +37,7 @@ struct Rgba { auto shl = [](uint8_t val, unsigned shift) { return static_cast(val) << shift; }; return shl(red, 24) | shl(green, 16) | shl(blue, 8) | shl(alpha, 0); } + friend bool operator==(Rgba const &lhs, Rgba const &rhs) { return lhs.toCSS() == rhs.toCSS(); } friend bool operator!=(Rgba const &lhs, Rgba const &rhs) { return lhs.toCSS() != rhs.toCSS(); } /* diff --git a/src/gfx/reverse.cpp b/src/gfx/reverse.cpp index 1dcae1dc..15a08c89 100644 --- a/src/gfx/reverse.cpp +++ b/src/gfx/reverse.cpp @@ -140,7 +140,8 @@ void reverse() { std::vector> palettes{ {Rgba(0xFFFFFFFF), Rgba(0xAAAAAAFF), Rgba(0x555555FF), Rgba(0x000000FF)} - }; + }; + // If a palette file is used as input, it overrides the default colours. if (options.palettes.has_value()) { File file; if (!file.open(*options.palettes, std::ios::in | std::ios::binary)) { @@ -171,6 +172,14 @@ void reverse() { warning("Read %zu palettes, more than the specified limit of %zu", palettes.size(), options.nbPalettes); } + + if (options.palSpecType == Options::EXPLICIT && palettes != options.palSpec) { + warning("Colors in the palette file do not match those specified with `-c`!"); + } + } else if (options.palSpecType == Options::EMBEDDED) { + warning("An embedded palette was requested, but no palette file was specified; ignoring request."); + } else if (options.palSpecType == Options::EXPLICIT) { + palettes = std::move(options.palSpec); // We won't be using it again. } std::optional> attrmap;