Skip to content

Commit 872c3dc

Browse files
committed
Port SDL_SetSurfaceRLE
1 parent c6d0877 commit 872c3dc

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

src_c/_pygame.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#define PG_PixelFormatEnum SDL_PixelFormat
8383

8484
#define PG_SurfaceHasRLE SDL_SurfaceHasRLE
85+
#define PG_SetSurfaceRLE SDL_SetSurfaceRLE
8586

8687
#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
8788
SDL_StretchSurface(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST)
@@ -350,6 +351,12 @@ PG_InitSubSystem(Uint32 flags)
350351

351352
#define PG_SurfaceHasRLE SDL_HasSurfaceRLE
352353

354+
static inline bool
355+
PG_SetSurfaceRLE(SDL_Surface *surface, bool enabled)
356+
{
357+
return SDL_SetSurfaceRLE(surface, enabled) == 0;
358+
}
359+
353360
static inline bool
354361
PG_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
355362
{

src_c/rotozoom.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ rotozoomSurface(SDL_Surface *src, double angle, double zoom, int smooth)
593593
SDL_FreeSurface(rz_dst);
594594
return NULL;
595595
}
596-
if (PG_SurfaceHasRLE(src) &&
597-
SDL_SetSurfaceRLE(rz_dst, SDL_TRUE) != 0) {
596+
if (PG_SurfaceHasRLE(src) && !PG_SetSurfaceRLE(rz_dst, SDL_TRUE)) {
598597
SDL_FreeSurface(rz_dst);
599598
return NULL;
600599
}
@@ -653,8 +652,7 @@ rotozoomSurface(SDL_Surface *src, double angle, double zoom, int smooth)
653652
SDL_FreeSurface(rz_dst);
654653
return NULL;
655654
}
656-
if (PG_SurfaceHasRLE(src) &&
657-
SDL_SetSurfaceRLE(rz_dst, SDL_TRUE) != 0) {
655+
if (PG_SurfaceHasRLE(src) && !PG_SetSurfaceRLE(rz_dst, SDL_TRUE)) {
658656
SDL_FreeSurface(rz_dst);
659657
return NULL;
660658
}

src_c/surface.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,9 +1442,8 @@ surf_set_colorkey(pgSurfaceObject *self, PyObject *args)
14421442
success = PG_SetSurfaceColorKey(surf, SDL_FALSE, color);
14431443
}
14441444
if (success && hascolor) {
1445-
success =
1446-
SDL_SetSurfaceRLE(
1447-
surf, (flags & PGS_RLEACCEL) ? SDL_TRUE : SDL_FALSE) == 0;
1445+
success = PG_SetSurfaceRLE(
1446+
surf, (flags & PGS_RLEACCEL) ? SDL_TRUE : SDL_FALSE);
14481447
}
14491448
if (success) {
14501449
success = PG_SetSurfaceColorKey(surf, hascolor, color);
@@ -1496,7 +1495,7 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args)
14961495
Uint32 flags = 0;
14971496
PyObject *alpha_obj = NULL, *intobj = NULL;
14981497
Uint8 alpha;
1499-
int result, alphaval = 255;
1498+
int alphaval = 255;
15001499
SDL_Rect sdlrect;
15011500
SDL_Surface *surface;
15021501

@@ -1544,8 +1543,8 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args)
15441543
}
15451544
}
15461545
pgSurface_Prep(self);
1547-
result =
1548-
SDL_SetSurfaceRLE(surf, (flags & PGS_RLEACCEL) ? SDL_TRUE : SDL_FALSE);
1546+
bool success =
1547+
PG_SetSurfaceRLE(surf, (flags & PGS_RLEACCEL) ? SDL_TRUE : SDL_FALSE);
15491548
/* HACK HACK HACK */
15501549
if ((surf->flags & SDL_RLEACCEL) && (!(flags & PGS_RLEACCEL))) {
15511550
/* hack to strip SDL_RLEACCEL flag off surface immediately when
@@ -1561,12 +1560,12 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args)
15611560
SDL_FreeSurface(surface);
15621561
}
15631562
/* HACK HACK HACK */
1564-
if (result == 0) {
1565-
result = !PG_SetSurfaceAlphaMod(surf, alpha);
1563+
if (success) {
1564+
success = PG_SetSurfaceAlphaMod(surf, alpha);
15661565
}
15671566
pgSurface_Unprep(self);
15681567

1569-
if (result != 0) {
1568+
if (!success) {
15701569
return RAISE(pgExc_SDLError, SDL_GetError());
15711570
}
15721571

src_c/transform.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
202202
SDL_FreeSurface(newsurf);
203203
return NULL;
204204
}
205-
if (PG_SurfaceHasRLE(surf) &&
206-
SDL_SetSurfaceRLE(newsurf, SDL_TRUE) != 0) {
205+
if (PG_SurfaceHasRLE(surf) && !PG_SetSurfaceRLE(newsurf, SDL_TRUE)) {
207206
PyErr_SetString(pgExc_SDLError, SDL_GetError());
208207
SDL_FreeSurface(newsurf);
209208
return NULL;

0 commit comments

Comments
 (0)