surfarray_test.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:Projects 作者: it2school 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号