Skip to content
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

Fix RLE usage in the transform module #2535

Merged
merged 20 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
33 changes: 17 additions & 16 deletions src_c/rotozoom.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@
*/

#include "_pygame.h"

#if !SDL_VERSION_ATLEAST(2, 0, 14)
SDL_bool
PG_SurfaceHasRLE(SDL_Surface *surface)
{
if (surface == NULL) {
return SDL_FALSE;
}

if (!(surface->map->info.flags & SDL_COPY_RLE_DESIRED)) {
return SDL_FALSE;
}

return SDL_TRUE;
}
#endif
#define NO_PYGAME_C_API
#include "pygame.h"

Expand All @@ -48,6 +32,23 @@ typedef struct tColorRGBA {
#define M_PI 3.141592654
#endif

#if !SDL_VERSION_ATLEAST(2, 0, 14)
// Remove this when our minimum version is 2.0.14 or larger
SDL_bool
PG_SurfaceHasRLE(SDL_Surface *surface)
{
if (surface == NULL) {
return SDL_FALSE;
}

if (!(surface->map->info.flags & SDL_COPY_RLE_DESIRED)) {
return SDL_FALSE;
}

return SDL_TRUE;
}
#endif
ankith26 marked this conversation as resolved.
Show resolved Hide resolved

/*

32bit Zoomer with optional anti-aliasing by bilinear interpolation.
Expand Down
7 changes: 6 additions & 1 deletion src_c/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
}

if (SDL_GetColorKey(surf, &colorkey) == 0) {
if (SDL_SetColorKey(newsurf, SDL_TRUE, colorkey) != 0 ||
if (SDL_SetColorKey(newsurf, SDL_TRUE, colorkey) != 0) {
PyErr_SetString(pgExc_SDLError, SDL_GetError());
SDL_FreeSurface(newsurf);
return NULL;
}
if (PG_SurfaceHasRLE(surf) &&
SDL_SetSurfaceRLE(newsurf, SDL_TRUE) != 0) {
PyErr_SetString(pgExc_SDLError, SDL_GetError());
SDL_FreeSurface(newsurf);
Expand Down
14 changes: 14 additions & 0 deletions test/transform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,20 @@ def test_flip_alpha(self):
self.assertEqual(surf.get_at((0, 0)), surf2.get_at((0, 0)))
self.assertEqual(surf2.get_at((0, 0)), (255, 0, 0, 255))

def test_unwanted_rle_not_added(self):
surf = pygame.Surface((16, 16))
surf.fill((255, 0, 0))
surf.set_colorkey((0, 0, 0))
surf.set_alpha(64)

# scale it to the same size (size doesn't matter here)
scaled_surf = pygame.transform.scale(surf, (16, 16))
pygame.Surface((100, 100)).blit(scaled_surf, (0, 0))

self.assertEqual(
surf.get_flags() & pygame.RLEACCEL, scaled_surf.get_flags() & pygame.RLEACCEL)
self.assertEqual(scaled_surf.get_at((8, 8)), (255, 0, 0, 255))


if __name__ == "__main__":
unittest.main()
Loading