I try to make a function to colorize image - desaturate and replace dark color with supplied RGB color.
I have found similar function from Mario Klingemann AS3 ColorMatrix library, which replace light color while preserving dark.
public function colorize(rgb:int, amount:Number=1):void
{
const LUMA_R:Number = 0.212671;
const LUMA_G:Number = 0.71516;
const LUMA_B:Number = 0.072169;
var r:Number;
var g:Number;
var b:Number;
var inv_amount:Number;
r = (((rgb >> 16) & 0xFF) / 0xFF);
g = (((rgb >> 8) & 0xFF) / 0xFF);
b = ((rgb & 0xFF) / 0xFF);
inv_amount = (1 - amount);
concat([(inv_amount + ((amount * r) * LUMA_R)), ((amount * r) * LUMA_G), ((amount * r) * LUMA_B), 0, 0,
((amount * g) * LUMA_R), (inv_amount + ((amount * g) * LUMA_G)), ((amount * g) * LUMA_B), 0, 0,
((amount * b) * LUMA_R), ((amount * b) * LUMA_G), (inv_amount + ((amount * b) * LUMA_B)), 0, 0,
0, 0, 0, 1, 0]);
}
I tried to modify the matrix but with no success. Please could you provide me any help or link to information or code that make me move forward a bit.
You could try to use the method above, but before you apply it you invert the image and the color. Then after applying the matrix, you invert the image again.