Actually, I don't need it in realtime. I can pre-process it. But I'm doing lots of stuff, so I need all my processes to be as fast as possible, as it adds up.
I guess I will be able to make it a bit faster by using the values of any of the channels of the mask as lookup table, to speed things a bit.