Skip to content

Commit ebcd733

Browse files
committed
SDL3: image+key+scrap+transform: runtime fixes
1 parent de289b4 commit ebcd733

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
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/key.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,11 @@ static const struct {
389389
{1073742054, "right alt"}, /* K_RALT */
390390
{1073742055, "right meta"}, /* K_RGUI, K_RMETA, K_RSUPER */
391391
{1073742081, "alt gr"}, /* K_MODE */
392-
{1073742094, "AC Back"}, /* K_AC_BACK */
392+
#if SDL_VERSION_ATLEAST(3, 0, 0)
393+
{1073742106, "AC Back"}, /* K_AC_BACK */
394+
#else
395+
{1073742094, "AC Back"}, /* K_AC_BACK */
396+
#endif
393397
};
394398

395399
/* Get name from keycode using pygame compat table */

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
@@ -83,7 +83,11 @@ pygame_scrap_put(char *type, Py_ssize_t srclen, char *src)
8383
}
8484

8585
if (strcmp(type, pygame_scrap_plaintext_type) == 0) {
86+
#if SDL_VERSION_ATLEAST(3, 0, 0)
87+
if (SDL_SetClipboardText(src)) {
88+
#else
8689
if (SDL_SetClipboardText(src) == 0) {
90+
#endif
8791
return 1;
8892
}
8993
}

src_c/transform.c

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

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

40554055
int radius;
40564056

@@ -4083,7 +4083,7 @@ surf_gaussian_blur(PyObject *self, PyObject *args, PyObject *kwargs)
40834083
pgSurfaceObject *dst_surf_obj = NULL;
40844084
pgSurfaceObject *src_surf_obj;
40854085
SDL_Surface *new_surf = NULL;
4086-
SDL_bool repeat_edge_pixels = SDL_TRUE;
4086+
int repeat_edge_pixels = SDL_TRUE;
40874087

40884088
int radius;
40894089

test/key_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# keys that are not tested for const-name match
1010
SKIPPED_KEYS = {"K_UNKNOWN"}
11+
SKIPPED_KEYS_NEW = {"K_MODE"}
1112

1213
# This is the expected compat output
1314
KEY_NAME_COMPAT = {
@@ -286,7 +287,8 @@ def test_name_and_key_code(self):
286287
# This is a test for an implementation detail of name with use_compat=False
287288
# If this test breaks in the future for any key, it is safe to put skips on
288289
# failing keys (the implementation detail is documented as being unreliable)
289-
self.assertEqual(pygame.key.key_code(alt_name), const_val)
290+
if const_name not in SKIPPED_KEYS_NEW:
291+
self.assertEqual(pygame.key.key_code(alt_name), const_val)
290292

291293
self.assertRaises(TypeError, pygame.key.name, "fizzbuzz")
292294
self.assertRaises(TypeError, pygame.key.key_code, pygame.K_a)

0 commit comments

Comments
 (0)