-
Notifications
You must be signed in to change notification settings - Fork 4
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
Separate formats from dithering? #2
Comments
Hmmm, they are actually in PaletteReducer already. I guess it's a case of inlining? Okay. |
Yeah, it's mostly like inlining, except in a few key places where it didn't make sense to duplicate almost all of the method but make a few parts specific to PNG8 or GIF. The animation code in particular has to track the current frame for some, but not all, dithering algorithms, and PaletteReducer doesn't have any concept of the current frame. Also, I think I can explain Scatter a little better than how it currently is in DitherAlgorithm, let's see... Broadly, it's Floyd-Steinberg error diffusion, but it adjusts that error up or down using blue noise, so it breaks up patterns in Floyd-Steinberg in a visually-preferable way. Specifically, it uses triangular-mapped blue noise, which produces more noise results in the center of the range (causing less adjustment of error) than noise at either extreme. At the end, there's an interesting step that exaggerates the diffusion of error but not the current pixel's color; this uses a method that can be thought of as an extremely rough approximation of cube root, and it only needs to be approximate because only the general shape of the function matters, not its precise values. The number Scatter has some artifact issues when the palette is small and dither strength is high; there are probably some ways to resolve this, but I'm not sure what they are yet. These artifacts appear as horizontal lines of contrasting color, and I think they're caused by over-correcting for one very high or low value at the start of the row. If you want to experiment with changing Scatter, good places to start might be adjusting various constants, simplifying Constants like The Changing how error gets diffused could be the most promising angle, but it's also the one I understand the least. I think something is wrong with all of the error-diffusion-based dithers when the dither strength is too high, but I don't really know why the linear "streak" artifacts occur. I hope that helps! |
I am a bit interested in getting a somewhat simple description of the cool new "scatter" algorithm, but the way it's duplicated in
AnimatedGif
andPNG8
is... not nice, I guess. Would it make more sense to make a shared function with a signature somewhat like the following to do all the dither instead?The text was updated successfully, but these errors were encountered: