surfarray_test.py 文件源码

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

项目:AIFun 作者: Plottel 项目源码 文件源码
def test_array2d(self):
        if not arraytype:
            self.fail("no array package installed")
        if arraytype == 'numeric':
            # This is known to fail with Numeric (incompatible
            # get_rgb and array element types).
            return

        sources = [self._make_src_surface(8),
                   self._make_src_surface(16),
                   self._make_src_surface(16, srcalpha=True),
                   self._make_src_surface(24),
                   self._make_src_surface(32),
                   self._make_src_surface(32, srcalpha=True)]
        palette = self.test_palette
        alpha_color = (0, 0, 0, 128)

        for surf in sources:
            arr = pygame.surfarray.array2d(surf)
            map_rgb = surf.map_rgb
            for (x, y), i in self.test_points:
                self.failUnlessEqual(arr[x, y], map_rgb(palette[i]),
                                     "%s != %s: flags: %i, bpp: %i, posn: %s" %
                                     (arr[x, y],
                                      map_rgb(palette[i]),
                                      surf.get_flags(), surf.get_bitsize(),
                                      (x, y)))

            if surf.get_masks()[3]:
                surf.fill(alpha_color)
                arr = pygame.surfarray.array2d(surf)
                self.failUnlessEqual(arr[0, 0], map_rgb(alpha_color),
                                     "%s != %s: bpp: %i" %
                                     (arr[0, 0],
                                      map_rgb(alpha_color),
                                      surf.get_bitsize()))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号