def test_map_array_newbuf(self): array2D = self.Array2D([0] * 15) elements = [i + (255 - i << 8) + (99 << 16) for i in range(0,15)] array3D = self.Array3D(elements) map_array(array2D, array3D, self.surface) for x in range(0, 3): for y in range(0, 5): p = array3D[x, y, 0], array3D[x, y, 1], array3D[x, y, 2] self.assertEqual(self.surface.unmap_rgb(array2D[x, y]), p)
def test_map_array(self): targets = [ self._make_surface(8), self._make_surface(16), self._make_surface(16, srcalpha=True), self._make_surface(24), self._make_surface(32), self._make_surface(32, srcalpha=True), ] source = pygame.Surface(self.surf_size, 0, 24, masks=[0xFF, 0xFF00, 0xFF0000, 0]) self._fill_surface(source) source_view = source.get_view("3") # (w, h, 3) for t in targets: map_array(t.get_view("2"), source_view, t) for posn, i in self.test_points: sc = t.map_rgb(source.get_at(posn)) dc = t.get_at_mapped(posn) self.assertEqual( dc, sc, "%s != %s: flags: %i" ", bpp: %i, posn: %s" % (dc, sc, t.get_flags(), t.get_bitsize(), posn), ) color = pygame.Color("salmon") color.set_length(3) for t in targets: map_array(t.get_view("2"), color, t) sc = t.map_rgb(color) for posn, i in self.test_points: dc = t.get_at_mapped(posn) self.assertEqual( dc, sc, "%s != %s: flags: %i" ", bpp: %i, posn: %s" % (dc, sc, t.get_flags(), t.get_bitsize(), posn), ) # mismatched shapes w, h = source.get_size() target = pygame.Surface((w, h + 1), 0, 32) self.assertRaises(ValueError, map_array, target, source, target) target = pygame.Surface((w - 1, h), 0, 32) self.assertRaises(ValueError, map_array, target, source, target)
def test_map_array(self): targets = [self._make_surface(8), self._make_surface(16), self._make_surface(16, srcalpha=True), self._make_surface(24), self._make_surface(32), self._make_surface(32, srcalpha=True), ] source = pygame.Surface(self.surf_size, 0, 24, masks=[0xff, 0xff00, 0xff0000, 0]) self._fill_surface(source) source_view = source.get_view('3') # (w, h, 3) for t in targets: map_array(t.get_view('2'), source_view, t) for posn, i in self.test_points: sc = t.map_rgb(source.get_at(posn)) dc = t.get_at_mapped(posn) self.assertEqual(dc, sc, "%s != %s: flags: %i" ", bpp: %i, posn: %s" % (dc, sc, t.get_flags(), t.get_bitsize(), posn)) color = pygame.Color("salmon") color.set_length(3) for t in targets: map_array(t.get_view('2'), color, t) sc = t.map_rgb(color) for posn, i in self.test_points: dc = t.get_at_mapped(posn) self.assertEqual(dc, sc, "%s != %s: flags: %i" ", bpp: %i, posn: %s" % (dc, sc, t.get_flags(), t.get_bitsize(), posn)) # mismatched shapes w, h = source.get_size() target = pygame.Surface((w, h + 1), 0, 32) self.assertRaises(ValueError, map_array, target, source, target) target = pygame.Surface((w - 1, h), 0, 32) self.assertRaises(ValueError, map_array, target, source, target)
def test_map_array(self): try: from numpy import array, zeros, uint8, int32, alltrue except ImportError: return surf = pygame.Surface((1, 1), 0, 32) # color fill color = array([11, 17, 59], uint8) target = zeros((5, 7), int32) map_array(target, color, surf) self.assertTrue(alltrue(target == surf.map_rgb(color))) # array column stripes stripe = array([[2, 5, 7], [11, 19, 23], [37, 53, 101]], uint8) target = zeros((4, stripe.shape[0]), int32) map_array(target, stripe, surf) target_stripe = array([surf.map_rgb(c) for c in stripe], int32) self.assertTrue(alltrue(target == target_stripe)) # array row stripes stripe = array([[[2, 5, 7]], [[11, 19, 24]], [[10, 20, 30]], [[37, 53, 101]]], uint8) target = zeros((stripe.shape[0], 3), int32) map_array(target, stripe, surf) target_stripe = array([[surf.map_rgb(c)] for c in stripe[:,0]], int32) self.assertTrue(alltrue(target == target_stripe)) # mismatched shape w = 4 h = 5 source = zeros((w, h, 3), uint8) target = zeros((w,), int32) self.assertRaises(ValueError, map_array, target, source, surf) source = zeros((12, w, h + 1), uint8) self.assertRaises(ValueError, map_array, target, source, surf) source = zeros((12, w - 1, 5), uint8) self.assertRaises(ValueError, map_array, target, source, surf)
def test_map_array(self): try: from numpy import array, zeros, uint8, int32, alltrue except ImportError: return surf = pygame.Surface((1, 1), 0, 32) # color fill color = array([11, 17, 59], uint8) target = zeros((5, 7), int32) map_array(target, color, surf) self.assert_(alltrue(target == surf.map_rgb(color))) # array column stripes stripe = array([[2, 5, 7], [11, 19, 23], [37, 53, 101]], uint8) target = zeros((4, stripe.shape[0]), int32) map_array(target, stripe, surf) target_stripe = array([surf.map_rgb(c) for c in stripe], int32) self.assert_(alltrue(target == target_stripe)) # array row stripes stripe = array([[[2, 5, 7]], [[11, 19, 24]], [[10, 20, 30]], [[37, 53, 101]]], uint8) target = zeros((stripe.shape[0], 3), int32) map_array(target, stripe, surf) target_stripe = array([[surf.map_rgb(c)] for c in stripe[:,0]], int32) self.assert_(alltrue(target == target_stripe)) # mismatched shape w = 4 h = 5 source = zeros((w, h, 3), uint8) target = zeros((w,), int32) self.assertRaises(ValueError, map_array, target, source, surf) source = zeros((12, w, h + 1), uint8) self.assertRaises(ValueError, map_array, target, source, surf) source = zeros((12, w - 1, 5), uint8) self.assertRaises(ValueError, map_array, target, source, surf)