From: <pe...@fo...> - 2000-07-03 22:15:01
|
we'll i did write up a simple numpy and pysdl binding and it worked out to be turbo-fast. my flame tests ran at twice the speed from the version using numpy, but with no quick way to xfer that to the surface data. while not fully featured, my little binding simply adds a new member to all the surface objects, named "pixels" so now surface.pixels[20,20] lets you access pixel at 20,20 this was an incredibly simple addition (just a couple lines of code) anyways, like i mentioned the flame demo ran at twice the speed. there was also this mentioned... >But I tried drawing simple gradients in a Python loop.. >I can make a beautiful Wise Installer/Power Point cheesy >blue blend in about... 20-30 seconds. here is a simple numpy example of creating a blue gradient and putting it into a surface. this example fills a 640x480 surface in about .05 seconds (1/17th) def fill_blue_gradient(surf): w = surf.get_width() h = surf.get_height() bloss = surf.get_losses()[3] bshift = surf.get_shifts()[3] #create vertical stripe ramp = arange(0, 255, 255.0/h, Int) #convert to surface colorspace ramp = ramp >> bloss << bshift #make 2 dimensional ramp = resize(ramp, (h, w)) #assign to surface #with my private unofficial pysdl&numpy bind surf.pixels[:] = transpose(ramp) anyways, i think with the numpy extensions pythin --CAN-- be used for pixel manipulating type routines we were expecting to be "C" side only. (stuff like transparant sprite collision detection is a snap) as far as scaling images go, SDL does have some "SoftStretch" scaling routines, but i was told not to use them as they will be removed once a real version of "scaling" is implemented (one that allows for hardware acceleration) fortunately, numpy again offers a quick enough way to do 2X image scaling for now. (until SDL does it "right") def double_image(src, dst): "dst must be at least big enough for 2xsrc" w = src.get_width()*2 h = src.get_height()*2 dst.pixels[0:w:2,0:h:2] = dst.pixels[1:w:2,0:h:2] = src.pixels[:] dst.pixels[:,1:h:2] = dst.pixels[:,0:h:2] the other feature i want before i "submit" is the ability to create a 3D array of the surface, with width and height being 2 of them, and each color plane (and alpha) being the 3rd dimension. essentially this wouldn't be too different than now but it will handle the "map_rgb" type stuff much more efficiently in the "C" loops. the transfer would also be "free" (as in no speed hit) on 24 and 32 bit surfaces anyways, i know it comes off a little 'intimidating' at first glance, but with numpy you can do amazingly complex operations with needing loops in python. (thus, all the speed) i'm looking for last suggestions/ideas as i wrap this thing up i'm also planning on writing a couple examples (like cleaning up the flame) as well as a small tutorial. let me know if there's any ideas you'd like to see ! :] ..argh Diablo2 is leeching all my time, heh |