Parse inline palette specs after getting CLI palette size limit (#2054)

This commit is contained in:
Rangi
2026-09-10 18:54:24 +02:00
committed by GitHub
parent 631ef003e7
commit 8a6b1946e3
8 changed files with 67 additions and 48 deletions
+10 -7
View File
@@ -29,6 +29,7 @@
#include "gfx/rgba.hpp"
#include "gfx/warning.hpp"
using namespace std::literals;
using namespace std::string_view_literals;
static char const *hexDigits = "0123456789ABCDEFabcdef";
@@ -131,8 +132,14 @@ void parseInlinePalSpec(char const * const rawArg) {
if (n == arg.length()) {
break;
} else if (arg[n] != ';' && arg[n] != ':') {
if (nbColors == 4) {
parseError(n, 1, "Each palette can only contain up to 4 colors");
if (nbColors == options.nbColorsPerPal) {
// `parseError` cannot take variadic arguments, since `format_` and
// `-Wformat-security` would complain about passing a template parameter pack
// to the C-style variadic `error` function, so we format the error message
// before passing it to `parseError`.
std::string msg = "Each palette can only contain up to "s
+ std::to_string(options.nbColorsPerPal) + " colors";
parseError(n, 1, msg.c_str());
return;
}
break;
@@ -664,11 +671,7 @@ void parseDmgPalSpec(char const * const rawArg) {
return;
}
parseDmgPalSpec(toHex(arg[0], arg[1]));
}
void parseDmgPalSpec(uint8_t palSpecDmg) {
options.palSpecDmg = palSpecDmg;
options.palSpecDmg = toHex(arg[0], arg[1]);
// Map gray shades to their DMG color indexes for fast lookup by `Rgba::grayIndex`
for (uint8_t i = 0; i < 4; ++i) {