rgbds icon indicating copy to clipboard operation
rgbds copied to clipboard

Encode reversed images as grayscale or indexed when possible

Open Rangi42 opened this issue 4 months ago • 0 comments

Fixes #1251 and #1704

This also fixes an issue with sorting indexed palettes that was breaking the reverse_curve test case. Say your input PNG has this indexed palette:

white, yellow, blue, black, white, yellow, fuchsia, black

That corresponds to these two GBC palettes:

  1. white, yellow, blue, black
  2. white, yellow, fuchsia, black

We were sorting each 4-color GBC palette by comparing colors' order in the PNG palette -- but the PNG palette is one long series with repeats, and ignoring the repeats since we search iterating from the beginning, it looks like:

white, yellow, blue, black, fuchsia

So the second GBC palette would end up as [white, yellow, black, fuchsia].

This wasn't a problem before because the reverse image was encoded as RGBA8888, so re-reversing it would sort each GBC palette by luminance. But now -r stores the -p palette in the output PNG's PLTE.

Rangi42 avatar Jun 16 '25 14:06 Rangi42