I was asked if my ColorMatrix Class can be used to change only a certain range of colors within a bitmap. Well, that's mathematically not possible, but nevertheless there is a way to make this work with Flash - it just needs a few more steps and some temporary helper bitmaps.
In short it works like this - if you only want to change the orange parts of an image you first isolate those parts by replacing all other colors with 100%transparent pixels, then you apply the ColorMatrix filter to it and finally draw it over the original bitmap.
Here is the part of the code that creates a mask from a given color range - as you see I'm using several consecutive threshold commands for every color channel.
mask.threshold( original, rect, zero, "<", rmin<<16,0,0x00ff0000,true); mask.threshold( mask, rect, zero, "<", gmin<<8,0,0x0000ff00,true); mask.threshold( mask, rect, zero, "<", bmin,0,0x000000ff,true); mask.threshold( mask, rect, zero, ">", rmax<<16,0,0x00ff0000,true); mask.threshold( mask, rect, zero, ">", gmax<<8,0,0x0000ff00,true); mask.threshold( mask, rect, zero, ">", bmax,0,0x000000ff,true); mask.threshold( mask, rect, zero, "==", 0xff000000,0xffffffff,0xff000000,true);
I have expanded the concept a bit and added a few tools to clean up and adjust the resulting mask. Check out the demo here:
Click on the middle color swatch and pick a color from the image that you want to change. With the range slider you can set the minimum and maximum color that is included in the selection. Upon start the range is set to maximum which means that all colors are included - move the silders to something like -20 / 20, select "mask" on the right side and you will see how it works. The shrink and grow sliders are used to remove noisy pixels or to fill small holes inside of the mask. For example if you have many stray single pixels use "shrink" with a small value to get rid of them.
The shrink and grow algorithms are quite heavy on the CPU with big radii so usually it's best to only use them with small values.
Download the source code here



