Skip to content

Commit 0eccffc

Browse files
committed
Port Get|SetSurfaceBlendMode int->bool return
1 parent 9e4941e commit 0eccffc

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

src_c/_pygame.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
132132

133133
#define PG_GetSurfacePalette SDL_GetSurfacePalette
134134
#define PG_SetPaletteColors SDL_SetPaletteColors
135+
#define PG_SetSurfaceBlendMode SDL_SetSurfaceBlendMode
136+
#define PG_GetSurfaceBlendMode SDL_GetSurfaceBlendMode
135137

136138
#define PG_GetRGBA SDL_GetRGBA
137139
#define PG_GetRGB SDL_GetRGB
@@ -241,6 +243,18 @@ PG_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
241243
return SDL_SetPaletteColors(palette, colors, firstcolor, ncolors) == 0;
242244
}
243245

246+
static inline bool
247+
PG_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode)
248+
{
249+
return SDL_SetSurfaceBlendMode(surface, blendMode) == 0;
250+
}
251+
252+
static inline bool
253+
PG_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode)
254+
{
255+
return SDL_GetSurfaceBlendMode(surface, blendMode) == 0;
256+
}
257+
244258
// NOTE:
245259
// palette is part of the format in SDL2, so these functions below have it
246260
// as a separate parameter to be consistent with the SDL3 signature.

src_c/alphablit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
127127
if ((info.src_has_colorkey = SDL_HasColorKey(src))) {
128128
SDL_GetColorKey(src, &info.src_colorkey);
129129
}
130-
if (SDL_GetSurfaceBlendMode(src, &info.src_blend) ||
131-
SDL_GetSurfaceBlendMode(dst, &info.dst_blend)) {
130+
if (!PG_GetSurfaceBlendMode(src, &info.src_blend) ||
131+
!PG_GetSurfaceBlendMode(dst, &info.dst_blend)) {
132132
okay = 0;
133133
}
134134
if (okay) {

src_c/pixelcopy.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,7 @@ _copy_colorplane(Py_buffer *view_p, SDL_Surface *surf,
287287
intsize);
288288
return -1;
289289
}
290-
#if SDL_VERSION_ATLEAST(3, 0, 0)
291-
if (!SDL_GetSurfaceBlendMode(surf, &mode))
292-
#else
293-
if (SDL_GetSurfaceBlendMode(surf, &mode) < 0)
294-
#endif
295-
{
290+
if (!PG_GetSurfaceBlendMode(surf, &mode)) {
296291
PyErr_SetString(pgExc_SDLError, SDL_GetError());
297292
return -1;
298293
}

src_c/surface.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,12 +1517,12 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args)
15171517
return RAISE(PyExc_TypeError, "invalid alpha argument");
15181518
}
15191519

1520-
if (SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_BLEND) != 0) {
1520+
if (!PG_SetSurfaceBlendMode(surf, SDL_BLENDMODE_BLEND)) {
15211521
return RAISE(pgExc_SDLError, SDL_GetError());
15221522
}
15231523
}
15241524
else {
1525-
if (SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE) != 0) {
1525+
if (!PG_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE)) {
15261526
return RAISE(pgExc_SDLError, SDL_GetError());
15271527
}
15281528
}
@@ -1539,7 +1539,7 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args)
15391539

15401540
if (alpha == 255 && (PG_SURF_BytesPerPixel(surf) == 1)) {
15411541
/* Can't blend with a surface alpha of 255 and 8bit surfaces */
1542-
if (SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE) != 0) {
1542+
if (!PG_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE)) {
15431543
return RAISE(pgExc_SDLError, SDL_GetError());
15441544
}
15451545
}
@@ -1582,7 +1582,7 @@ surf_get_alpha(pgSurfaceObject *self, PyObject *_null)
15821582

15831583
SURF_INIT_CHECK(surf)
15841584

1585-
if (SDL_GetSurfaceBlendMode(surf, &mode) != 0) {
1585+
if (!PG_GetSurfaceBlendMode(surf, &mode)) {
15861586
return RAISE(pgExc_SDLError, SDL_GetError());
15871587
}
15881588

@@ -1605,7 +1605,7 @@ surf_get_blendmode(PyObject *self, PyObject *_null)
16051605

16061606
SURF_INIT_CHECK(surf)
16071607

1608-
if (SDL_GetSurfaceBlendMode(surf, &mode) != 0) {
1608+
if (!PG_GetSurfaceBlendMode(surf, &mode)) {
16091609
return RAISE(pgExc_SDLError, SDL_GetError());
16101610
}
16111611
return PyLong_FromLong((long)mode);
@@ -2970,7 +2970,7 @@ static int
29702970
_PgSurface_SrcAlpha(SDL_Surface *surf)
29712971
{
29722972
SDL_BlendMode mode;
2973-
if (SDL_GetSurfaceBlendMode(surf, &mode) < 0) {
2973+
if (!PG_GetSurfaceBlendMode(surf, &mode)) {
29742974
PyErr_SetString(pgExc_SDLError, SDL_GetError());
29752975
return -1;
29762976
}

src_c/transform.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,7 @@ _PgSurface_SrcAlpha(SDL_Surface *surf)
9595
{
9696
if (SDL_ISPIXELFORMAT_ALPHA(PG_SURF_FORMATENUM(surf))) {
9797
SDL_BlendMode mode;
98-
#if SDL_VERSION_ATLEAST(3, 0, 0)
99-
if (!SDL_GetSurfaceBlendMode(surf, &mode))
100-
#else
101-
if (SDL_GetSurfaceBlendMode(surf, &mode) < 0)
102-
#endif
103-
{
98+
if (!PG_GetSurfaceBlendMode(surf, &mode)) {
10499
return -1;
105100
}
106101
if (mode == SDL_BLENDMODE_BLEND) {
@@ -181,7 +176,7 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
181176

182177
isalpha = _PgSurface_SrcAlpha(surf);
183178
if (isalpha == 1) {
184-
if (SDL_SetSurfaceBlendMode(newsurf, SDL_BLENDMODE_BLEND) != 0) {
179+
if (!PG_SetSurfaceBlendMode(newsurf, SDL_BLENDMODE_BLEND)) {
185180
PyErr_SetString(pgExc_SDLError, SDL_GetError());
186181
SDL_FreeSurface(newsurf);
187182
return NULL;
@@ -193,7 +188,7 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height)
193188
return NULL;
194189
}
195190
else {
196-
if (SDL_SetSurfaceBlendMode(newsurf, SDL_BLENDMODE_NONE) != 0) {
191+
if (!PG_SetSurfaceBlendMode(newsurf, SDL_BLENDMODE_NONE)) {
197192
PyErr_SetString(pgExc_SDLError, SDL_GetError());
198193
SDL_FreeSurface(newsurf);
199194
return NULL;

0 commit comments

Comments
 (0)