More Than Meets the Eye
Posted by caseyrayl on April 11, 2007
I decided to continue my image theme from my last post. This time though I am going to talk about some interesting transformations I just did to some BitmapData objects. The most esoteric (for me) color transformations involved moving from RGB color to black & white (also called desaturation) or sepia. I accomplished this via the applyFilter function of the BitmapData object and passed it unique ColorMatrixFilters. The exact values within the matrices are the real trick here. Behold!
Black and White ColorMatrixFilter matrix:
(r_lum, g_lum, b_lum, 0, 0,
r_lum, g_lum, b_lum, 0, 0,
r_lum, g_lum, b_lum, 0, 0,
0 , 0 , 0 , 1, 0)
Where
r_lum = 0.212671;
g_lum = 0.715160;
b_lum = 0.072169;
OR
r_lum = 0.3086;
g_lum = 0.6094;
b_lum = 0.0820;
The selection of the “luminance vector” value will likely depend on your renderer, but it seems Flash likes the first more.
And the sepia ColorMatrixFilter matrix:
(0.393 , 0.749 , 0.189 , 0.0 , 0.0 ,
0.349 , 0.686 , 0.168 , 0.0 , 0.0 ,
0.272 , 0.534 , 0.131 , 0.0 , 0.0 ,
0.0 , 0.0 , 0.0 , 1.0 , 1.0)
If you are interested in a very dynamic color transformation utility, a class in AS2 that implements some cool functionality (in a very AS3 convertible form) is the ColorMatrix class by Quasimondo.