Skip to content

Commit cf7adab

Browse files
committed
Port Get|SetSurfaceAlphaMod int->bool return
1 parent 0eccffc commit cf7adab

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src_c/_pygame.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
134134
#define PG_SetPaletteColors SDL_SetPaletteColors
135135
#define PG_SetSurfaceBlendMode SDL_SetSurfaceBlendMode
136136
#define PG_GetSurfaceBlendMode SDL_GetSurfaceBlendMode
137+
#define PG_GetSurfaceAlphaMod SDL_GetSurfaceAlphaMod
138+
#define PG_SetSurfaceAlphaMod SDL_SetSurfaceAlphaMod
137139

138140
#define PG_GetRGBA SDL_GetRGBA
139141
#define PG_GetRGB SDL_GetRGB
@@ -255,6 +257,18 @@ PG_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
255257
return SDL_GetSurfaceBlendMode(surface, blendMode) == 0;
256258
}
257259

260+
static inline bool
261+
PG_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha)
262+
{
263+
return SDL_GetSurfaceAlphaMod(surface, alpha) == 0;
264+
}
265+
266+
static inline bool
267+
PG_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
268+
{
269+
return SDL_SetSurfaceAlphaMod(surface, alpha) == 0;
270+
}
271+
258272
// NOTE:
259273
// palette is part of the format in SDL2, so these functions below have it
260274
// as a separate parameter to be consistent with the SDL3 signature.

src_c/surface.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,11 +1562,11 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args)
15621562
}
15631563
/* HACK HACK HACK */
15641564
if (result == 0) {
1565-
result = SDL_SetSurfaceAlphaMod(surf, alpha);
1565+
result = !PG_SetSurfaceAlphaMod(surf, alpha);
15661566
}
15671567
pgSurface_Unprep(self);
15681568

1569-
if (result == -1) {
1569+
if (result != 0) {
15701570
return RAISE(pgExc_SDLError, SDL_GetError());
15711571
}
15721572

@@ -1590,7 +1590,7 @@ surf_get_alpha(pgSurfaceObject *self, PyObject *_null)
15901590
Py_RETURN_NONE;
15911591
}
15921592

1593-
if (SDL_GetSurfaceAlphaMod(surf, &alpha) != 0) {
1593+
if (!PG_GetSurfaceAlphaMod(surf, &alpha)) {
15941594
return RAISE(pgExc_SDLError, SDL_GetError());
15951595
}
15961596

@@ -3245,13 +3245,13 @@ surf_subsurface(PyObject *self, PyObject *args)
32453245
}
32463246
SDL_FreePalette(pal);
32473247
}
3248-
if (SDL_GetSurfaceAlphaMod(surf, &alpha) != 0) {
3248+
if (!PG_GetSurfaceAlphaMod(surf, &alpha)) {
32493249
PyErr_SetString(pgExc_SDLError, SDL_GetError());
32503250
SDL_FreeSurface(sub);
32513251
return NULL;
32523252
}
32533253
if (alpha != 255) {
3254-
if (SDL_SetSurfaceAlphaMod(sub, alpha) != 0) {
3254+
if (!PG_SetSurfaceAlphaMod(sub, alpha)) {
32553255
PyErr_SetString(pgExc_SDLError, SDL_GetError());
32563256
SDL_FreeSurface(sub);
32573257
return NULL;
@@ -4515,7 +4515,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
45154515
/* can't blit alpha to 8bit, crashes SDL */
45164516
else if (PG_SURF_BytesPerPixel(dst) == 1 &&
45174517
(SDL_ISPIXELFORMAT_ALPHA(PG_SURF_FORMATENUM(src)) ||
4518-
((SDL_GetSurfaceAlphaMod(src, &alpha) == 0 && alpha != 255)))) {
4518+
((PG_GetSurfaceAlphaMod(src, &alpha) && alpha != 255)))) {
45194519
/* Py_BEGIN_ALLOW_THREADS */
45204520
if (PG_SURF_BytesPerPixel(src) == 1) {
45214521
result = pygame_Blit(src, srcrect, dst, dstrect, 0);

src_c/transform.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ _PgSurface_SrcAlpha(SDL_Surface *surf)
104104
}
105105
else {
106106
Uint8 color = SDL_ALPHA_OPAQUE;
107-
if (SDL_GetSurfaceAlphaMod(surf, &color) != 0) {
107+
if (!PG_GetSurfaceAlphaMod(surf, &color)) {
108108
return -1;
109109
}
110110
if (color != SDL_ALPHA_OPAQUE) {
@@ -161,13 +161,13 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
161161
}
162162
}
163163

164-
if (SDL_GetSurfaceAlphaMod(surf, &alpha) != 0) {
164+
if (!PG_GetSurfaceAlphaMod(surf, &alpha)) {
165165
PyErr_SetString(pgExc_SDLError, SDL_GetError());
166166
SDL_FreeSurface(newsurf);
167167
return NULL;
168168
}
169169
if (alpha != 255) {
170-
if (SDL_SetSurfaceAlphaMod(newsurf, alpha) != 0) {
170+
if (!PG_SetSurfaceAlphaMod(newsurf, alpha)) {
171171
PyErr_SetString(pgExc_SDLError, SDL_GetError());
172172
SDL_FreeSurface(newsurf);
173173
return NULL;

0 commit comments

Comments
 (0)