def test_rgba_argb_to_color(self): self.assertEqual(color.RGBA, color.rgba_to_color) self.assertEqual(color.ARGB, color.argb_to_color) assertEqual = self.assertEqual assertNotEqual = self.assertNotEqual cvals = list(color_combos()) for index, val in enumerate(rgba_combos()): c = cvals[index] if c.r == c.g == c.b == c.a: assertEqual(color.RGBA(val), c) assertEqual(color.ARGB(val), c) continue assertEqual(color.RGBA(val), c, "Failed for '%s'" % val) assertNotEqual(color.ARGB(val), c, "Failed for '0x%.8x'" % val) for index, val in enumerate(argb_combos()): c = cvals[index] if c.r == c.g == c.b == c.a: assertEqual(color.RGBA(val), c) assertEqual(color.ARGB(val), c) continue assertEqual(color.ARGB(val), c, "Failed for '%s'" % val) assertNotEqual(color.RGBA(val), c, "Failed for '0x%.8x'" % val)
def test_rgba_argb_to_color(self): assert color.RGBA == color.rgba_to_color assert color.ARGB == color.argb_to_color cvals = list(color_combos()) for index, val in enumerate(rgba_combos()): c = cvals[index] if c.r == c.g == c.b == c.a: assert color.RGBA(val) == c assert color.ARGB(val) == c continue assert color.RGBA(val) == c, "Failed for '%s'" % val assert not color.ARGB(val) == c, "Failed for '0x%.8x'" % val for index, val in enumerate(argb_combos()): c = cvals[index] if c.r == c.g == c.b == c.a: assert color.RGBA(val) == c assert color.ARGB(val) == c continue assert color.ARGB(val) == c, "Failed for '%s'" % val assert not color.RGBA(val) == c, "Failed for '0x%.8x'" % val
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