RGBGFX honors -c/--colors in -r/--reverse mode (#2144)

f4463b17 (#1254) was an incomplete fix for #1166
This commit is contained in:
Rangi authored and GitHub committed 2026-09-26 19:13:34 +02:00
1 parent 03c71ced93
commit e6e5133bcf
3 files changed
+17 -6

No files matched your search

+15 -6
View File
@@ -205,6 +205,7 @@ void reverse() {
{grayColors[0], grayColors[1], grayColors[2], grayColors[3]}
};
// If a palette file or palette spec is used as input, it overrides the default colors.
bool grayscale = false;
if (!options.palettes.empty()) {
File file;
if (!file.open(options.palettes, std::ios::in | std::ios::binary)) {
@@ -280,11 +281,15 @@ void reverse() {
for (size_t i = 0; i < palettes[0].size(); ++i) {
palettes[0][i] = grayColors[options.dmgValue(i)];
}
grayscale = true;
} else if (options.palSpecType == Options::EMBEDDED) {
warnx("An embedded palette was requested, but no palette file was specified; ignoring "
"request");
grayscale = true;
} else if (options.hasExplicitPalSpec()) {
palettes = std::move(options.palSpec); // We won't be using it again.
} else {
grayscale = true;
}
std::optional<std::vector<uint8_t>> attrmap;
@@ -497,10 +502,10 @@ void reverse() {
}
png_set_write_fn(png, &pngFile, writePng, flushPng);
int pngColorType = options.palettes.empty() ? PNG_COLOR_TYPE_GRAY
int pngColorType = grayscale ? PNG_COLOR_TYPE_GRAY
: palettes.size() == 1 ? PNG_COLOR_TYPE_PALETTE
: PNG_COLOR_TYPE_RGB_ALPHA;
int pngDepth = options.palettes.empty() ? options.bitDepth : 8;
int pngDepth = grayscale ? options.bitDepth : 8;
png_set_IHDR(
png,
@@ -531,17 +536,21 @@ void reverse() {
png_byte pngTrans[4] = {};
int nbPngColors = 0, nbPngTrans = 0;
for (auto const &color : palettes[0]) {
if (!color.has_value()) {
continue;
}
if (color.has_value()) {
pngPalette[nbPngColors].red = color->red;
pngPalette[nbPngColors].green = color->green;
pngPalette[nbPngColors].blue = color->blue;
pngTrans[nbPngColors] = color->alpha;
++nbPngColors;
if (color->alpha < 255) {
nbPngTrans = nbPngColors;
}
} else {
pngPalette[nbPngColors].red = 255;
pngPalette[nbPngColors].green = 255;
pngPalette[nbPngColors].blue = 255;
pngTrans[nbPngColors] = 255;
}
++nbPngColors;
}
png_set_PLTE(png, pngInfo, pngPalette, nbPngColors);
if (nbPngTrans > 0) {
+1
View File
@@ -0,0 +1 @@
U3U3U3U3U3U3U3U3
+1
View File
@@ -0,0 +1 @@
-c #ff0000,#00ff00,#0000ff,#ffffff