Skip to content

Commit ad13d70

Browse files
committed
Add unit test
1 parent bae2047 commit ad13d70

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/surface_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import gc
1919
import weakref
2020
import ctypes
21+
import itertools
2122

2223
IS_PYPY = "PyPy" == platform.python_implementation()
2324

@@ -1060,6 +1061,41 @@ def test_blit__SRCALPHA32_to_8(self):
10601061
source.set_at((0, 0), test_color)
10611062
target.blit(source, (0, 0))
10621063

1064+
def test_blit__SCALPHA32_TO_OPAQUE32(self):
1065+
# Apparently these types of blits need to write 0 to the destination's
1066+
# alpha channel (it's not really an alpha channel but it's treated like one)
1067+
# See https://github.com/pygame-community/pygame-ce/pull/2067
1068+
1069+
alphas = [0, 10, 50, 122, 240, 255]
1070+
1071+
combinations = list(itertools.combinations_with_replacement(alphas, 2))
1072+
width = len(combinations)
1073+
1074+
# masks explicitly specified so direct pixel access of bytes below is
1075+
# gauranteed to be stable
1076+
surf1 = pygame.Surface((width, 1), depth=32, masks=(0xFF0000, 0xFF00, 0xFF, 0))
1077+
surf2 = pygame.Surface(
1078+
(width, 1),
1079+
pygame.SRCALPHA,
1080+
depth=32,
1081+
masks=(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
1082+
)
1083+
1084+
for i in range(width):
1085+
alpha1, alpha2 = combinations[i]
1086+
surf1.set_at((i, 0), (0, 0, 0, alpha1))
1087+
surf2.set_at((i, 0), (0, 0, 0, alpha2))
1088+
1089+
surf1.blit(surf2, (0, 0))
1090+
1091+
# Why use get_buffer?
1092+
# get_at for RGBX surfaces seems to always think A=255, regardless
1093+
# of bytes in surface, which makes sense.
1094+
surf1_bytes = surf1.get_buffer().raw
1095+
for i in range(width):
1096+
# +3 gets the "alpha channel" in this pixel format
1097+
assert surf1_bytes[i * 4 + 3] == 0
1098+
10631099

10641100
class GeneralSurfaceTests(unittest.TestCase):
10651101
@unittest.skipIf(

0 commit comments

Comments
 (0)