X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsdl.c;h=76c70cc4a66e6b2d3d8ee27c9b1261b5330197da;hb=7a3792dad12dfcdac06d0566da60a4ea69c5dfac;hp=89d2af1efb8c28896ca76876bdec6f67b8509a91;hpb=30797dcb6034d34040a7888cf2adfe5cd48ec986;p=rocksndiamonds.git diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 89d2af1e..76c70cc4 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -415,6 +415,25 @@ const char *SDLGetRendererName(void) return renderer_info.name; } +static SDL_Surface *SDLGetOpaqueSurface(SDL_Surface *surface) +{ + SDL_Surface *new_surface; + + if (surface == NULL) + return NULL; + + if ((new_surface = SDLGetNativeSurface(surface)) == NULL) + Fail("SDLGetNativeSurface() failed"); + + // remove alpha channel from native non-transparent surface, if defined + SDLSetAlpha(new_surface, FALSE, 0); + + // remove transparent color from native non-transparent surface, if defined + SDL_SetColorKey(new_surface, UNSET_TRANSPARENT_PIXEL, 0); + + return new_surface; +} + SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) { SDL_PixelFormat format; @@ -483,6 +502,31 @@ SDL_Surface *SDLCreateNativeSurface(int width, int height, int depth) return surface; } +Bitmap *SDLGetBitmapFromSurface(SDL_Surface *surface) +{ + int width = surface->w; + int height = surface->h; + int depth = video.default_depth; + Bitmap *bitmap = CreateBitmap(width, height, depth); + + // free default surface (not needed anymore) + SDL_FreeSurface(bitmap->surface); + + // get native, non-transparent surface from original surface + bitmap->surface = SDLGetOpaqueSurface(surface); + + // get native, potentially transparent surface from original surface + bitmap->surface_masked = SDLGetNativeSurface(surface); + + // set black pixel to transparent if no alpha channel / transparent color + if (!SDLHasAlpha(bitmap->surface_masked) && + !SDLHasColorKey(bitmap->surface_masked)) + SDL_SetColorKey(bitmap->surface_masked, SET_TRANSPARENT_PIXEL, + SDL_MapRGB(bitmap->surface_masked->format, 0x00, 0x00, 0x00)); + + return bitmap; +} + static SDL_Texture *SDLCreateTextureFromSurface(SDL_Surface *surface) { if (program.headless) @@ -2320,25 +2364,6 @@ SDL_Surface *SDLZoomSurface(SDL_Surface *src, int dst_width, int dst_height) return zoom_dst; } -static SDL_Surface *SDLGetOpaqueSurface(SDL_Surface *surface) -{ - SDL_Surface *new_surface; - - if (surface == NULL) - return NULL; - - if ((new_surface = SDLGetNativeSurface(surface)) == NULL) - Fail("SDLGetNativeSurface() failed"); - - // remove alpha channel from native non-transparent surface, if defined - SDLSetAlpha(new_surface, FALSE, 0); - - // remove transparent color from native non-transparent surface, if defined - SDL_SetColorKey(new_surface, UNSET_TRANSPARENT_PIXEL, 0); - - return new_surface; -} - Bitmap *SDLZoomBitmap(Bitmap *src_bitmap, int dst_width, int dst_height) { Bitmap *dst_bitmap = CreateBitmapStruct();