The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs.
authorSam Lantinga <slouken@libsdl.org>
Sat, 29 Nov 2008 11:26:01 +0000
changeset 2807 365fe1a2aad5
parent 2806 938aa47f903a
child 2808 368410632f2d
The SDL_RLEACCEL flag is respected in SDL_ConvertSurface(), per the docs. Fixed saving BMP files of surfaces with an alpha channel.
include/SDL_surface.h
src/SDL_compat.c
src/video/SDL_bmp.c
src/video/SDL_surface.c
--- a/include/SDL_surface.h	Sat Nov 29 11:24:18 2008 +0000
+++ b/include/SDL_surface.h	Sat Nov 29 11:26:01 2008 +0000
@@ -101,9 +101,7 @@
  * flags '[RGB]mask'.
  * If the function runs out of memory, it will return NULL.
  *
- * The 'flags' tell what kind of surface to create.
- * SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits.
- * SDL_SRCALPHA means that the surface will be used for alpha blits.
+ * The 'flags' are obsolete and should be set to 0.
  */
 extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
     (Uint32 flags, int width, int height, int depth,
--- a/src/SDL_compat.c	Sat Nov 29 11:24:18 2008 +0000
+++ b/src/SDL_compat.c	Sat Nov 29 11:26:01 2008 +0000
@@ -614,17 +614,16 @@
 SDL_Surface *
 SDL_DisplayFormat(SDL_Surface * surface)
 {
-    SDL_Surface *converted;
+    SDL_PixelFormat *format;
 
     if (!SDL_PublicSurface) {
         SDL_SetError("No video mode has been set");
         return NULL;
     }
+    format = SDL_PublicSurface->format;
 
     /* Set the flags appropriate for copying to display surface */
-    converted = SDL_ConvertSurface(surface, SDL_PublicSurface->format, 0);
-    SDL_SetSurfaceRLE(converted, 1);
-    return converted;
+    return SDL_ConvertSurface(surface, format, SDL_RLEACCEL);
 }
 
 SDL_Surface *
@@ -673,8 +672,7 @@
         break;
     }
     format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
-    converted = SDL_ConvertSurface(surface, format, 0);
-    SDL_SetSurfaceRLE(converted, 1);
+    converted = SDL_ConvertSurface(surface, format, SDL_RLEACCEL);
     SDL_FreeFormat(format);
     return converted;
 }
--- a/src/video/SDL_bmp.c	Sat Nov 29 11:24:18 2008 +0000
+++ b/src/video/SDL_bmp.c	Sat Nov 29 11:26:01 2008 +0000
@@ -382,26 +382,22 @@
             ) {
             surface = saveme;
         } else {
-            SDL_Rect bounds;
+            SDL_PixelFormat *format;
 
             /* Convert to 24 bits per pixel */
-            surface = SDL_CreateRGBSurface(0, saveme->w, saveme->h, 24,
+            format = SDL_AllocFormat(24,
 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
-                                           0x00FF0000, 0x0000FF00, 0x000000FF,
+                                     0x00FF0000, 0x0000FF00, 0x000000FF,
 #else
-                                           0x000000FF, 0x0000FF00, 0x00FF0000,
+                                     0x000000FF, 0x0000FF00, 0x00FF0000,
 #endif
-                                           0);
-            if (surface != NULL) {
-                bounds.x = 0;
-                bounds.y = 0;
-                bounds.w = saveme->w;
-                bounds.h = saveme->h;
-                if (SDL_LowerBlit(saveme, &bounds, surface, &bounds) < 0) {
-                    SDL_FreeSurface(surface);
+                                     0);
+            if (format != NULL) {
+                surface = SDL_ConvertSurface(saveme, format, 0);
+                if (!surface) {
                     SDL_SetError("Couldn't convert image to 24 bpp");
-                    surface = NULL;
                 }
+                SDL_FreeFormat(format);
             }
         }
     }
--- a/src/video/SDL_surface.c	Sat Nov 29 11:24:18 2008 +0000
+++ b/src/video/SDL_surface.c	Sat Nov 29 11:26:01 2008 +0000
@@ -41,6 +41,9 @@
 {
     SDL_Surface *surface;
 
+    /* The flags are no longer used, make the compiler happy */
+    flags;
+
     /* Allocate the surface */
     surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
     if (surface == NULL) {
@@ -754,8 +757,8 @@
  * Convert a surface into the specified pixel format.
  */
 SDL_Surface *
-SDL_ConvertSurface(SDL_Surface * surface,
-                   SDL_PixelFormat * format, Uint32 flags)
+SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format,
+                   Uint32 flags)
 {
     SDL_Surface *convert;
     Uint32 copy_flags;
@@ -777,7 +780,7 @@
     }
 
     /* Create a new surface with the desired format */
-    convert = SDL_CreateRGBSurface(0, surface->w, surface->h,
+    convert = SDL_CreateRGBSurface(flags, surface->w, surface->h,
                                    format->BitsPerPixel, format->Rmask,
                                    format->Gmask, format->Bmask,
                                    format->Amask);
@@ -827,6 +830,7 @@
     if (format->Amask || (copy_flags & SDL_COPY_MODULATE_ALPHA)) {
         SDL_SetSurfaceBlendMode(convert, SDL_TEXTUREBLENDMODE_BLEND);
     }
+    SDL_SetSurfaceRLE(convert, (flags & SDL_RLEACCEL));
 
     /* We're ready to go! */
     return (convert);