[pypy-svn] r54848 - in pypy/dist/pypy/rlib/rsdl: . test
karlb at codespeak.net
karlb at codespeak.net
Sat May 17 17:40:55 CEST 2008
Author: karlb
Date: Sat May 17 17:40:54 2008
New Revision: 54848
Modified:
pypy/dist/pypy/rlib/rsdl/RSDL.py
pypy/dist/pypy/rlib/rsdl/test/test_video.py
Log:
Added support for RSDL.BlitRect
Modified: pypy/dist/pypy/rlib/rsdl/RSDL.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/RSDL.py (original)
+++ pypy/dist/pypy/rlib/rsdl/RSDL.py Sat May 17 17:40:54 2008
@@ -84,7 +84,7 @@
GetRGB = external('SDL_GetRGB', [Uint32, PixelFormatPtr,
Uint8P, Uint8P, Uint8P], lltype.Void)
FillRect = external('SDL_FillRect', [SurfacePtr, RectPtr, Uint32], rffi.INT)
-
+BlitSurface = external('SDL_UpperBlit', [SurfacePtr, RectPtr, SurfacePtr, RectPtr], rffi.INT)
def getpixel(image, x, y):
"""Return the pixel value at (x, y)
Modified: pypy/dist/pypy/rlib/rsdl/test/test_video.py
==============================================================================
--- pypy/dist/pypy/rlib/rsdl/test/test_video.py (original)
+++ pypy/dist/pypy/rlib/rsdl/test/test_video.py Sat May 17 17:40:54 2008
@@ -18,8 +18,8 @@
py.test.skip("'--view' not specified, "
"skipping tests that open a window")
assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
- self.surface = RSDL.SetVideoMode(640, 480, 32, 0)
- assert self.surface
+ self.screen = RSDL.SetVideoMode(640, 480, 32, 0)
+ assert self.screen
def check(self, msg):
if sys.stdout.isatty():
@@ -34,14 +34,37 @@
pass # only checks that opening and closing the window works
def test_fillrect_full(self):
- fmt = self.surface.c_format
+ fmt = self.screen.c_format
for colorname, r, g, b in [('dark red', 128, 0, 0),
('yellow', 255, 255, 0),
('blue', 0, 0, 255)]:
color = RSDL.MapRGB(fmt, r, g, b)
- RSDL.FillRect(self.surface, lltype.nullptr(RSDL.Rect), color)
- RSDL.Flip(self.surface)
+ RSDL.FillRect(self.screen, lltype.nullptr(RSDL.Rect), color)
+ RSDL.Flip(self.screen)
self.check("Screen filled with %s" % colorname)
+ def test_blit_rect(self):
+ surface = RSDL.CreateRGBSurface(0, 150, 50, 32,
+ r_uint(0x000000FF),
+ r_uint(0x0000FF00),
+ r_uint(0x00FF0000),
+ r_uint(0xFF000000))
+ fmt = surface.c_format
+ color = RSDL.MapRGB(fmt, 255, 0, 0)
+ RSDL.FillRect(surface, lltype.nullptr(RSDL.Rect), color)
+ dstrect = lltype.malloc(RSDL.Rect, flavor='raw')
+ try:
+ rffi.setintfield(dstrect, 'c_x', 10)
+ rffi.setintfield(dstrect, 'c_y', 10)
+ rffi.setintfield(dstrect, 'c_w', 150)
+ rffi.setintfield(dstrect, 'c_h', 50)
+ RSDL.BlitSurface(surface, lltype.nullptr(RSDL.Rect), self.screen, dstrect)
+ RSDL.Flip(self.screen)
+ finally:
+ lltype.free(dstrect, flavor='raw')
+ RSDL.FreeSurface(surface)
+ self.check("Red rectangle(150px * 50px) at the top left, 10 pixels from the border")
+
def teardown_method(self, meth):
RSDL.Quit()
+
More information about the Pypy-commit
mailing list