node-sixel icon indicating copy to clipboard operation
node-sixel copied to clipboard

Restore nearest behavior

Open ellbur opened this issue 8 months ago • 2 comments

The nearest-matching palette behavior was removed in https://github.com/jerch/node-sixel/commit/b6b107cd1ce7fade04b6c90631eb852eb1e0eb36

This change puts it back.

I haven't managed to build it yet so I haven't tested it. I will do that next.

ellbur avatar May 02 '25 03:05 ellbur

Oh weird, this || 0 looks like some testing remnant.

Note that the encoder part of this lib is alpha and almost untested. It has serious performance issues, so I did not try to get it into better shape. Instead I might release a wasm based encoder soon (half done), which is like 10+ times faster, includes a decent quantizer already and has a very low code and memory footprint. It also uses https://github.com/jerch/inwasm, which makes the wasm parts much easier to deal with.

From a conceptual side - you should not rely on that "dumb" nearest color match implementation at all, as it does square root distance matching for every color against all colors of the given palette w'o any palette correction. Thats very very wasteful, and the palette is almost always subpar. Better use a quantizer to get an optimized palette, that is closer to the original colors.

jerch avatar May 02 '25 08:05 jerch

Thanks for the info, and I'm happy to hear you're working on a faster version! For my limited purposes though, this one is plenty fast enough.

I got it to build, though I had to use a newer version of canvas since I couldn't install the older version on my computer.

ellbur avatar May 02 '25 12:05 ellbur