tilemap-studio icon indicating copy to clipboard operation
tilemap-studio copied to clipboard

Improve or replace the palette generation algorithm

Open Rangi42 opened this issue 1 year ago • 2 comments

Given this input image:

image

(Or this equivalent one which I find easier to look at):

image

It could be done with just two palettes:

{ 001f, 03f0, 7fe0, 7c10, }
{ 02ff, 23e0, 7d00, 5c1f, }

But Tilemap Studio (and superfamiconv) do it in six:

84ff00 ffbd00 00ff42 ff0000
ffbd00 00ffff ff0000 0042ff
ffbd00 ff00bd ff0000 8400ff
84ff00 00ffff 00ff42 0042ff
84ff00 00ff42 ff00bd 8400ff
00ffff ff00bd 8400ff 0042ff

(Extending the input to one which could fit in 8 palettes but for which we fail to do so is left as an exercise for the reader.)

Rangi42 avatar Aug 08 '24 15:08 Rangi42

@ISSOtm found this example in https://github.com/gbdev/rgbds/issues/1451. We may want to use the Overload-and-Remove algorithm from rgbgfx.

Rangi42 avatar Aug 08 '24 15:08 Rangi42

(Extending the input to one which could fit in 8 palettes but for which we fail to do so is left as an exercise for the reader.)

Here you go chief:

Image that fails to fit within 8 palettes

Correct answer:

{ 03f0, 7fe0, 001f, 7c10, }
{ 02cb, 5ac0, 0016, 580b, }
{ 02ff, 23e0, 5c1f, 7d00, }
{ 0216, 16c0, 4016, 58a0, }

SuperFamiconv (requires -P 12 or higher):

[["#b50000","#ffbd00","#5ab500","#00ff42"],
 ["#ff0000","#b58400","#00b529","#00ffff"],
 ["#b50000","#ffbd00","#00b5b5","#0042ff"],
 ["#ff0000","#b58400","#0029b5","#8400ff"],
 ["#b50000","#ffbd00","#5a00b5","#ff00bd"],
 ["#ff0000","#b58400","#84ff00","#b50084"],
 ["#5ab500","#00ff42","#00b5b5","#0042ff"],
 ["#84ff00","#00b529","#0029b5","#8400ff"],
 ["#5ab500","#00ff42","#5a00b5","#ff00bd"],
 ["#00b529","#00ffff","#8400ff","#b50084"],
 ["#5a00b5","#00b5b5","#0042ff","#ff00bd"],
 ["#84ff00","#00ffff","#0029b5","#b50084"]]

ISSOtm avatar Aug 08 '24 17:08 ISSOtm

Also refer to https://git.sr.ht/~issotm/pagination-rs/tree/master/item/src/lib.rs.

Rangi42 avatar Aug 19 '25 01:08 Rangi42