fixed loading images with alpha channel or transparent color
authorHolger Schemel <info@artsoft.org>
Mon, 27 Jun 2016 23:45:44 +0000 (01:45 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 27 Jun 2016 23:45:44 +0000 (01:45 +0200)
src/libgame/sdl.c

index 72bbc14abe3df5abee36b2aeac94943cdfd3ff7b..30ca17949a8ad2f9192eed9fb0bd697a75207fd7 100644 (file)
@@ -2232,15 +2232,23 @@ Bitmap *SDLLoadImage(char *filename)
     return NULL;
   }
 
     return NULL;
   }
 
+  /* remove alpha channel from native non-transparent surface, if defined */
+  SDLSetAlpha(new_bitmap->surface, FALSE, 0);
+
+  /* remove transparent color from native non-transparent surface, if defined */
+  SDL_SetColorKey(new_bitmap->surface, UNSET_TRANSPARENT_PIXEL, 0);
+
   print_timestamp_time("SDL_DisplayFormat (opaque)");
 
   UPDATE_BUSY_STATE();
 
   print_timestamp_time("SDL_DisplayFormat (opaque)");
 
   UPDATE_BUSY_STATE();
 
-  /* create native transparent surface for current image */
-  if (sdl_image_tmp->format->Amask == 0)
+  /* set black pixel to transparent if no alpha channel / transparent color */
+  if (!SDLHasAlpha(sdl_image_tmp) &&
+      !SDLHasColorKey(sdl_image_tmp))
     SDL_SetColorKey(sdl_image_tmp, SET_TRANSPARENT_PIXEL,
                    SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
 
     SDL_SetColorKey(sdl_image_tmp, SET_TRANSPARENT_PIXEL,
                    SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
 
+  /* create native transparent surface for current image */
   if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL)
   {
     SetError("SDL_DisplayFormat(): %s", SDL_GetError());
   if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL)
   {
     SetError("SDL_DisplayFormat(): %s", SDL_GetError());