+SDL_Surface *SDLCreateNativeSurface(int width, int height, int depth)
+{
+ if (program.headless)
+ return NULL;
+
+ SDL_Surface *surface = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, 0,0,0, 0);
+
+ if (surface == NULL)
+ Fail("SDL_CreateRGBSurface() failed: %s", SDL_GetError());
+
+ SDLSetNativeSurface(&surface);
+
+ return surface;
+}
+
+Bitmap *SDLGetBitmapFromSurface_WithMaskedColor(SDL_Surface *surface, int r, int g, int b)
+{
+ 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, r, g, b));
+
+ return bitmap;
+}
+
+Bitmap *SDLGetBitmapFromSurface(SDL_Surface *surface)
+{
+ return SDLGetBitmapFromSurface_WithMaskedColor(surface, 0x00, 0x00, 0x00);
+}
+