|
18 | 18 | import gc |
19 | 19 | import weakref |
20 | 20 | import ctypes |
| 21 | +import itertools |
21 | 22 |
|
22 | 23 | IS_PYPY = "PyPy" == platform.python_implementation() |
23 | 24 |
|
@@ -1060,6 +1061,41 @@ def test_blit__SRCALPHA32_to_8(self): |
1060 | 1061 | source.set_at((0, 0), test_color) |
1061 | 1062 | target.blit(source, (0, 0)) |
1062 | 1063 |
|
| 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 | + |
1063 | 1099 |
|
1064 | 1100 | class GeneralSurfaceTests(unittest.TestCase): |
1065 | 1101 | @unittest.skipIf( |
|
0 commit comments