def test_pixels3d(self): colors = { 'red': color.Color(255, 0, 0, 255), 'blue': color.Color(0, 0, 255, 255), 'black': color.Color(0, 0, 0, 255), 'white': color.Color(255, 255, 255, 255) } rgba = pixels.SDL_PIXELFORMAT_ABGR8888 # Import test image, convert to RGBA, and open pixels3d view imgsurf = surface.SDL_LoadBMP(self.testfile.encode("utf-8")) imgsurf = surface.SDL_ConvertSurfaceFormat(imgsurf.contents, rgba, 0) with pytest.warns(sdl2ext.compat.ExperimentalWarning): nparray = sdl2ext.pixels3d(imgsurf.contents, transpose=False) assert nparray.shape == (32, 32, 4) # Test different coordinates on surface assert color.Color(*nparray[0][0]) == colors['red'] assert color.Color(*nparray[0][16]) == colors['blue'] assert color.Color(*nparray[0][31]) == colors['white'] assert color.Color(*nparray[31][31]) == colors['black'] # Try modifying surface, test if changes persist grey = [128, 128, 128, 255] nparray[31][0][:] = grey with pytest.warns(sdl2ext.compat.ExperimentalWarning): nparray2 = sdl2ext.pixels3d(imgsurf.contents, transpose=False) assert color.Color(*nparray2[31][0]) == color.Color(*grey)
def test_BitmapFont_can_render(self): sf = surface.SDL_LoadBMP( byteify(RESOURCES.get_path("font.bmp"), "utf-8")) self.assertIsInstance(sf.contents, surface.SDL_Surface) font = sdl2ext.BitmapFont(sf, (32, 32), FONTMAP) self.assertIsInstance(font, sdl2ext.BitmapFont) self.assertTrue(font.can_render("text")) self.assertTrue(font.can_render("473285435hfsjadfhriuewtrhefd")) self.assertFalse(font.can_render("testä"))
def test_BitmapFont_contains(self): sf = surface.SDL_LoadBMP( byteify(RESOURCES.get_path("font.bmp"), "utf-8")) self.assertIsInstance(sf.contents, surface.SDL_Surface) font = sdl2ext.BitmapFont(sf, (32, 32), FONTMAP) self.assertIsInstance(font, sdl2ext.BitmapFont) for ch in "abcde12345.-,+": self.assertTrue(font.contains(ch)) for ch in "äöüß": self.assertFalse(font.contains(ch))
def test_BitmapFont(self): sf = surface.SDL_LoadBMP( byteify(RESOURCES.get_path("font.bmp"), "utf-8")) self.assertIsInstance(sf.contents, surface.SDL_Surface) font = sdl2ext.BitmapFont(sf, (32, 32), FONTMAP) self.assertIsInstance(font, sdl2ext.BitmapFont) sprite = sdl2ext.SoftwareSprite(sf.contents, True) self.assertIsInstance(sprite, sdl2ext.SoftwareSprite) font = sdl2ext.BitmapFont(sprite, (32, 32), FONTMAP) self.assertIsInstance(font, sdl2ext.BitmapFont)
def test_pixels2d(self): colors = { 'red': color.Color(255, 0, 0, 255), 'blue': color.Color(0, 0, 255, 255), 'black': color.Color(0, 0, 0, 255), 'white': color.Color(255, 255, 255, 255) } # Import test image, convert to RGBA, and open pixels2d view imgsurf = surface.SDL_LoadBMP(self.testfile.encode("utf-8")) with pytest.warns(sdl2ext.compat.ExperimentalWarning): nparray = sdl2ext.pixels2d(imgsurf.contents, transpose=False) assert nparray.shape == (32, 32) # Test different coordinates on surface assert color.ARGB(nparray[0][0]) == colors['red'] assert color.ARGB(nparray[0][16]) == colors['blue'] assert color.ARGB(nparray[0][31]) == colors['white'] assert color.ARGB(nparray[31][31]) == colors['black'] # Try modifying surface, test if changes persist nparray[31][0] = 0xFF808080 # medium grey in ARGB with pytest.warns(sdl2ext.compat.ExperimentalWarning): nparray2 = sdl2ext.pixels2d(imgsurf.contents, transpose=False) assert nparray2[31][0] == 0xFF808080
def test_SDL_LoadBMP(self): imgsurface = surface.SDL_LoadBMP(self.testfile.encode("utf-8")) self.assertIsInstance(imgsurface.contents, surface.SDL_Surface) surface.SDL_FreeSurface(imgsurface)