GianlucaGuarini / jQuery.BlackAndWhite

Clientside grayscale images on any browser
http://gianlucaguarini.github.io/jQuery.BlackAndWhite/
Other
310 stars 131 forks source link

Desaturation intensity #34

Closed marceloinxs closed 11 years ago

marceloinxs commented 11 years ago

Great piece of code :)

I made a little change that I think might be useful to add to the plugin. Sometimes you simply don't want to desaturate the image completely.

Assuming intensity is a plugin variable:

for (; i < length; i += 4) {
     var k = px[i] * 0.3 + px[i + 1] * 0.59 + px[i + 2] * 0.11;
     px[i] = Math.floor(k * intensity + px[i] * (1 - intensity));
     px[i + 1] = Math.floor(k * intensity + px[i+1] * (1 - intensity));
     px[i + 2] = Math.floor(k * intensity + px[i+2] * (1 - intensity));
}
GianlucaGuarini commented 11 years ago

Wow great idea.. I will update my code as soon as possible releasing a new version of the plugin. Thank you so much

GianlucaGuarini commented 11 years ago

The new feature is available in the new release, thank you for your help ;-)

marceloinxs commented 11 years ago

:-D