bro
This commit is contained in:
1 parent
de41a02749
commit
9af09cebd3
764 files changed
+54218
-78859
No files matched your search
@@ -15,6 +15,7 @@ except NameError:
|
||||
|
||||
import pygame
|
||||
|
||||
|
||||
IS_PYPY = "PyPy" == platform.python_implementation()
|
||||
|
||||
|
||||
@@ -307,7 +308,7 @@ class PixelArrayTypeTest(unittest.TestCase, TestMixin):
|
||||
self.assertFalse(sf.get_locked())
|
||||
|
||||
def test_as_class(self):
|
||||
# Check general new-style class features.
|
||||
# Check general new-style class freatures.
|
||||
sf = pygame.Surface((2, 3), 0, 32)
|
||||
ar = pygame.PixelArray(sf)
|
||||
self.assertRaises(AttributeError, getattr, ar, "nonnative")
|
||||
@@ -669,7 +670,7 @@ class PixelArrayTypeTest(unittest.TestCase, TestMixin):
|
||||
self.assertEqual(refcnts_after, refcnts_before)
|
||||
|
||||
def test_subscript(self):
|
||||
# By default, we do not need to work with any special __***__
|
||||
# By default we do not need to work with any special __***__
|
||||
# methods as map subscripts are the first looked up by the
|
||||
# object system.
|
||||
for bpp in (8, 16, 24, 32):
|
||||
@@ -1019,6 +1020,7 @@ class PixelArrayTypeTest(unittest.TestCase, TestMixin):
|
||||
self.assertEqual(iterations, 5)
|
||||
|
||||
def test_replace(self):
|
||||
# print("replace start")
|
||||
for bpp in (8, 16, 24, 32):
|
||||
sf = pygame.Surface((10, 10), 0, bpp)
|
||||
sf.fill((255, 0, 0))
|
||||
@@ -1039,8 +1041,10 @@ class PixelArrayTypeTest(unittest.TestCase, TestMixin):
|
||||
self.assertEqual(ar[3][6], oval)
|
||||
self.assertEqual(ar[8][9], oval)
|
||||
self.assertEqual(ar[9][9], oval)
|
||||
# print("replace end")
|
||||
|
||||
def test_extract(self):
|
||||
# print("extract start")
|
||||
for bpp in (8, 16, 24, 32):
|
||||
sf = pygame.Surface((10, 10), 0, bpp)
|
||||
sf.fill((0, 0, 255))
|
||||
@@ -1066,6 +1070,7 @@ class PixelArrayTypeTest(unittest.TestCase, TestMixin):
|
||||
self.assertEqual(newar[3][6], white)
|
||||
self.assertEqual(newar[8][9], black)
|
||||
self.assertEqual(newar[9][9], black)
|
||||
# print("extract end")
|
||||
|
||||
def test_2dslice_assignment(self):
|
||||
w = 2 * 5 * 8
|
||||
@@ -1229,7 +1234,7 @@ class PixelArrayTypeTest(unittest.TestCase, TestMixin):
|
||||
|
||||
def test_transpose(self):
|
||||
# PixelArray.transpose(): swap axis on a 2D array, add a length
|
||||
# 1 x-axis to a 1D array.
|
||||
# 1 x axis to a 1D array.
|
||||
sf = pygame.Surface((3, 7), 0, 32)
|
||||
ar = pygame.PixelArray(sf)
|
||||
w, h = ar.shape
|
||||
@@ -1304,113 +1309,6 @@ class PixelArrayTypeTest(unittest.TestCase, TestMixin):
|
||||
pixel = sf.get_at_mapped((0, 0))
|
||||
self.assertEqual(repr(ar), type(ar).__name__ + "([\n [42, 42, 42]]\n)")
|
||||
|
||||
def test_zero_size_surface(self):
|
||||
"""Should not be able to create PixelArray on a surface with a width or height of 0
|
||||
Regression test for pygame-ce issue 2275 (https://github.com/pygame-community/pygame-ce/issues/2275)
|
||||
"""
|
||||
weird_surface = pygame.Surface((5, 0))
|
||||
self.assertRaises(ValueError, lambda: pygame.PixelArray(weird_surface))
|
||||
|
||||
weird_surface = pygame.Surface((0, 5))
|
||||
self.assertRaises(ValueError, lambda: pygame.PixelArray(weird_surface))
|
||||
|
||||
def test_assign_seq_to_single(self):
|
||||
"""
|
||||
Regression test for https://github.com/pygame-community/pygame-ce/issues/2740
|
||||
This usage should ValueError and not segfault (as list is to be interpreted as
|
||||
pixel sequence, and not color)
|
||||
"""
|
||||
test = pygame.PixelArray(pygame.Surface([800, 800]))
|
||||
with self.assertRaises(ValueError):
|
||||
test[400][400] = [255, 255, 0]
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
test[400, 400] = [255, 255, 0]
|
||||
|
||||
def test_set_pixel_24bit_formats(self):
|
||||
"""Pixel assignment must write the correct channels on both RGB24 and BGR24.
|
||||
|
||||
On little-endian systems, RGB24 has Rmask=0xFF (R at byte 0) while the
|
||||
default pygame.Surface(..., 24) produces BGR24 (Rmask=0xFF0000, R at
|
||||
byte 2). The old _array_assign_index code assumed the mapped color was
|
||||
always 0x00RRGGBB, which silently worked for BGR24 but swapped R and B
|
||||
for RGB24.
|
||||
"""
|
||||
color = (200, 100, 50)
|
||||
masks_and_names = [
|
||||
((0xFF, 0xFF00, 0xFF0000, 0), "RGB24"),
|
||||
((0xFF0000, 0xFF00, 0xFF, 0), "BGR24"),
|
||||
]
|
||||
for masks, name in masks_and_names:
|
||||
with self.subTest(format=name):
|
||||
sf = pygame.Surface((4, 4), depth=24, masks=masks)
|
||||
sf.fill((0, 0, 0))
|
||||
ar = pygame.PixelArray(sf)
|
||||
ar[1][2] = color
|
||||
del ar
|
||||
self.assertEqual(sf.get_at((1, 2))[:3], color)
|
||||
|
||||
def test_set_slice_24bit_formats(self):
|
||||
"""Slice assignment with a single color must write correctly on RGB24 and BGR24."""
|
||||
color = (200, 100, 50)
|
||||
masks_and_names = [
|
||||
((0xFF, 0xFF00, 0xFF0000, 0), "RGB24"),
|
||||
((0xFF0000, 0xFF00, 0xFF, 0), "BGR24"),
|
||||
]
|
||||
for masks, name in masks_and_names:
|
||||
with self.subTest(format=name):
|
||||
sf = pygame.Surface((4, 4), depth=24, masks=masks)
|
||||
sf.fill((0, 0, 0))
|
||||
ar = pygame.PixelArray(sf)
|
||||
ar[0:2] = color
|
||||
del ar
|
||||
self.assertEqual(sf.get_at((0, 0))[:3], color)
|
||||
self.assertEqual(sf.get_at((1, 3))[:3], color)
|
||||
self.assertEqual(sf.get_at((2, 0))[:3], (0, 0, 0))
|
||||
|
||||
def test_set_sequence_24bit_formats(self):
|
||||
"""Slice assignment with a color list must write correctly on RGB24 and BGR24."""
|
||||
color_a = (200, 100, 50)
|
||||
color_b = (10, 20, 30)
|
||||
masks_and_names = [
|
||||
((0xFF, 0xFF00, 0xFF0000, 0), "RGB24"),
|
||||
((0xFF0000, 0xFF00, 0xFF, 0), "BGR24"),
|
||||
]
|
||||
for masks, name in masks_and_names:
|
||||
with self.subTest(format=name):
|
||||
sf = pygame.Surface((4, 4), depth=24, masks=masks)
|
||||
sf.fill((0, 0, 0))
|
||||
ar = pygame.PixelArray(sf)
|
||||
ar[0:2] = [color_a, color_b]
|
||||
del ar
|
||||
self.assertEqual(sf.get_at((0, 0))[:3], color_a)
|
||||
self.assertEqual(sf.get_at((1, 0))[:3], color_b)
|
||||
|
||||
def test_replace_24bit_formats(self):
|
||||
"""PixelArray.replace must match and write the correct channels on RGB24 and BGR24."""
|
||||
old_color = (200, 100, 50)
|
||||
new_color = (10, 20, 30)
|
||||
masks_and_names = [
|
||||
((0xFF, 0xFF00, 0xFF0000, 0), "RGB24"),
|
||||
((0xFF0000, 0xFF00, 0xFF, 0), "BGR24"),
|
||||
]
|
||||
for masks, name in masks_and_names:
|
||||
with self.subTest(format=name):
|
||||
sf = pygame.Surface((4, 4), depth=24, masks=masks)
|
||||
sf.fill(old_color)
|
||||
ar = pygame.PixelArray(sf)
|
||||
ar.replace(old_color, new_color)
|
||||
del ar
|
||||
self.assertEqual(sf.get_at((0, 0))[:3], new_color)
|
||||
self.assertEqual(sf.get_at((3, 3))[:3], new_color)
|
||||
|
||||
# distance-based variant
|
||||
sf.fill(old_color)
|
||||
ar = pygame.PixelArray(sf)
|
||||
ar.replace(old_color, new_color, distance=0.1)
|
||||
del ar
|
||||
self.assertEqual(sf.get_at((0, 0))[:3], new_color)
|
||||
|
||||
|
||||
@unittest.skipIf(IS_PYPY, "pypy having issues")
|
||||
class PixelArrayArrayInterfaceTest(unittest.TestCase, TestMixin):
|
||||
@@ -1542,9 +1440,11 @@ class PixelArrayArrayInterfaceTest(unittest.TestCase, TestMixin):
|
||||
self.assert_surfaces_equal(sf3, sf2)
|
||||
|
||||
|
||||
@unittest.skipIf(not pygame.HAVE_NEWBUF, "newbuf not implemented")
|
||||
@unittest.skipIf(IS_PYPY, "pypy having issues")
|
||||
class PixelArrayNewBufferTest(unittest.TestCase, TestMixin):
|
||||
from pygame.tests.test_utils import buftools
|
||||
if pygame.HAVE_NEWBUF:
|
||||
from pygame.tests.test_utils import buftools
|
||||
|
||||
bitsize_to_format = {8: "B", 16: "=H", 24: "3x", 32: "=I"}
|
||||
|
||||
|
||||
Reference in new issue
Block a user