The performance is worse than I would expect with a correctly implemented Floyd-Steinberg algorithm, I'd expect it to rasterize well even with a 2 color palette (that's easier to get right than RGB).<p>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.
The best palette-reducing algorithm I know is the one by Xiaolin Wu: <a href="https://www.ece.mcmaster.ca/~xwu/cq.c" rel="nofollow">https://www.ece.mcmaster.ca/~xwu/cq.c</a><p>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).<p>But the algorithm itself is awesome.
Could this be done in a opengl shader? That way it could be run on the GPU and improve performance a lot.<p>Shadertoy has [1] a dithering example that runs at 60fps, might be the same effect you have though<p>[1] <a href="https://www.shadertoy.com/view/NdsyD7" rel="nofollow">https://www.shadertoy.com/view/NdsyD7</a>
Nice work!<p>> Note that this is a resource-intensive filter. Memoization is strongly advised!<p>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.