Skip to content

Commit 64b626d

Browse files
committed
SDL3: image+scrap+transform+debug: runtime fixes
1 parent 853eb58 commit 64b626d

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

src_c/image.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -454,17 +454,10 @@ tobytes_surf_32bpp(SDL_Surface *surf, SDL_PixelFormat *format_details,
454454
{
455455
int w, h;
456456

457-
#if SDL_VERSION_ATLEAST(3, 0, 0)
458-
Uint32 Rloss = format_details->Rbits;
459-
Uint32 Gloss = format_details->Gbits;
460-
Uint32 Bloss = format_details->Bbits;
461-
Uint32 Aloss = format_details->Abits;
462-
#else
463-
Uint32 Rloss = format_details->Rloss;
464-
Uint32 Gloss = format_details->Gloss;
465-
Uint32 Bloss = format_details->Bloss;
466-
Uint32 Aloss = format_details->Aloss;
467-
#endif
457+
Uint32 Rloss = PG_FORMAT_R_LOSS(format_details);
458+
Uint32 Gloss = PG_FORMAT_G_LOSS(format_details);
459+
Uint32 Bloss = PG_FORMAT_B_LOSS(format_details);
460+
Uint32 Aloss = PG_FORMAT_A_LOSS(format_details);
468461
Uint32 Rmask = format_details->Rmask;
469462
Uint32 Gmask = format_details->Gmask;
470463
Uint32 Bmask = format_details->Bmask;
@@ -565,19 +558,15 @@ image_tobytes(PyObject *self, PyObject *arg, PyObject *kwarg)
565558
if (!format_details) {
566559
return RAISE(pgExc_SDLError, SDL_GetError());
567560
}
568-
SDL_Palette *surf_palette = SDL_GetSurfacePalette(surf);
569-
Rloss = format_details->Rbits;
570-
Gloss = format_details->Gbits;
571-
Bloss = format_details->Bbits;
572-
Aloss = format_details->Abits;
561+
SDL_Palette *surf_palette = PG_GetSurfacePalette(surf);
573562
#else
574563
SDL_PixelFormat *format_details = surf->format;
575564
SDL_Palette *surf_palette = surf->format->palette;
576-
Rloss = format_details->Rloss;
577-
Gloss = format_details->Gloss;
578-
Bloss = format_details->Bloss;
579-
Aloss = format_details->Aloss;
580565
#endif
566+
Rloss = PG_FORMAT_R_LOSS(format_details);
567+
Gloss = PG_FORMAT_G_LOSS(format_details);
568+
Bloss = PG_FORMAT_B_LOSS(format_details);
569+
Aloss = PG_FORMAT_A_LOSS(format_details);
581570
Rmask = format_details->Rmask;
582571
Gmask = format_details->Gmask;
583572
Bmask = format_details->Bmask;
@@ -1722,7 +1711,7 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle)
17221711
}
17231712
SDL_PixelFormat output_format;
17241713

1725-
SDL_Palette *surf_palette = SDL_GetSurfacePalette(surface);
1714+
SDL_Palette *surf_palette = PG_GetSurfacePalette(surface);
17261715
#else
17271716
SDL_PixelFormat *surf_format = surface->format;
17281717
SDL_Palette *surf_palette = surface->format->palette;

src_c/scrap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,11 @@ _scrap_put_text(PyObject *self, PyObject *args)
441441
return NULL;
442442
}
443443

444+
#if SDL_VERSION_ATLEAST(3, 0, 0)
445+
if (!SDL_SetClipboardText(text)) {
446+
#else
444447
if (SDL_SetClipboardText(text)) {
448+
#endif
445449
return RAISE(pgExc_SDLError, SDL_GetError());
446450
}
447451

src_c/scrap_sdl2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ pygame_scrap_put(char *type, Py_ssize_t srclen, char *src)
109109

110110
if (strcmp(type, pygame_scrap_plaintext_type) == 0 ||
111111
strcmp(type, pygame_scrap_utf8text_type) == 0) {
112+
#if SDL_VERSION_ATLEAST(3, 0, 0)
113+
if (SDL_SetClipboardText(src)) {
114+
#else
112115
if (SDL_SetClipboardText(src) == 0) {
116+
#endif
113117
return 1;
114118
}
115119
}

src_c/transform.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,7 +3737,7 @@ surf_average_color(PyObject *self, PyObject *args, PyObject *kwargs)
37373737
Uint8 r, g, b, a;
37383738
int x, y, w, h;
37393739
static char *keywords[] = {"surface", "rect", "consider_alpha", NULL};
3740-
SDL_bool consider_alpha = SDL_FALSE;
3740+
int consider_alpha = SDL_FALSE;
37413741

37423742
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|Op", keywords,
37433743
&pgSurface_Type, &surfobj, &rectobj,
@@ -4051,7 +4051,7 @@ surf_box_blur(PyObject *self, PyObject *args, PyObject *kwargs)
40514051
pgSurfaceObject *dst_surf_obj = NULL;
40524052
pgSurfaceObject *src_surf_obj;
40534053
SDL_Surface *new_surf = NULL;
4054-
SDL_bool repeat_edge_pixels = SDL_TRUE;
4054+
int repeat_edge_pixels = SDL_TRUE;
40554055

40564056
int radius;
40574057

@@ -4084,7 +4084,7 @@ surf_gaussian_blur(PyObject *self, PyObject *args, PyObject *kwargs)
40844084
pgSurfaceObject *dst_surf_obj = NULL;
40854085
pgSurfaceObject *src_surf_obj;
40864086
SDL_Surface *new_surf = NULL;
4087-
SDL_bool repeat_edge_pixels = SDL_TRUE;
4087+
int repeat_edge_pixels = SDL_TRUE;
40884088

40894089
int radius;
40904090

src_py/_debug.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,18 @@ def default_return(linked=True):
106106
get_driver as get_display_driver,
107107
get_init as display_init,
108108
)
109-
from pygame.mixer import (
110-
get_driver as get_mixer_driver,
111-
get_init as mixer_init,
112-
)
109+
110+
debug_str, *mixer = attempt_import("pygame.mixer", "get_driver", debug_str)
111+
if not mixer[0]:
112+
get_mixer_driver = lambda: None
113+
else:
114+
get_mixer_driver = mixer[1]
115+
116+
debug_str, *mixer = attempt_import("pygame.mixer", "get_init", debug_str)
117+
if not mixer[0]:
118+
mixer_init = lambda: False
119+
else:
120+
mixer_init = mixer[1]
113121

114122
debug_str, *mixer = attempt_import(
115123
"pygame.mixer", "get_sdl_mixer_version", debug_str

0 commit comments

Comments
 (0)