[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Question about .bmp files and transparency
Erlend Strømsvik wrote:
the original game you most likely uses 'addative' blending for the
explosions. this sort of blending looks fantastic for smoke and fire
effects, but it not at all supported by SDL.
since this 'add' blending just adds the two colors together, any black
pixels have no effect on the other image. therefore no need for alpha.
and now for some Numeric wizardry lessons ;)
as for your code, using Numeric we can do this sort of thing without
needing to loop "pixel by pixel" in python. here's something that
should be similar and considerable faster (hopefully, an email type-in
here). also note by using the "pixels" instead of "array" functions we
are modifying the image 'in-place' and no longer need the blit_array
function at the end
if needalpha == 1:
colors = surfarray.pixels3d(surface)
alphas = surfarray.pixels_alpha(surface)
r = colors[:,:,0]
g = colors[:,:,1]
b = colors[:,:,2]
alphas[:] = r | g | b
or, if you prefer the 'packed pixel' method, you can still do it all
without a pixel by pixel loop.
if needalpha == 1:
masks = surface.get_masks()
shifts = surface.get_shifts()
losses = surface.get_losses()
pixels = surfarray.pixels2d(surface)
r = (pixels&masks[0]) >> shifts[0]
g = (pixels&masks[1]) >> shifts[1]
b = (pixels&masks[2]) >> shifts[2]
a = r | g | b
pixels |= a >> losses[3] << shifts[3]