[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
RE: [pygame] Question about .bmp files and transparency
Hi
Thanks for the lesson. :)
As for the pixel loop I find it easier working with when trying to
figure out how things worked and it's a bit easier writing out specific
test data. I planned to take a closer look at Numeric today. But no need
for that now, your code is like a million times faster :p
The blending I get from this code is better IMO than adding a alpha
layer to a .png image using Paintshop Pro (don't own Photoshop or any
other image processing program)
Next goal will be the terrain. -One must have some terrain which one
can blow sky high! :)
Most likely I will have to use pixel comparison here (with 'Numeric
wizardry' ;) and the fastest thing might be to test on the terrains
alpha layer? I'm not sure but it doesn't seem too stupid... :-|
When a bullet is fired, I could calculate the trajectory at once, so
I'll know where the bullet -should- explode and not having to do pixel
tests inside the bullet update loop.
Another thing.. Are there any specific reason for having a mailinglist
and not forum/message board(s)?
-erlend
-----Original Message-----
From: owner-pygame-users@seul.org [mailto:owner-pygame-users@seul.org]
On Behalf Of Pete Shinners
Sent: 10. september 2003 06:25
To: pygame-users@seul.org
Subject: 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]