TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: An attempt to make a reduce-palette/dither filter for 2d canvas images

21 pointsby rikrootsalmost 3 years ago

5 comments

marginalia_nualmost 3 years ago
The performance is worse than I would expect with a correctly implemented Floyd-Steinberg algorithm, I&#x27;d expect it to rasterize well even with a 2 color palette (that&#x27;s easier to get right than RGB).<p>I don&#x27;t at all mean to diminish the work, it&#x27;s more a hunch that it&#x27;s under-performing. I was dicking around with dithering last year, and had similar problems initially.
评论 #32533590 未加载
Const-mealmost 3 years ago
The best palette-reducing algorithm I know is the one by Xiaolin Wu: <a href="https:&#x2F;&#x2F;www.ece.mcmaster.ca&#x2F;~xwu&#x2F;cq.c" rel="nofollow">https:&#x2F;&#x2F;www.ece.mcmaster.ca&#x2F;~xwu&#x2F;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.
gitgudalmost 3 years ago
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:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;NdsyD7" rel="nofollow">https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;NdsyD7</a>
评论 #32647656 未加载
hx2aalmost 3 years ago
Nice work!<p>&gt; 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.
评论 #32531406 未加载
JKCalhounalmost 3 years ago
I remember when <i>blue noise</i> was the shit back in the 90&#x27;s. And wow, what a difference it makes when you enable it.
评论 #32532941 未加载