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 Pete Shinners other posts by this author
Sep 10 2003 4:24AM messages near this date
RE: [pygame] Question about .bmp files and transparency | 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