Recently on Flashcoders the question came up if it is possible to mask JPEGs based on a color value, similar to GIFs where one color can be reserved for transparency. Well, I created a little application based on my image-to-pixelinfo script that demonstrates the possiblities. You can upload an image and pick a color range that should be masked or un-masked.
On my machine this runs faster than I expected first based on whats actually happening behind the scenes. The current approach I would call brute force attack: The code traverses line by line through the image and checks if the current pixel has a color in the mask range or not. If yes it draws a pixel-sized rectangle at that position. I use a tiny optimization already: Horizontally neighbored mask pixels are combined into one long rectangle. Still the optimum code that I could imagine would be a kind of tracing routine that follows the surface of the masked areas. The question is what would be faster and how to do that.Posted at September 28, 2002 07:24 PM | Further reading