Commits

timfel  committed c419533

(jlincke, timfel) Add a test for blitting surface from pixelbuffer

  • Participants
  • Parent commits 5c7bcc8

Comments (0)

Files changed (1)

File rsdl/test/test_video.py

         RSDL.FreeSurface(surface)
         self.check("Half Red/Orange rectangle(150px * 50px) at the top left, 10 pixels from the border")
 
+
+    def test_blit_pxrect(self):
+        max  = 150 * 50
+        surfacepx = lltype.malloc(rffi.VOIDP.TO, max * 4, flavor='raw')
+        pos = 0
+        for i in xrange(max):
+            surfacepx[pos]     = chr(int(float(i) / max * 255))
+            surfacepx[pos + 1] = chr(int(float(i) / max * 255))
+            surfacepx[pos + 2] = chr(int(float(i) / max * 255))
+            surfacepx[pos + 3] = chr(255)
+            pos += 4
+
+        pitch = 4 * 150 # 4 byte per line * width
+        surface = RSDL.CreateRGBSurfaceFrom(surfacepx, 150, 50, 32, pitch,
+                                            r_uint(0x000000FF),
+                                            r_uint(0x0000FF00),
+                                            r_uint(0x00FF0000),
+                                            r_uint(0xFF000000))
+
+        dstrect = RSDL_helper.mallocrect(0, 0, 150, 50)
+        try:
+            RSDL.BlitSurface(surface, lltype.nullptr(RSDL.Rect), self.screen, dstrect)
+            RSDL.Flip(self.screen)
+        finally:
+            lltype.free(dstrect, flavor='raw')
+        RSDL.FreeSurface(surface)
+        lltype.free(surfacepx, flavor='raw')
+        self.check("Gradient from black to white rectangle(150px * 50px) at the top left")
+
     def teardown_method(self, meth):
         RSDL.Quit()