From 1e80409f123f7443ebb535f93cc60bdd8d5c6d61 Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:30:14 -0700 Subject: [PATCH] Port last SDL_CreateRGBSurface calls to SDL3-safe PG_CreateSurface --- src_c/image.c | 24 +++++++----------------- src_c/surface.c | 5 +++-- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src_c/image.c b/src_c/image.c index 0e1f59f203..7524f572c0 100644 --- a/src_c/image.c +++ b/src_c/image.c @@ -1509,7 +1509,7 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) Uint8 surf_alpha; int have_surf_colorkey = 0; Uint32 surf_colorkey; - Uint32 rmask, gmask, bmask, amask; + Uint32 format; SDL_Rect r; int bpp; Uint8 *rlebuf = NULL; @@ -1535,7 +1535,7 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) h.cmap_bits = 24; SETLE16(h.cmap_len, surface->format->palette->ncolors); h.pixel_bits = 8; - rmask = gmask = bmask = amask = 0; + format = SDL_PIXELFORMAT_INDEX8; } else { h.has_cmap = 0; @@ -1545,21 +1545,12 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) if (surface->format->Amask) { alpha = 1; h.pixel_bits = 32; + format = SDL_PIXELFORMAT_BGRA32; } - else + else { h.pixel_bits = 24; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - int s = alpha ? 0 : 8; - amask = 0x000000ff >> s; - rmask = 0x0000ff00 >> s; - gmask = 0x00ff0000 >> s; - bmask = 0xff000000 >> s; -#else /* SDL_BYTEORDER != SDL_BIG_ENDIAN */ - amask = alpha ? 0xff000000 : 0; - rmask = 0x00ff0000; - gmask = 0x0000ff00; - bmask = 0x000000ff; -#endif /* SDL_BYTEORDER != SDL_BIG_ENDIAN */ + format = SDL_PIXELFORMAT_BGR24; + } } bpp = h.pixel_bits >> 3; if (rle) @@ -1588,8 +1579,7 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) } } - linebuf = SDL_CreateRGBSurface(0, surface->w, 1, h.pixel_bits, rmask, - gmask, bmask, amask); + linebuf = PG_CreateSurface(surface->w, 1, format); if (!linebuf) return -1; diff --git a/src_c/surface.c b/src_c/surface.c index 07776c81d6..61fe36763d 100644 --- a/src_c/surface.c +++ b/src_c/surface.c @@ -717,8 +717,9 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) } } - surface = SDL_CreateRGBSurface(0, width, height, bpp, Rmask, Gmask, Bmask, - Amask); + surface = PG_CreateSurface( + width, height, + SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask)); if (!surface) { _raise_create_surface_error(); return -1;