Flood fill / trace image outline?


I need to extract RectangleLists / Paths / regions from a 16-color PNG that's used as a collision mask definition. Image::createSolidAreaMask() works great but I need something non-alpha based (chroma key?) to extract the sub-regions. I couldn't find a flood fill - is there some color remapping function I missed? This happens at load time so it''s not performance critical.

thx & cheers,

-- p


Hi petah, I think the use case for such a flood fill is too limited to include into JUCE. I think there should be plenty of sample code out there to show how this could be done. For example wikipedia has this: http://en.wikipedia.org/wiki/Flood_fill#The_algorithm


yeah I'm just starting to learn juce so still poking around to see what's built-in.

I realized accessing Image pixels is really easy so wrote my own layer separator based on createSolidAreaMask(). One question though, how do you write a zero alpha pixel with Graphics? say you want an existing opaque area to "poke-through"?

Have to say, all in all Juce is really impressive!


-- p


That's not possible with Graphics - that class is all about compositing, and it may not even be drawing to a destination that has an alpha channel.

You can clear pixels in an Image directly though, with Image::setPixelAt


I see. Cairo has way too many compostiting operator but the basic ones are useful.

Maybe it wouldn't require all that much complexity in Juce if you had an internal compositor template function so some Graphics member functions could be instantiated for different compositing modes?

thx for listening,

-- p


No, it wouldn't make any sense for Graphics to offer that kind of functionality, but as I said you can do what you need to do by working directly on the image's pixels.