3 ms·
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
by marginalia_nu 4y ago
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).
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.
- rikroots 4y agoThanks for checking the demo out. The code[1] is very much a work-in-progress - suggestions for algorithm improvements (they're not based on Floyd-Steinberg) are always welcome! [1] - https://github.com/KaliedaRik/Scrawl-canvas/blob/master/source/factory/filterEngine.js#L4015 https://github.com/KaliedaRik/Scrawl-canvas/blob/master/sour...
- dubiousconst281 4y agoOne fast way to do palette reduction is by using a 16-bit RGB565 lookup table filled with all the closest colors relative to each entry index, then you can replace each pixel in the image using just a few bitwise ops and one array access.
- rikroots 4y agoThat's an interesting approach! 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.