def test_make_surface(self):
if not arraytype:
self.fail("no array package installed")
# How does one properly test this with 2d arrays. It makes no sense
# since the pixel format is not entirely dependent on element size.
# Just make sure the surface pixel size is at least as large as the
# array element size I guess.
#
for bitsize, dtype in [(8, uint8), (16, uint16), (24, uint32)]:
## Even this simple assertion fails for 2d arrays. Where's the problem?
## surf = pygame.surfarray.make_surface(self._make_array2d(dtype))
## self.failUnless(surf.get_bitsize() >= bitsize,
## "not %i >= %i)" % (surf.get_bitsize(), bitsize))
##
surf = pygame.surfarray.make_surface(self._make_src_array3d(dtype))
self._assert_surface(surf)
# Issue #81: round from float to int
try:
rint
except NameError:
pass
else:
w = 9
h = 11
length = w * h
for dtype in [float32, float64]:
farr = arange(0, length, dtype=dtype)
farr.shape = w, h
surf = pygame.surfarray.make_surface(farr)
for x in range(w):
for y in range(h):
self.assertEqual(surf.get_at_mapped((x, y)),
int(rint(farr[x, y])))
评论列表
文章目录