In a nutshell I have two images I want to overlay one over the other using a mask so that only parts of the second image show up. This is part of a real time image processing routine so I need the operation to happen as fast as possible.
Specifically, I have two 32 bit image BGR byte arrays. In addition, I have a byte array that represents an image mask.
I want to generate a new byte array where byte array A is overlayed on top of byte array B using the mask array to decide which byte is used.
What is the quickest way to do this?
I was looking at this wikipedia article about old fashioned sprite masking but I am not sure how to best translate this to C#. http://en.wikipedia.org/wiki/Mask_(computing)
EDIT: I forgot to mention that I can restruct any or all of this to make it run faster.
In principle, masking like this is very simple – assuming the arrays are the same size, this code would do it:
In a reality this will be quite a bit more complicated – your background is likely to be larger than whatever foreground image you’re masking onto it, and you’ll have to do some arithmetic to place it properly. While tedious to get right, it’s not hard.