Skip to content

Fix palettes in newsurf_fromsurf #3464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src_c/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
/* Copy palette, colorkey, etc info */
if (SDL_ISPIXELFORMAT_INDEXED(PG_SURF_FORMATENUM(surf))) {
SDL_Palette *newsurf_palette = PG_GetSurfacePalette(newsurf);
SDL_Palette *surf_palette = PG_GetSurfacePalette(newsurf);
SDL_Palette *surf_palette = PG_GetSurfacePalette(surf);

if (newsurf_palette == NULL) {
PyErr_SetString(
Expand Down
33 changes: 33 additions & 0 deletions test/transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,39 @@ def test_rotate__lossless_at_90_degrees(self):
for pt, color in gradient:
self.assertTrue(s.get_at(pt) == color)

def test_rotate_after_convert_regression(self):
# Tests a regression found from https://github.com/pygame-community/pygame-ce/pull/3314
# Reported in https://github.com/pygame-community/pygame-ce/issues/3463

pygame.display.set_mode((1, 1))

output1 = pygame.transform.rotate(
pygame.image.load(
os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"../examples/data/alien1.png",
)
).convert_alpha(),
180,
)
output2 = pygame.transform.rotate(
pygame.image.load(
os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"../examples/data/alien1.png",
)
),
180,
).convert_alpha()

for x in range(50):
for y in range(50):
color1 = pygame.Color(output1.get_at((x, y)))
color2 = pygame.Color(output2.get_at((x, y)))
self.assertEqual(color1, color2)

pygame.quit()

def test_scale2x(self):
# __doc__ (as of 2008-06-25) for pygame.transform.scale2x:

Expand Down
Loading