From: Mark B. <mb...@0x...> - 2000-04-07 00:59:28
|
On Wed, 05 Apr 2000, Ben Smith wrote: > My name is Ben Smith, I was attempting to write a SDL module for python as > well. It was an uphill battle for me, I'm new to python, and I've still > got a lot to learn about c, and trying to use the ExtensionClass for it. > I found this module today and it rules! I added a small patch that allows > you to manipulate the pixel buffer of an SDL surface in a 2d python array. There's a bit of a problem with your patch, and how it manipulates the surface's memory. Not all is lost, though, since I thought the idea was a fairly good one, and replaced the current sequence based system with something similar to what you've proposed. I'd been blindly and temporaraly treating the sequence of a surface as a linear chunk of memory. This needed to be changed sometime, and now is better than later, since the user base is smaller. Still it would be bad of me to change the interface many many times, so I'm going to go over the code and do whatever interface changes I plan on doing, now. I intend to move some of the -1 error code functions and methods, to using exceptions. Of course this won't be practiced everywhere, since the idea of SDL is to get fairly good performance, even though we're using Python. An example how the new sequence interface works: import sdl sdl.init(sdl.INIT_VIDEO) s = sdl.video_set_mode(100, 100, 16, sdl.SWSURFACE) s[0] = range(0, 100) s[1] = range(200, 300) s[2] = range(400, 500) x = s[0:3] s[3:6] = x s.update_rect((0, 0, 0, 0)) surface[y] returns a list of integers for the color of each x component surface[y1:y2] return a list of lists of integers from y1 to y2 (non-inclusive) You can also assign to these surface[y] = [1, 3, 5] surface[y] = range(0, 100) ... If the list you're assigning to the element of the surface is smaller than the width of the surface, then it just stops at the end of the list. It will always start at element zero of the surface. surface[y1:y2] = [[1, 2], [3, 4, 5, 6, 7]] surface[y1:y2] = [range(0, 100)] * 100 It behaves just like a single element assignment, in that if the list of lists is shorter than the slice, then it'll just stop at the end of the list of lists. Also each list can be shorter than the width of the surface, with the same behavior as if it were being assigned individually. I've also added get_at() and set_at() methods get_at(x, y) -> color set_at(x, y, pixel) -> None so surface.set_at(0, 0, surface.map_rgb(255, 255, 0)) would be ok I'd like to hear any interface suggestions, if anyone has any. |