jnordberg / gif.js

JavaScript GIF encoding library
http://jnordberg.github.io/gif.js/
MIT License
4.76k stars 668 forks source link

Dithering #12

Open PAEz opened 10 years ago

PAEz commented 10 years ago

Still haven't got around to trying your stuff (web workers are tomorrow), but thought you might like a look at this.... https://dl.dropboxusercontent.com/u/3610419/JsGifStuff/Dithering.zip ...I did dithering! Ive been looking around getting stuff for gif in js and was amazed no one had dithering so looked into it and found some nice AS to convert (the urls to the originals are in the source if you want to check my work). Makes a real nice difference on gradients. Sorry bout the awful test code ;) Im still in mucking around mode so I just throw what ever I need in there ;) You want to look at the Bitmap.prototype.dither function at the end of dither.js. Sorry bout the odd Bitmap class aswell ;) was just meant to give me something to work with and I know its odd.

Also while Im here, have a real good look at rgbQuant..it can do a MUCH better job than the other one alot of the time....dont give a dam if its slower....Im trying to get lots of options and they can decide if they want quick renders or production renders.

PAEz commented 10 years ago

Updated the above link. The speed was awful and figured it was due to the looking for the closest color when putting a pixel into the indexed data so made it cache the previous finds and that speed it up ALOT. If they used every color in the spectrum thats gonna be one HUGE lookup table tho...memory or speed....speed!

By the way, I only test my stuff in Chrome.

PAEz commented 10 years ago

Sorry but the original code was broken....thought it was but its so hard to tell with out something working to compare it against.
But the new version totally works! And its got serpentining now, which is that it will alternate between going left to right and right to left when doing the kernel on alternating lines. This can hide some of the pattern some times and other times false is better.
Check out the screenshot, how nice is that dithering :P http://jsbin.com/iXofIji/2/edit jsdither

jnordberg commented 10 years ago

Thanks! This will be a really helpful reference when implementing dithering in gif.js