rgbds
                                
                                 rgbds copied to clipboard
                                
                                    rgbds copied to clipboard
                            
                            
                            
                        Encode reversed images as grayscale or indexed when possible
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:
- white, yellow, blue, black
- 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.