I have two images:


I’d like to essentially ‘cut out’ the black shape from the texture tile so that I end up with something along these lines:

Except transparent around the shape. Is this possible using pygame? This example I had to create in GIMP.
Additionally, would it be too performance-heavy to do this for every frame for a few sprites in a real-time environment? (30+ frames per second)
I made a solution, however it is not the best either for speed either for beauty.
You can use double blitting with setting colorkeys for transparency. In that way the mask should have only two colors: black and white.
Note that you can’t use this for images with per pixel alpha (RGBA) only for RGB images.
Other restriction is that it is recommended that the size of the texture and the mask image is the same (if not you should use areas for blitting).
In words, step by step:
Code sample:
I recommend not to use jpg as mask because of its lossy format, I recommend bmp or png (bmp is better). Remember it not uses alpha so the edges won’t be anti-aliased so it is not a nice solution in 2010 🙂
Here is the screenshot of the result:

Edit:
Hi again,
I made some tests with the blitting with BLEND_ADD and the results was promising. Here is the code:
And the result:

With this solution you can get per pixel alpha texturing. Please note that the mask should be an image with alpha channel so jpg could not be used. The best to use is png.
Texture image (texture.jpg):

Mask image (mask2.png):
