/ Published in: ActionScript
Desaturates/Saturates a BMP
Expand |
Embed | Plain Text
// saturation libraries import flash.filters.BitmapFilter; import flash.filters.ColorMatrixFilter; // Turn an image (gradually) into a grayscale // t is a Number ranging from 0 == 100% saturation, full colors // to 1 == fully grayscale (is default) function getDesaturationFilter(t:Number):BitmapFilter{ t = t ? t : 1; // luminance coefficients as by Charles A. Poynton, 1997 // see point C-9 of http://www.faqs.org/faqs/graphics/colorspace-faq/ // alternative coefficients by Paul Haeberly :http://www.sgi.com/misc/grafica/matrix/ var r = 0.212671; var g = 0.715160; var b = 0.072169; return new ColorMatrixFilter( [t*r+1-t, t*g, t*b, 0, 0, t*r, t*g+1-t, t*b, 0, 0, t*r, t*g, t*b+1-t, 0, 0, 0, 0, 0, 1, 0]); } // saturation velocity var satInc:Number = 0.08; // saturates image function saturate(mc:MovieClip):Void{ // 1 = dsaturate // 0.01 saturate var sat = 1; mc.onEnterFrame = function(){ sat -= satInc; if(sat < 0.01){ sat = 0.01; // remove control delete mc.onEnterFrame; } mc.filters = new Array(getDesaturationFilter(sat)); }// enterframe } // desaturates image function desaturate(mc:MovieClip):Void{ // 1 = dsaturate // 0.1 saturate var sat = 0.1; mc.onEnterFrame = function(){ sat += satInc; if(sat > 1){ sat = 1; // remove control delete mc.onEnterFrame; } mc.filters = new Array(getDesaturationFilter(sat)); }// enterframe } // Usage function thumbOut():Void { desaturate(this.loader_MC); }
You need to login to post a comment.
