def test_map_array(self):
if not arraytype:
self.fail("no array package installed")
if not arraytype == 'numpy':
# This test would probably fail for Numeric
# (incompatible get_rgb and array element types
# and zero alpha for SRCALPHA surfaces).
return
arr3d = self._make_src_array3d(uint8)
targets = [self._make_surface(16),
self._make_surface(16, srcalpha=True),
self._make_surface(24),
self._make_surface(32),
self._make_surface(32, srcalpha=True)]
palette = self.test_palette
for surf in targets:
arr2d = pygame.surfarray.map_array(surf, arr3d)
for (x, y), i in self.test_points:
self.failUnlessEqual(arr2d[x, y], surf.map_rgb(palette[i]),
"%i != %i, bitsize: %i, flags: %i" %
(arr2d[x, y], surf.map_rgb(palette[i]),
surf.get_bitsize(), surf.get_flags()))
# Exception checks
def do_map_array(surf, arr):
pygame.surfarray.map_array(surf, arr)
self.failUnlessRaises(ValueError, do_map_array,
self._make_surface(32),
self._make_array2d(uint8))
评论列表
文章目录