Default palette entries to white, instead of black. SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Fri, 16 Jun 2006 06:00:31 +0000
branchSDL-1.3
changeset 1682 7ae8018b2e5d
parent 1681 80a5e6a4e1e2
child 1683 396a35389351
Default palette entries to white, instead of black. More palettized video mode support...
include/SDL_compat.h
include/SDL_pixels.h
include/SDL_video.h
src/SDL_compat.c
src/video/SDL_pixels.c
src/video/SDL_surface.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullrender.c
--- a/include/SDL_compat.h	Thu Jun 15 07:07:07 2006 +0000
+++ b/include/SDL_compat.h	Fri Jun 16 06:00:31 2006 +0000
@@ -44,8 +44,8 @@
 #define SDL_RESIZABLE       0x01000000
 #define SDL_NOFRAME         0x02000000
 #define SDL_OPENGL          0x04000000
-#define SDL_ASYNCBLIT       0x00000000
-#define SDL_HWACCEL         0x00000000
+#define SDL_ASYNCBLIT       0x08000000  /* Not used */
+#define SDL_HWACCEL         0x08000000  /* Not used */
 #define SDL_SCREEN_SURFACE  0x10000000  /* Surface is a window screen surface */
 #define SDL_SHADOW_SURFACE  0x20000000  /* Surface is a window shadow surface */
 
@@ -146,10 +146,10 @@
 extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface);
 extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode);
 extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, int flags,
-                                           SDL_Color * colors,
+                                           const SDL_Color * colors,
                                            int firstcolor, int ncolors);
 extern DECLSPEC int SDLCALL SDL_SetScreenColors(SDL_Surface * screen,
-                                                SDL_Color * colors,
+                                                const SDL_Color * colors,
                                                 int firstcolor, int ncolors);
 extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo * info);
 extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void);
--- a/include/SDL_pixels.h	Thu Jun 15 07:07:07 2006 +0000
+++ b/include/SDL_pixels.h	Fri Jun 16 06:00:31 2006 +0000
@@ -114,7 +114,7 @@
      (SDL_PIXELTYPE(format) == SDL_PixelType_Index8))
 
 #define SDL_ISPIXELFORMAT_FOURCC(format)    \
-    ((format) && !((format) & 0x8000000))
+    ((format) && !((format) & 0x80000000))
 
 enum
 {
--- a/include/SDL_video.h	Thu Jun 15 07:07:07 2006 +0000
+++ b/include/SDL_video.h	Fri Jun 16 06:00:31 2006 +0000
@@ -1082,8 +1082,8 @@
  * emulation.
  */
 extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface * surface,
-                                          SDL_Color * colors, int firstcolor,
-                                          int ncolors);
+                                          const SDL_Color * colors,
+                                          int firstcolor, int ncolors);
 
 /*
  * Maps an RGB triple to an opaque pixel value for a given pixel format
--- a/src/SDL_compat.c	Thu Jun 15 07:07:07 2006 +0000
+++ b/src/SDL_compat.c	Fri Jun 16 06:00:31 2006 +0000
@@ -218,6 +218,7 @@
     Uint32 desktop_format;
     Uint32 desired_format;
     Uint32 texture_format;
+    Uint32 surface_flags;
 
     if (!SDL_GetVideoDevice()) {
         if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
@@ -264,6 +265,21 @@
         return NULL;
     }
 
+    window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
+    surface_flags = SDL_SCREEN_SURFACE;
+    if (window_flags & SDL_WINDOW_FULLSCREEN) {
+        surface_flags |= SDL_FULLSCREEN;
+    }
+    if (window_flags & SDL_WINDOW_OPENGL) {
+        surface_flags |= SDL_OPENGL;
+    }
+    if (window_flags & SDL_WINDOW_RESIZABLE) {
+        surface_flags |= SDL_RESIZABLE;
+    }
+    if (window_flags & SDL_WINDOW_BORDERLESS) {
+        surface_flags |= SDL_NOFRAME;
+    }
+
     /* Set up the desired display mode */
     desktop_mode = SDL_GetDesktopDisplayMode();
     desktop_format = desktop_mode->format;
@@ -323,6 +339,18 @@
         return NULL;
     }
 
+    /* If we're in OpenGL mode, just create a stub surface and we're done! */
+    if (flags & SDL_OPENGL) {
+        SDL_VideoSurface =
+            SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
+        if (!SDL_VideoSurface) {
+            return NULL;
+        }
+        SDL_VideoSurface->flags |= surface_flags;
+        SDL_PublicSurface = SDL_VideoSurface;
+        return SDL_PublicSurface;
+    }
+
     /* Create a renderer for the window */
     if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
         return NULL;
@@ -345,6 +373,7 @@
     if (!SDL_VideoSurface) {
         return NULL;
     }
+    SDL_VideoSurface->flags |= surface_flags;
 
     /* Set a default screen palette */
     if (SDL_VideoSurface->format->palette) {
@@ -354,6 +383,8 @@
         SDL_SetTexturePalette(SDL_VideoTexture,
                               SDL_VideoSurface->format->palette->colors, 0,
                               SDL_VideoSurface->format->palette->ncolors);
+        SDL_SetDisplayPalette(SDL_VideoSurface->format->palette->colors, 0,
+                              SDL_VideoSurface->format->palette->ncolors);
     }
 
     /* Create a shadow surface if necessary */
@@ -377,6 +408,9 @@
         if (!SDL_ShadowSurface) {
             return NULL;
         }
+        surface_flags &= ~SDL_SCREEN_SURFACE;
+        surface_flags |= SDL_SHADOW_SURFACE;
+        SDL_ShadowSurface->flags |= surface_flags;
 
         /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
         if (SDL_ShadowSurface->format->palette) {
@@ -615,15 +649,15 @@
 }
 
 int
-SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors,
+SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
                int firstcolor, int ncolors)
 {
     SDL_SetColors(surface, colors, firstcolor, ncolors);
 }
 
 int
-SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
-                    int ncolors)
+SDL_SetScreenColors(SDL_Surface * screen, const SDL_Color * colors,
+                    int firstcolor, int ncolors)
 {
     SDL_Palette *pal;
     int gotall;
--- a/src/video/SDL_pixels.c	Thu Jun 15 07:07:07 2006 +0000
+++ b/src/video/SDL_pixels.c	Fri Jun 16 06:00:31 2006 +0000
@@ -386,7 +386,7 @@
                 a = (a << format->Aloss) | ((a * Am) >> Aw);
                 format->palette->colors[i].unused = a;
 #else
-                format->palette->colors[i].unused = 0;
+                format->palette->colors[i].unused = SDL_ALPHA_OPAQUE;
 #endif
             }
         } else if (ncolors == 2) {
@@ -399,7 +399,7 @@
             format->palette->colors[1].b = 0x00;
         } else {
             /* Create an empty palette */
-            SDL_memset((format->palette)->colors, 0,
+            SDL_memset((format->palette)->colors, 0xFF,
                        (format->palette)->ncolors * sizeof(SDL_Color));
         }
     }
@@ -474,6 +474,7 @@
         b |= b << 2;
         b |= b << 4;
         colors[i].b = b;
+        colors[i].unused = SDL_ALPHA_OPAQUE;
     }
 }
 
@@ -696,7 +697,7 @@
 
     /* SDL_DitherColors does not initialize the 'unused' component of colors,
        but Map1to1 compares it against pal, so we should initialize it. */
-    SDL_memset(colors, 0, sizeof(colors));
+    SDL_memset(colors, 0xFF, sizeof(colors));
 
     dithered.ncolors = 256;
     SDL_DitherColors(colors, 8);
--- a/src/video/SDL_surface.c	Thu Jun 15 07:07:07 2006 +0000
+++ b/src/video/SDL_surface.c	Fri Jun 16 06:00:31 2006 +0000
@@ -39,7 +39,6 @@
                      int width, int height, int depth,
                      Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
 {
-    SDL_VideoDevice *_this = SDL_GetVideoDevice();
     SDL_Surface *screen;
     SDL_Surface *surface;
 
@@ -170,7 +169,7 @@
  * Set the palette in a blittable surface
  */
 int
-SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor,
+SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
               int ncolors)
 {
     SDL_Palette *pal;
@@ -557,7 +556,6 @@
 int
 SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
 {
-    SDL_VideoDevice *_this = SDL_GetVideoDevice();
     int x, y;
     Uint8 *row;
 
@@ -789,9 +787,9 @@
     if (format->palette != NULL) {
         int i;
         for (i = 0; i < format->palette->ncolors; ++i) {
-            if ((format->palette->colors[i].r != 0) ||
-                (format->palette->colors[i].g != 0) ||
-                (format->palette->colors[i].b != 0))
+            if ((format->palette->colors[i].r != 0xFF) ||
+                (format->palette->colors[i].g != 0xFF) ||
+                (format->palette->colors[i].b != 0xFF))
                 break;
         }
         if (i == format->palette->ncolors) {
--- a/src/video/SDL_sysvideo.h	Thu Jun 15 07:07:07 2006 +0000
+++ b/src/video/SDL_sysvideo.h	Fri Jun 16 06:00:31 2006 +0000
@@ -159,6 +159,8 @@
     /* The hash list of textures */
     SDL_Texture *textures[64];
 
+    SDL_VideoDevice *device;
+
     void *driverdata;
 };
 
--- a/src/video/SDL_video.c	Thu Jun 15 07:07:07 2006 +0000
+++ b/src/video/SDL_video.c	Fri Jun 16 06:00:31 2006 +0000
@@ -333,6 +333,7 @@
     if (displays) {
         index = _this->num_displays++;
         displays[index] = *display;
+        displays[index].device = _this;
         _this->displays = displays;
     } else {
         SDL_OutOfMemory();
--- a/src/video/dummy/SDL_nullrender.c	Thu Jun 15 07:07:07 2006 +0000
+++ b/src/video/dummy/SDL_nullrender.c	Fri Jun 16 06:00:31 2006 +0000
@@ -32,11 +32,11 @@
 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
                                    SDL_Texture * texture);
 static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
-                                      SDL_Rect * rect, void *pixels,
+                                      const SDL_Rect * rect, void *pixels,
                                       int pitch);
 static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
-                                       SDL_Rect * rect, const void *pixels,
-                                       int pitch);
+                                       const SDL_Rect * rect,
+                                       const void *pixels, int pitch);
 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
 
@@ -57,7 +57,7 @@
 
 typedef struct
 {
-    SDL_Surface *screen;
+    SDL_Surface *surface;
 } SDL_DUMMY_RenderData;
 
 SDL_Renderer *
@@ -99,24 +99,34 @@
     renderer->window = window;
     renderer->driverdata = data;
 
-    data->screen =
+    data->surface =
         SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
                              Bmask, Amask);
-    if (!data->screen) {
+    if (!data->surface) {
         SDL_DUMMY_DestroyRenderer(renderer);
         return NULL;
     }
 
+    /* If the display has a palette, use it for the window surfaces */
+    if (window->display->palette.ncolors) {
+        SDL_PixelFormat *format = data->surface->format;
+        if (format->palette->colors) {
+            SDL_free(format->palette->colors);
+        }
+        SDL_free(format->palette);
+        format->palette = &window->display->palette;
+    }
+
     return renderer;
 }
 
 int
-SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
+SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
                            void *pixels, int pitch)
 {
     SDL_DUMMY_RenderData *data =
         (SDL_DUMMY_RenderData *) renderer->driverdata;
-    SDL_Surface *surface = data->screen;
+    SDL_Surface *surface = data->surface;
     Uint8 *src, *dst;
     int row;
     size_t length;
@@ -135,12 +145,12 @@
 }
 
 int
-SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
+SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
                             const void *pixels, int pitch)
 {
     SDL_DUMMY_RenderData *data =
         (SDL_DUMMY_RenderData *) renderer->driverdata;
-    SDL_Surface *surface = data->screen;
+    SDL_Surface *surface = data->surface;
     Uint8 *src, *dst;
     int row;
     size_t length;
@@ -164,7 +174,7 @@
     static int frame_number;
     SDL_DUMMY_RenderData *data =
         (SDL_DUMMY_RenderData *) renderer->driverdata;
-    SDL_Surface *surface = data->screen;
+    SDL_Surface *surface = data->surface;
 
     if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
         char file[128];
@@ -181,8 +191,9 @@
         (SDL_DUMMY_RenderData *) renderer->driverdata;
 
     if (data) {
-        if (data->screen) {
-            SDL_FreeSurface(data->screen);
+        if (data->surface) {
+            data->surface->format->palette = NULL;
+            SDL_FreeSurface(data->surface);
         }
         SDL_free(data);
     }