Skip to content

Commit

Permalink
video: Add a fallback case for creating 16-bit surfaces with bogus ma…
Browse files Browse the repository at this point in the history
…sks.

Fixes #257.
  • Loading branch information
icculus committed Oct 19, 2022
1 parent e86d024 commit eaeaf93
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/SDL12_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -5003,12 +5003,19 @@ SDL_CreateRGBSurface(Uint32 flags12, int width, int height, int depth, Uint32 Rm
a generic blitter that just copied data blindly. SDL2 wants more strict
pixel formats, so try to detect this case and try again with a standard
format. */
if ((surface20 == NULL) && (depth >= 24) && (SDL20_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask) == SDL_PIXELFORMAT_UNKNOWN)) {
if ((surface20 == NULL) && (depth >= 16) && (SDL20_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask) == SDL_PIXELFORMAT_UNKNOWN)) {
/* I have no illusions this is correct, it just works for the known problem cases so far. */
Rmask = SDL_SwapLE32(0x000000FF);
Gmask = SDL_SwapLE32(0x0000FF00);
Bmask = SDL_SwapLE32(0x00FF0000);
Amask = SDL_SwapLE32(Amask ? 0xFF000000 : 0x00000000);
if (depth == 16) {
Rmask = SDL_SwapLE32(0x0000F800);
Gmask = SDL_SwapLE32(0x000007E0);
Bmask = SDL_SwapLE32(0x0000001F);
Amask = 0;
} else {
Rmask = SDL_SwapLE32(0x000000FF);
Gmask = SDL_SwapLE32(0x0000FF00);
Bmask = SDL_SwapLE32(0x00FF0000);
Amask = SDL_SwapLE32(Amask ? 0xFF000000 : 0x00000000);
}
surface20 = SDL20_CreateRGBSurface(0, width, height, depth, Rmask, Gmask, Bmask, Amask);
}

Expand Down

0 comments on commit eaeaf93

Please sign in to comment.