예제 #1
0
def test_image_pixels():
    for filename in ["demo.jpg", "demo.png"]:
        image = RIMG.Load(os.path.join(autopath.this_dir, filename))
        assert image
        assert rffi.getintfield(image.c_format, 'c_BytesPerPixel') in (3, 4)
        RSDL.LockSurface(image)
        result = {}
        try:
            rgb = lltype.malloc(rffi.CArray(RSDL.Uint8), 3, flavor='raw')
            try:
                for y in range(23):
                    for x in range(y % 13, 17, 13):
                        color = RSDL_helper.get_pixel(image, x, y)
                        RSDL.GetRGB(color, image.c_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[x, y] = r, g, b
            finally:
                lltype.free(rgb, flavor='raw')
        finally:
            RSDL.UnlockSurface(image)
        RSDL.FreeSurface(image)
        for x, y in result:
            f = (x * 17 + y * 23) / float(17 * 17 + 23 * 23)
            expected_r = int(255.0 * (1.0 - f))
            expected_g = 0
            expected_b = int(255.0 * f)
            r, g, b = result[x, y]
            assert abs(r - expected_r) < 10
            assert abs(g - expected_g) < 10
            assert abs(b - expected_b) < 10
예제 #2
0
def update_screen(screen, paintpattern):
    fmt = screen.c_format
    white = RSDL.MapRGB(fmt, 255, 255, 255)
    black = RSDL.MapRGB(fmt, 0, 0, 0)
    RSDL.LockSurface(screen)
    pattern[paintpattern % pl](screen, black, white)
    RSDL.UnlockSurface(screen)
    RSDL.Flip(screen)
    RSDL.Delay(10)
예제 #3
0
 def test_bit_pattern(self):
     HEIGHT = WIDTH = 10
     fmt = self.screen.c_format
     white = RSDL.MapRGB(fmt, 255, 255, 255)
     black = RSDL.MapRGB(fmt, 0, 0, 0)
     RSDL.LockSurface(self.screen)
     for i in xrange(WIDTH):
         for j in xrange(HEIGHT):
             k = j*WIDTH + i
             if k % 2:
                 c = white
             else:
                 c = black
             RSDL_helper.set_pixel(self.screen, i, j, c)
     RSDL.UnlockSurface(self.screen)
     RSDL.Flip(self.screen)
     self.check("Upper left corner 10x10 field with vertical black/white stripes")
예제 #4
0
 def update_display(self):
     RSDL.LockSurface(self.screen)
     self.draw_pixels()
     RSDL.UnlockSurface(self.screen)
     RSDL.Flip(self.screen)