[pypy-svn] r54866 - pypy/dist/pypy/rlib/rsdl

karlb at codespeak.net karlb at codespeak.net
Sat May 17 19:02:50 CEST 2008


Author: karlb
Date: Sat May 17 19:02:47 2008
New Revision: 54866

Added:
   pypy/dist/pypy/rlib/rsdl/RSDL_helper.py
Modified:
   pypy/dist/pypy/rlib/rsdl/RSDL.py
Log:
Added RSDL_helper module


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 19:02:47 2008
@@ -86,8 +86,11 @@
 MapRGB = external('SDL_MapRGB', [PixelFormatPtr, Uint8, Uint8, Uint8], Uint32)
 GetRGB = external('SDL_GetRGB', [Uint32, PixelFormatPtr,
                                  Uint8P, Uint8P, Uint8P], lltype.Void)
+GetRGBA = external('SDL_GetRGBA', [Uint32, PixelFormatPtr,
+                                 Uint8P, Uint8P, Uint8P, Uint8P], lltype.Void)
 FillRect = external('SDL_FillRect', [SurfacePtr, RectPtr, Uint32], rffi.INT)
 BlitSurface = external('SDL_UpperBlit', [SurfacePtr, RectPtr, SurfacePtr, RectPtr], rffi.INT)
+SetAlpha = external('SDL_SetAlpha', [SurfacePtr, Uint32, Uint8], rffi.INT)
 
 def getpixel(image, x, y):
     """Return the pixel value at (x, y)

Added: pypy/dist/pypy/rlib/rsdl/RSDL_helper.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rlib/rsdl/RSDL_helper.py	Sat May 17 19:02:47 2008
@@ -0,0 +1,38 @@
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rlib.rsdl import RSDL
+
+def get_rgb(color, format):
+    rgb = lltype.malloc(rffi.CArray(RSDL.Uint8), 3, flavor='raw')
+    try:
+        RSDL.GetRGB(color,
+                    format,
+                    rffi.ptradd(rgb, 0),
+                    rffi.ptradd(rgb, 1),
+                    rffi.ptradd(rgb, 2))
+        r = rffi.cast(lltype.Signed, rgb[0])
+        g = rffi.cast(lltype.Signed, rgb[1])
+        b = rffi.cast(lltype.Signed, rgb[2])
+        result = r, g, b
+    finally:
+        lltype.free(rgb, flavor='raw')
+
+    return result
+
+def get_rgba(color, format):
+    rgb = lltype.malloc(rffi.CArray(RSDL.Uint8), 4, flavor='raw')
+    try:
+        RSDL.GetRGBA(color,
+                    format,
+                    rffi.ptradd(rgb, 0),
+                    rffi.ptradd(rgb, 1),
+                    rffi.ptradd(rgb, 2),
+                    rffi.ptradd(rgb, 3))
+        r = rffi.cast(lltype.Signed, rgb[0])
+        g = rffi.cast(lltype.Signed, rgb[1])
+        b = rffi.cast(lltype.Signed, rgb[2])
+        a = rffi.cast(lltype.Signed, rgb[3])
+        result = r, g, b, a
+    finally:
+        lltype.free(rgb, flavor='raw')
+
+    return result



More information about the Pypy-commit mailing list