changeset 1560:7a2337dcd1b3

Cleanup some remnants of SDL1 code.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 May 2018 06:39:13 +0300
parents 43e18726e54d
children b6ee934496d1
files src/dmimage.c src/dmimage.h
diffstat 2 files changed, 18 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/dmimage.c	Sun May 13 06:14:08 2018 +0300
+++ b/src/dmimage.c	Sun May 13 06:39:13 2018 +0300
@@ -25,44 +25,22 @@
 #include "stb_image.c"
 
 
-static Uint32
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-        dmXrmask = 0xff000000,
-        dmXgmask = 0x00ff0000,
-        dmXbmask = 0x0000ff00,
-        dmXamask = 0x000000ff;
-#else
-        dmXrmask = 0x000000ff,
-        dmXgmask = 0x0000ff00,
-        dmXbmask = 0x00ff0000,
-        dmXamask = 0xff000000;
-#endif
-
-
 SDL_Surface *dmCreateRGBSurfaceFrom(void *data,
     const int width, const int height,
     const int depth, const int pitch,
-    const int rmask, const int gmask, const int bmask, const int amask)
+    const Uint32 format)
 {
     // Create source surface from given data
-    SDL_Surface *tmp = SDL_CreateRGBSurfaceFrom(data, width, height, depth, pitch, bmask, gmask, rmask, amask);
-
-    // Create result conversion surface
     SDL_Surface
         *result = NULL,
-        *pixtmp = SDL_CreateRGBSurface(
-            SDL_SWSURFACE,
-            16, 16, 32,
-            dmXrmask, dmXgmask, dmXbmask, dmXamask);
+        *tmp = SDL_CreateRGBSurfaceWithFormatFrom(data, width, height, depth, pitch, format);
 
-    if (tmp != NULL && pixtmp != NULL)
+    // Create result conversion surface
+    if (tmp != NULL)
     {
-        // Convert surface
-        result = SDL_ConvertSurface(tmp, pixtmp->format, SDL_SWSURFACE);
+        result = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_RGBA32, 0);
         SDL_FreeSurface(tmp);
     }
-    if (pixtmp != NULL)
-        SDL_FreeSurface(pixtmp);
 
     return result;
 }
@@ -73,7 +51,7 @@
     int yc;
     Uint8 *dst, *src;
     SDL_Surface *result;
-    result = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0,0,0,0);
+    result = SDL_CreateRGBSurfaceWithFormat(0, width, height, 8, SDL_PIXELFORMAT_INDEX8);
     if (result == NULL)
         return NULL;
 
@@ -118,7 +96,6 @@
 
 SDL_Surface *dmLoadImage(DMResource *file)
 {
-    Uint32 rmask, gmask, bmask, amask;
     SDL_Surface *result = NULL;
     int width = 0, height = 0, comp = 0;
     Uint8 *data;
@@ -138,25 +115,24 @@
     switch (comp)
     {
         case 4:
-            result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8,
-                width * comp, dmXrmask, dmXgmask, dmXbmask, dmXamask);
+            result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8, width * comp,
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+                SDL_PIXELFORMAT_ABGR8888
+#else
+                SDL_PIXELFORMAT_ARGB8888
+#endif
+                );
             break;
 
         case 3:
             // These masks are different from the dmX*masks
+            result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8, width * comp,
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-            rmask = 0x00ff0000;
-            gmask = 0x0000ff00;
-            bmask = 0x000000ff;
-            amask = 0x00000000;
+                SDL_PIXELFORMAT_BGR888
 #else
-            rmask = 0x000000ff;
-            gmask = 0x0000ff00;
-            bmask = 0x00ff0000;
-            amask = 0x00000000;
+                SDL_PIXELFORMAT_RGB888
 #endif
-            result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8,
-                width * comp, rmask, gmask, bmask, amask);
+                );
             break;
 
         case 1:
--- a/src/dmimage.h	Sun May 13 06:14:08 2018 +0300
+++ b/src/dmimage.h	Sun May 13 06:39:13 2018 +0300
@@ -15,7 +15,7 @@
 #endif
 
 
-SDL_Surface *dmCreateRGBSurfaceFrom(void *data, const int width, const int height, const int depth, const int pitch, const int rmask, const int gmask, const int bmask, const int amask);
+SDL_Surface *dmCreateRGBSurfaceFrom(void *data, const int width, const int height, const int depth, const int pitch, const Uint32 format);
 SDL_Surface *dmCreatePaletteSurfaceFrom(void *data, const int width, const int height, const int pitch);
 SDL_Surface *dmLoadImage(DMResource *file);
 SDL_Texture *dmLoadImageToTexture(DMResource *file, SDL_Renderer *renderer);