Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordered Dithering #32

Open
alexharris opened this issue Jan 9, 2020 · 3 comments
Open

Ordered Dithering #32

alexharris opened this issue Jan 9, 2020 · 3 comments

Comments

@alexharris
Copy link

Hi Leon,

I am interested in adding some ordered dithering options to RgbQuant.js. I am trying to implement, to start, a 2x2 Bayer Matrix. I am trying to do this by adding the following to the kernels array:

Bayer2x2: [
[3 / 6, 0, 0],
[1 / 6, 1, 0],
[0 / 6, 0, 1],
[2 / 6, 1, 1],
],

However, it seems that setting the first value at 0,0 is preventing colors from getting applied. Having a little trouble understanding the code to debug, I can dig in more but thought you might have some quick ideas of where to look.

thanks, love the script,

Alex

@leeoniya
Copy link
Owner

leeoniya commented Jan 9, 2020

i'm pretty sure that an ordered dither will need a dedicated loop since it operates on a different principal than error diffusion dithers - you cannot just stick a bayer matrix into an error diffusion loop and have it work. you'll likely need to implement an ordered dither as its own loop.

here's way too much info on how both work, with pseudo-code:

http://www.tannerhelland.com/4660/dithering-eleven-algorithms-source-code/
https://bisqwit.iki.fi/story/howto/dither/jy/

also, serpentine error diffusion currently has a bug [1] that i haven't gotten around to diving into. feel free to take a look at that, if interested.

i'm currently working on another project that i'd like to get to 1.0, but i'd be happy to review code or discuss dithering further. i'm no expert in the subject either, so i can't give you much advice without sinking some additional time myself.

[1] #30

@alexharris
Copy link
Author

Thanks for the response. I'll take a look at that bug, and put some more thought into the ordered dither situation. It looks like the fork that you mentioned in another issue comment is considering implementing ordered dithering, so I might poke around over there too. Thanks!

@leeoniya
Copy link
Owner

leeoniya commented Jan 9, 2020

i've got a bunch of thoughts rolling around. at some point i want to look into improving perf and color accuracy via non-rgb color spaces in #31. i've recently stumbled upon https://github.com/photopea/UPNG.js which is very fast and great at 256 colors, but further testing is revealing that it often misses key colors at palette sizes of e.g. <= 32 and rgbquant does better. i've inquired about dithering support in photopea/UNN.js#1.

it's all lazy investigative work at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants