Skip to content

Commit b145d4d

Browse files
authored
Merge pull request #3464 from oddbookworm/fix-transform-regression
Fix palettes in `newsurf_fromsurf`
2 parents 4b6303a + b30397e commit b145d4d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src_c/transform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
136136
/* Copy palette, colorkey, etc info */
137137
if (SDL_ISPIXELFORMAT_INDEXED(PG_SURF_FORMATENUM(surf))) {
138138
SDL_Palette *newsurf_palette = PG_GetSurfacePalette(newsurf);
139-
SDL_Palette *surf_palette = PG_GetSurfacePalette(newsurf);
139+
SDL_Palette *surf_palette = PG_GetSurfacePalette(surf);
140140

141141
if (newsurf_palette == NULL) {
142142
PyErr_SetString(

test/transform_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,39 @@ def test_rotate__lossless_at_90_degrees(self):
14491449
for pt, color in gradient:
14501450
self.assertTrue(s.get_at(pt) == color)
14511451

1452+
def test_rotate_after_convert_regression(self):
1453+
# Tests a regression found from https://github.com/pygame-community/pygame-ce/pull/3314
1454+
# Reported in https://github.com/pygame-community/pygame-ce/issues/3463
1455+
1456+
pygame.display.set_mode((1, 1))
1457+
1458+
output1 = pygame.transform.rotate(
1459+
pygame.image.load(
1460+
os.path.join(
1461+
os.path.abspath(os.path.dirname(__file__)),
1462+
"../examples/data/alien1.png",
1463+
)
1464+
).convert_alpha(),
1465+
180,
1466+
)
1467+
output2 = pygame.transform.rotate(
1468+
pygame.image.load(
1469+
os.path.join(
1470+
os.path.abspath(os.path.dirname(__file__)),
1471+
"../examples/data/alien1.png",
1472+
)
1473+
),
1474+
180,
1475+
).convert_alpha()
1476+
1477+
for x in range(50):
1478+
for y in range(50):
1479+
color1 = pygame.Color(output1.get_at((x, y)))
1480+
color2 = pygame.Color(output2.get_at((x, y)))
1481+
self.assertEqual(color1, color2)
1482+
1483+
pygame.quit()
1484+
14521485
def test_scale2x(self):
14531486
# __doc__ (as of 2008-06-25) for pygame.transform.scale2x:
14541487

0 commit comments

Comments
 (0)