|
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 |
|
@@ -1084,6 +1085,41 @@ def test_blit__SRCALPHA32_to_8(self):
|
1084 | 1085 | source.set_at((0, 0), test_color)
|
1085 | 1086 | target.blit(source, (0, 0))
|
1086 | 1087 |
|
| 1088 | + def test_blit__SCALPHA32_TO_OPAQUE32(self): |
| 1089 | + # Apparently these types of blits need to write 0 to the destination's |
| 1090 | + # alpha channel (it's not really an alpha channel but it's treated like one) |
| 1091 | + # See https://github.com/pygame-community/pygame-ce/pull/2067 |
| 1092 | + |
| 1093 | + alphas = [0, 10, 50, 122, 240, 255] |
| 1094 | + |
| 1095 | + combinations = list(itertools.combinations_with_replacement(alphas, 2)) |
| 1096 | + width = len(combinations) |
| 1097 | + |
| 1098 | + # masks explicitly specified so direct pixel access of bytes below is |
| 1099 | + # gauranteed to be stable |
| 1100 | + surf1 = pygame.Surface((width, 1), depth=32, masks=(0xFF0000, 0xFF00, 0xFF, 0)) |
| 1101 | + surf2 = pygame.Surface( |
| 1102 | + (width, 1), |
| 1103 | + pygame.SRCALPHA, |
| 1104 | + depth=32, |
| 1105 | + masks=(0xFF0000, 0xFF00, 0xFF, 0xFF000000), |
| 1106 | + ) |
| 1107 | + |
| 1108 | + for i in range(width): |
| 1109 | + alpha1, alpha2 = combinations[i] |
| 1110 | + surf1.set_at((i, 0), (0, 0, 0, alpha1)) |
| 1111 | + surf2.set_at((i, 0), (0, 0, 0, alpha2)) |
| 1112 | + |
| 1113 | + surf1.blit(surf2, (0, 0)) |
| 1114 | + |
| 1115 | + # Why use get_buffer? |
| 1116 | + # get_at for RGBX surfaces seems to always think A=255, regardless |
| 1117 | + # of bytes in surface, which makes sense. |
| 1118 | + surf1_bytes = surf1.get_buffer().raw |
| 1119 | + for i in range(width): |
| 1120 | + # +3 gets the "alpha channel" in this pixel format |
| 1121 | + assert surf1_bytes[i * 4 + 3] == 0 |
| 1122 | + |
1087 | 1123 |
|
1088 | 1124 | class GeneralSurfaceTests(unittest.TestCase):
|
1089 | 1125 | @unittest.skipIf(
|
|
0 commit comments