Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions src_c/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,10 @@ tobytes_surf_32bpp(SDL_Surface *surf, SDL_PixelFormat *format_details,
{
int w, h;

#if SDL_VERSION_ATLEAST(3, 0, 0)
Uint32 Rloss = format_details->Rbits;
Uint32 Gloss = format_details->Gbits;
Uint32 Bloss = format_details->Bbits;
Uint32 Aloss = format_details->Abits;
#else
Uint32 Rloss = format_details->Rloss;
Uint32 Gloss = format_details->Gloss;
Uint32 Bloss = format_details->Bloss;
Uint32 Aloss = format_details->Aloss;
#endif
Uint32 Rloss = PG_FORMAT_R_LOSS(format_details);
Uint32 Gloss = PG_FORMAT_G_LOSS(format_details);
Uint32 Bloss = PG_FORMAT_B_LOSS(format_details);
Uint32 Aloss = PG_FORMAT_A_LOSS(format_details);
Uint32 Rmask = format_details->Rmask;
Uint32 Gmask = format_details->Gmask;
Uint32 Bmask = format_details->Bmask;
Expand Down Expand Up @@ -565,19 +558,15 @@ image_tobytes(PyObject *self, PyObject *arg, PyObject *kwarg)
if (!format_details) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole SDL_VERSION_ATLEAST could be removed by using PG_GetSurfaceDetails, same with the block below (+PG_PixelFormatEnum) for that one, if you're reducing redundancy on these.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. But the main reason for me doing these loss changes is not reducing redundancy, it is fixing behavior because bits != loss and our compat macro handles the conversion.
I want to keep the diff minimal in these runtime fixes PRs, cleanups and stuff can always be done in future PRs.

return RAISE(pgExc_SDLError, SDL_GetError());
}
SDL_Palette *surf_palette = SDL_GetSurfacePalette(surf);
Rloss = format_details->Rbits;
Gloss = format_details->Gbits;
Bloss = format_details->Bbits;
Aloss = format_details->Abits;
SDL_Palette *surf_palette = PG_GetSurfacePalette(surf);
#else
SDL_PixelFormat *format_details = surf->format;
SDL_Palette *surf_palette = surf->format->palette;
Rloss = format_details->Rloss;
Gloss = format_details->Gloss;
Bloss = format_details->Bloss;
Aloss = format_details->Aloss;
#endif
Rloss = PG_FORMAT_R_LOSS(format_details);
Gloss = PG_FORMAT_G_LOSS(format_details);
Bloss = PG_FORMAT_B_LOSS(format_details);
Aloss = PG_FORMAT_A_LOSS(format_details);
Rmask = format_details->Rmask;
Gmask = format_details->Gmask;
Bmask = format_details->Bmask;
Expand Down Expand Up @@ -1722,7 +1711,7 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle)
}
SDL_PixelFormat output_format;

SDL_Palette *surf_palette = SDL_GetSurfacePalette(surface);
SDL_Palette *surf_palette = PG_GetSurfacePalette(surface);
#else
SDL_PixelFormat *surf_format = surface->format;
SDL_Palette *surf_palette = surface->format->palette;
Expand Down
4 changes: 4 additions & 0 deletions src_c/scrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,11 @@ _scrap_put_text(PyObject *self, PyObject *args)
return NULL;
}

#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!SDL_SetClipboardText(text)) {
#else
if (SDL_SetClipboardText(text)) {
#endif
return RAISE(pgExc_SDLError, SDL_GetError());
}

Expand Down
4 changes: 4 additions & 0 deletions src_c/scrap_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ pygame_scrap_put(char *type, Py_ssize_t srclen, char *src)

if (strcmp(type, pygame_scrap_plaintext_type) == 0 ||
strcmp(type, pygame_scrap_utf8text_type) == 0) {
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (SDL_SetClipboardText(src)) {
#else
if (SDL_SetClipboardText(src) == 0) {
#endif
return 1;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src_c/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -3737,7 +3737,7 @@ surf_average_color(PyObject *self, PyObject *args, PyObject *kwargs)
Uint8 r, g, b, a;
int x, y, w, h;
static char *keywords[] = {"surface", "rect", "consider_alpha", NULL};
SDL_bool consider_alpha = SDL_FALSE;
int consider_alpha = SDL_FALSE;

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|Op", keywords,
&pgSurface_Type, &surfobj, &rectobj,
Expand Down Expand Up @@ -4051,7 +4051,7 @@ surf_box_blur(PyObject *self, PyObject *args, PyObject *kwargs)
pgSurfaceObject *dst_surf_obj = NULL;
pgSurfaceObject *src_surf_obj;
SDL_Surface *new_surf = NULL;
SDL_bool repeat_edge_pixels = SDL_TRUE;
int repeat_edge_pixels = SDL_TRUE;

int radius;

Expand Down Expand Up @@ -4084,7 +4084,7 @@ surf_gaussian_blur(PyObject *self, PyObject *args, PyObject *kwargs)
pgSurfaceObject *dst_surf_obj = NULL;
pgSurfaceObject *src_surf_obj;
SDL_Surface *new_surf = NULL;
SDL_bool repeat_edge_pixels = SDL_TRUE;
int repeat_edge_pixels = SDL_TRUE;

int radius;

Expand Down
21 changes: 10 additions & 11 deletions src_py/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def _get_platform_info():
Internal helper to get platform information
"""
cpu_inst_dict = get_cpu_instruction_sets()
sse2 = 'Yes' if cpu_inst_dict['SSE2'] else 'No'
avx2 = 'Yes' if cpu_inst_dict['AVX2'] else 'No'
neon = 'Yes' if cpu_inst_dict['NEON'] else 'No'
sse2 = "Yes" if cpu_inst_dict["SSE2"] else "No"
avx2 = "Yes" if cpu_inst_dict["AVX2"] else "No"
neon = "Yes" if cpu_inst_dict["NEON"] else "No"
ret = f"Platform:\t\t{platform.platform()}\n"
ret += f"System:\t\t\t{platform.system()}\n"
ret += f"System Version:\t\t{platform.version()}\n"
Expand Down Expand Up @@ -106,18 +106,17 @@ def default_return(linked=True):
get_driver as get_display_driver,
get_init as display_init,
)
from pygame.mixer import (
get_driver as get_mixer_driver,
get_init as mixer_init,
)

debug_str, *mixer = attempt_import("pygame.mixer", "get_driver", debug_str)
get_mixer_driver = mixer[1] if mixer[0] else lambda: None

debug_str, *mixer = attempt_import("pygame.mixer", "get_init", debug_str)
mixer_init = mixer[1] if mixer[0] else lambda: False

debug_str, *mixer = attempt_import(
"pygame.mixer", "get_sdl_mixer_version", debug_str
)
if not mixer[0]:
get_sdl_mixer_version = default_return
else:
get_sdl_mixer_version = mixer[1]
get_sdl_mixer_version = mixer[1] if mixer[0] else default_return

debug_str, *font = attempt_import("pygame.font", "get_sdl_ttf_version", debug_str)
if not font[0]:
Expand Down
Loading