Show HN: An attempt to make a reduce-palette/dither filter for 2d canvas images
scrawl-v8.rikweb.org.uk
scrawl-v8.rikweb.org.uk
I don't at all mean to diminish the work, it's more a hunch that it's under-performing. I was dicking around with dithering last year, and had similar problems initially.
[1] - https://github.com/KaliedaRik/Scrawl-canvas/blob/master/sour...
I went a different way, converting each pixel to its LAB color space values to find the optimal palette for the image (based on preference arguments), then afterwards measuring each pixel against the palette colors to find the two closest colors before deciding which of those two colors to pick based on a distance propensity weighting against the semi-random number assigned to that pixel.
Coming up with highly efficient algorithms (for anything!) is not my strongest skill. Neither is trying to explain them.
That particular implementation is less than ideal. It has issues with correctness (the precision of FP32 accumulators was not enough for my use cases, needed an upgrade to FP64), performance (no SIMD), and subjective code quality (I tend to avoid global variables for things like that).
But the algorithm itself is awesome.
Shadertoy has [1] a dithering example that runs at 60fps, might be the same effect you have though
> Note that this is a resource-intensive filter. Memoization is strongly advised!
Can you make this be the default for non Safari browsers? This really made my CPU fan work hard. Also, why does this need to recalculate the image so many times a second if it is the same image each time? It really only needs to redraw when I change one of the options.
The demo is a part of the testing regime for my canvas library. I set the default to "don't memoize" because it's the quickest way to see how intense/computationally expensive the filter gets using different parameters. For most scenarios the output should be memoized (to stop unresponsive websites, device damage, etc)
My ultimate goal would be to get the filter working more efficiently on dynamic input eg a video media stream. So far only the simplest settings (2 colours with dither) are watchable: https://codepen.io/kaliedarik/pen/OJOaOZz
Turning on/off Blue Noise in the OP's demo makes clear to me how good it was.
https://en.wikipedia.org/wiki/Dither#Digital_photography_and...