ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pygame-users
pygame-users
RE: [pygame] Question about .bmp files and transparency
by =?iso-8859-1?Q?Erlend_Str=F8msvik?= other posts by this author
Sep 10 2003 6:52AM messages near this date
Re: [pygame] Question about .bmp files and transparency | 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@[...].org [mailto:owner-pygame-users@[...].org]
On Behalf Of Pete Shinners
Sent: 10. september 2003 06:25
To: pygame-users@[...].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]
Thread:
Pete Shinners
Ricardo Quesada
caffeine@tuxfamily.org
=?ISO-8859-1?Q?Nicol=E1s_Ech=E1niz?=
=?iso-8859-1?Q?Erlend_Str=F8msvik?=
SB
=?iso-8859-1?Q?Erlend_Str=F8msvik?=
Pete Shinners
=?iso-8859-1?Q?Erlend_Str=F8msvik?=
Pete Shinners
R. Alan Monroe
Fredrik Johansson
bob@threeoh.com
Pete Shinners
bob@threeoh.com
Caffeine@Tuxfamily.Org

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved