def test_pixels_alpha(self):
if not arraytype:
self.fail("no array package installed")
palette = [(0, 0, 0, 0),
(127, 127, 127, 0),
(127, 127, 127, 85),
(127, 127, 127, 170),
(127, 127, 127, 255)]
alphas = [0, 45, 86, 99, 180]
surf = self._make_src_surface(32, srcalpha=True, palette=palette)
self.failIf(surf.get_locked())
arr = pygame.surfarray.pixels_alpha(surf)
self.failUnless(surf.get_locked())
surf.unlock()
self.failUnless(surf.get_locked())
for (x, y), i in self.test_points:
self.failUnlessEqual(arr[x, y], palette[i][3])
for (x, y), i in self.test_points:
alpha = alphas[i]
arr[x, y] = alpha
color = (127, 127, 127, alpha)
self.failUnlessEqual(surf.get_at((x, y)), color,
"posn: (%i, %i)" % (x, y))
del arr
self.failIf(surf.get_locked())
self.failUnlessEqual(surf.get_locks(), ())
# Check exceptions.
def do_pixels_alpha(surf):
pygame.surfarray.pixels_alpha(surf)
targets = [(8, False),
(16, False),
(16, True),
(24, False),
(32, False)]
for bitsize, srcalpha in targets:
self.failUnlessRaises(ValueError, do_pixels_alpha,
self._make_surface(bitsize, srcalpha))
评论列表
文章目录