From 98c5c7f7768092153378624b1602d99e958eaf35 Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Tue, 5 Aug 2025 13:05:21 -0400 Subject: [PATCH] Support `rgbgfx -c auto` for automatic palette generation --- man/rgbgfx.1 | 10 ++++++++++ src/gfx/main.cpp | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/man/rgbgfx.1 b/man/rgbgfx.1 index 906398fb..fef83e09 100644 --- a/man/rgbgfx.1 +++ b/man/rgbgfx.1 @@ -180,6 +180,16 @@ and so on. Gray shade 0 is the lightest (white), 3 is the darkest (black). The same gray shade cannot go in two color indexes. To specify a DMG palette, the input PNG must have all its colors in shades of gray, without any transparent colors. +.It Sy automatic palette generation +If +.Ar pal_spec +is the case-insensitive word +.Cm auto , +then a palette is automatically generated using the procedure described in +.Sx PALETTE GENERATION . +This is the default behavior if +.Fl c +was not specified. .It Sy external palette spec Otherwise, .Ar pal_spec diff --git a/src/gfx/main.cpp b/src/gfx/main.cpp index 877b0d26..a967be07 100644 --- a/src/gfx/main.cpp +++ b/src/gfx/main.cpp @@ -343,6 +343,8 @@ static char *parseArgv(int argc, char *argv[]) { } else if (strcasecmp(musl_optarg, "embedded") == 0) { // Use PLTE, error out if missing options.palSpecType = Options::EMBEDDED; + } else if (strcasecmp(musl_optarg, "auto") == 0) { + options.palSpecType = Options::NO_SPEC; } else if (strncasecmp(musl_optarg, "dmg=", literal_strlen("dmg=")) == 0) { options.palSpecType = Options::DMG; parseDmgPalSpec(&musl_optarg[literal_strlen("dmg=")]); @@ -634,7 +636,9 @@ static void verboseOutputConfig() { // -s/--palette-size fprintf(stderr, "\tPalettes contain %" PRIu8 " colors\n", options.nbColorsPerPal); // -c/--colors - if (options.palSpecType != Options::NO_SPEC) { + if (options.palSpecType == Options::NO_SPEC) { + fputs("\tAutomatic palette generation\n", stderr); + } else { fprintf(stderr, "\t%s palette spec\n", [] { switch (options.palSpecType) { case Options::EXPLICIT: