diff src/video/dummy/SDL_nullrender.c @ 1682:7ae8018b2e5d SDL-1.3

Default palette entries to white, instead of black. More palettized video mode support...
author Sam Lantinga <slouken@libsdl.org>
date Fri, 16 Jun 2006 06:00:31 +0000
parents 90bf530ced8e
children 396a35389351
line wrap: on
line diff
--- 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);
     }