changeset 1681:80a5e6a4e1e2 SDL-1.3

Working on paletted display and texture support (two different issues)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 15 Jun 2006 07:07:07 +0000
parents 9488fca10677
children 7ae8018b2e5d
files include/SDL_pixels.h include/SDL_video.h src/SDL_compat.c src/video/SDL_renderer_sw.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/dummy/SDL_nullvideo.c
diffstat 7 files changed, 247 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_pixels.h	Wed Jun 14 08:41:13 2006 +0000
+++ b/include/SDL_pixels.h	Thu Jun 15 07:07:07 2006 +0000
@@ -108,7 +108,13 @@
 #define SDL_BITSPERPIXEL(X)	(((X) >> 8) & 0xFF)
 #define SDL_BYTESPERPIXEL(X)	(((X) >> 0) & 0xFF)
 
-#define SDL_ISPIXELFORMAT_FOURCC(format)    (((format) & 0x8000000) != 0)
+#define SDL_ISPIXELFORMAT_INDEXED(format)   \
+    ((SDL_PIXELTYPE(format) == SDL_PixelType_Index1) || \
+     (SDL_PIXELTYPE(format) == SDL_PixelType_Index4) || \
+     (SDL_PIXELTYPE(format) == SDL_PixelType_Index8))
+
+#define SDL_ISPIXELFORMAT_FOURCC(format)    \
+    ((format) && !((format) & 0x8000000))
 
 enum
 {
--- a/include/SDL_video.h	Wed Jun 14 08:41:13 2006 +0000
+++ b/include/SDL_video.h	Thu Jun 15 07:07:07 2006 +0000
@@ -462,14 +462,26 @@
 extern DECLSPEC int SDLCALL SDL_SetDisplayMode(const SDL_DisplayMode * mode);
 
 /**
- * \fn int SDL_SetDisplayColormap(SDL_Color *colors, int firstcolor, int ncolors)
+ * \fn int SDL_SetDisplayPalette(const SDL_Color *colors, int firstcolor, int ncolors)
  *
- * \brief Set the colormap for indexed display modes.
+ * \brief Set the palette entries for indexed display modes.
  *
- * \return 0 on success, or -1 if not all the colors could be set.
+ * \return 0 on success, or -1 if the display mode isn't palettized or the colors couldn't be set.
  */
-extern DECLSPEC int SDLCALL SDL_SetDisplayColors(SDL_Color * colors,
-                                                 int firstcolor, int ncolors);
+extern DECLSPEC int SDLCALL SDL_SetDisplayPalette(const SDL_Color * colors,
+                                                  int firstcolor,
+                                                  int ncolors);
+
+/**
+ * \fn int SDL_GetDisplayPalette(SDL_Color *colors, int firstcolor, int ncolors)
+ *
+ * \brief Gets the palette entries for indexed display modes.
+ *
+ * \return 0 on success, or -1 if the display mode isn't palettized
+ */
+extern DECLSPEC int SDLCALL SDL_GetDisplayPalette(SDL_Color * colors,
+                                                  int firstcolor,
+                                                  int ncolors);
 
 /**
  * \fn SDL_WindowID SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
@@ -506,7 +518,7 @@
  *
  * \sa SDL_DestroyWindow()
  */
-extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindowFrom(void *data);
+extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindowFrom(const void *data);
 
 /**
  * \fn Uint32 SDL_GetWindowFlags(SDL_WindowID windowID)
@@ -818,7 +830,7 @@
                                                    void **pixels, int *pitch);
 
 /**
- * \fn int SDL_SetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, int firstcolor, int ncolors)
+ * \fn int SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors, int firstcolor, int ncolors)
  *
  * \brief Update an indexed texture with a color palette
  *
@@ -830,12 +842,29 @@
  * \return 0 on success, or -1 if the texture is not valid or not an indexed texture
  */
 extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_TextureID textureID,
+                                                  const SDL_Color * colors,
+                                                  int firstcolor,
+                                                  int ncolors);
+
+/**
+ * \fn int SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, int firstcolor, int ncolors)
+ *
+ * \brief Update an indexed texture with a color palette
+ *
+ * \param texture The texture to update
+ * \param colors The array to fill with RGB color data
+ * \param firstcolor The first index to retrieve
+ * \param ncolors The number of palette entries to retrieve
+ *
+ * \return 0 on success, or -1 if the texture is not valid or not an indexed texture
+ */
+extern DECLSPEC int SDLCALL SDL_GetTexturePalette(SDL_TextureID textureID,
                                                   SDL_Color * colors,
                                                   int firstcolor,
                                                   int ncolors);
 
 /**
- * \fn int SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect *rect, const void *pixels, int pitch)
+ * \fn int SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect *rect, const void *pixels, int pitch)
  *
  * \brief Update the given texture rectangle with new pixel data.
  *
@@ -849,11 +878,11 @@
  * \note This is a very slow function for textures not created with SDL_TextureAccess_Local.
  */
 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_TextureID textureID,
-                                              SDL_Rect * rect,
+                                              const SDL_Rect * rect,
                                               const void *pixels, int pitch);
 
 /**
- * \fn void SDL_LockTexture(SDL_TextureID textureID, SDL_Rect *rect, int markDirty, void **pixels, int *pitch)
+ * \fn void SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect *rect, int markDirty, void **pixels, int *pitch)
  *
  * \brief Lock a portion of the texture for pixel access.
  *
@@ -869,8 +898,9 @@
  * \sa SDL_UnlockTexture()
  */
 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_TextureID textureID,
-                                            SDL_Rect * rect, int markDirty,
-                                            void **pixels, int *pitch);
+                                            const SDL_Rect * rect,
+                                            int markDirty, void **pixels,
+                                            int *pitch);
 
 /**
  * \fn void SDL_UnlockTexture(SDL_TextureID textureID)
@@ -883,7 +913,7 @@
 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_TextureID textureID);
 
 /**
- * \fn void SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects)
+ * \fn void SDL_DirtyTexture(SDL_TextureID textureID, int numrects, const SDL_Rect * rects)
  *
  * \brief Mark the specified rectangles of the texture as dirty.
  *
@@ -893,7 +923,8 @@
  * \sa SDL_UnlockTexture()
  */
 extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_TextureID textureID,
-                                              int numrects, SDL_Rect * rects);
+                                              int numrects,
+                                              const SDL_Rect * rects);
 
 /**
  * \fn void SDL_SelectRenderTexture(SDL_TextureID textureID)
@@ -905,7 +936,7 @@
 extern DECLSPEC void SDLCALL SDL_SelectRenderTexture(SDL_TextureID textureID);
 
 /**
- * \fn void SDL_RenderFill(SDL_Rect *rect, Uint32 color)
+ * \fn void SDL_RenderFill(const SDL_Rect *rect, Uint32 color)
  *
  * \brief Fill the current rendering target with the specified color.
  *
@@ -914,10 +945,11 @@
  *
  * \return 0 on success, or -1 if there is no renderer current
  */
-extern DECLSPEC int SDLCALL SDL_RenderFill(SDL_Rect * rect, Uint32 color);
+extern DECLSPEC int SDLCALL SDL_RenderFill(const SDL_Rect * rect,
+                                           Uint32 color);
 
 /**
- * \fn int SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect *srcrect, SDL_Rect *dstrect, Uint32 blendMode, Uint32 scaleMode)
+ * \fn int SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect *srcrect, const SDL_Rect *dstrect, Uint32 blendMode, Uint32 scaleMode)
  *
  * \brief Copy a portion of the texture to the current rendering target.
  *
@@ -932,12 +964,12 @@
  * \note You can check the video driver info to see what operations are supported.
  */
 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_TextureID textureID,
-                                           SDL_Rect * srcrect,
-                                           SDL_Rect * dstrect, int blendMode,
-                                           int scaleMode);
+                                           const SDL_Rect * srcrect,
+                                           const SDL_Rect * dstrect,
+                                           int blendMode, int scaleMode);
 
 /**
- * \fn int SDL_RenderReadPixels(SDL_Rect *rect, void *pixels, int pitch)
+ * \fn int SDL_RenderReadPixels(const SDL_Rect *rect, void *pixels, int pitch)
  *
  * \brief Read pixels from the current rendering target.
  *
@@ -949,11 +981,11 @@
  *
  * \warning This is a very slow operation, and should not be used frequently.
  */
-extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Rect * rect,
+extern DECLSPEC int SDLCALL SDL_RenderReadPixels(const SDL_Rect * rect,
                                                  void *pixels, int pitch);
 
 /**
- * \fn int SDL_RenderWritePixels(SDL_Rect *rect, const void *pixels, int pitch)
+ * \fn int SDL_RenderWritePixels(const SDL_Rect *rect, const void *pixels, int pitch)
  *
  * \brief Write pixels to the current rendering target.
  *
@@ -965,7 +997,7 @@
  *
  * \warning This is a very slow operation, and should not be used frequently.
  */
-extern DECLSPEC int SDLCALL SDL_RenderWritePixels(SDL_Rect * rect,
+extern DECLSPEC int SDLCALL SDL_RenderWritePixels(const SDL_Rect * rect,
                                                   const void *pixels,
                                                   int pitch);
 
--- a/src/SDL_compat.c	Wed Jun 14 08:41:13 2006 +0000
+++ b/src/SDL_compat.c	Thu Jun 15 07:07:07 2006 +0000
@@ -666,6 +666,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);
     }
 
     return gotall;
--- a/src/video/SDL_renderer_sw.c	Wed Jun 14 08:41:13 2006 +0000
+++ b/src/video/SDL_renderer_sw.c	Thu Jun 15 07:07:07 2006 +0000
@@ -34,30 +34,37 @@
                                      SDL_Texture * texture, void **pixels,
                                      int *pitch);
 static int SDL_SW_SetTexturePalette(SDL_Renderer * renderer,
+                                    SDL_Texture * texture,
+                                    const SDL_Color * colors, int firstcolor,
+                                    int ncolors);
+static int SDL_SW_GetTexturePalette(SDL_Renderer * renderer,
                                     SDL_Texture * texture, SDL_Color * colors,
                                     int firstcolor, int ncolors);
 static int SDL_SW_UpdateTexture(SDL_Renderer * renderer,
-                                SDL_Texture * texture, SDL_Rect * rect,
+                                SDL_Texture * texture, const SDL_Rect * rect,
                                 const void *pixels, int pitch);
 static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                              SDL_Rect * rect, int markDirty, void **pixels,
-                              int *pitch);
+                              const SDL_Rect * rect, int markDirty,
+                              void **pixels, int *pitch);
 static void SDL_SW_UnlockTexture(SDL_Renderer * renderer,
                                  SDL_Texture * texture);
 static void SDL_SW_DirtyTexture(SDL_Renderer * renderer,
                                 SDL_Texture * texture, int numrects,
-                                SDL_Rect * rects);
+                                const SDL_Rect * rects);
 static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer,
                                        SDL_Texture * texture);
-static void SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect,
+static void SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
                               Uint32 color);
 static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
-                             SDL_Rect * srcrect, SDL_Rect * dstrect,
-                             int blendMode, int scaleMode);
-static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
-                                   void *pixels, int pitch);
-static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
-                                    const void *pixels, int pitch);
+                             const SDL_Rect * srcrect,
+                             const SDL_Rect * dstrect, int blendMode,
+                             int scaleMode);
+static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer,
+                                   const SDL_Rect * rect, void *pixels,
+                                   int pitch);
+static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer,
+                                    const SDL_Rect * rect, const void *pixels,
+                                    int pitch);
 static void SDL_SW_RenderPresent(SDL_Renderer * renderer);
 static void SDL_SW_DestroyTexture(SDL_Renderer * renderer,
                                   SDL_Texture * texture);
@@ -134,6 +141,7 @@
     renderer->CreateTexture = SDL_SW_CreateTexture;
     renderer->QueryTexturePixels = SDL_SW_QueryTexturePixels;
     renderer->SetTexturePalette = SDL_SW_SetTexturePalette;
+    renderer->GetTexturePalette = SDL_SW_GetTexturePalette;
     renderer->UpdateTexture = SDL_SW_UpdateTexture;
     renderer->LockTexture = SDL_SW_LockTexture;
     renderer->UnlockTexture = SDL_SW_UnlockTexture;
@@ -235,7 +243,8 @@
 
 static int
 SDL_SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
-                         SDL_Color * colors, int firstcolor, int ncolors)
+                         const SDL_Color * colors, int firstcolor,
+                         int ncolors)
 {
     SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
 
@@ -244,8 +253,19 @@
 }
 
 static int
+SDL_SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
+                         SDL_Color * colors, int firstcolor, int ncolors)
+{
+    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+
+    SDL_memcpy(colors, &surface->format->palette->colors[firstcolor],
+               ncolors * sizeof(*colors));
+    return 0;
+}
+
+static int
 SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                     SDL_Rect * rect, const void *pixels, int pitch)
+                     const SDL_Rect * rect, const void *pixels, int pitch)
 {
     SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
     Uint8 *src, *dst;
@@ -267,7 +287,8 @@
 
 static int
 SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                   SDL_Rect * rect, int markDirty, void **pixels, int *pitch)
+                   const SDL_Rect * rect, int markDirty, void **pixels,
+                   int *pitch)
 {
     SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
 
@@ -285,7 +306,7 @@
 
 static void
 SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
-                    int numrects, SDL_Rect * rects)
+                    int numrects, const SDL_Rect * rects)
 {
 }
 
@@ -297,9 +318,11 @@
 }
 
 static void
-SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, Uint32 color)
+SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
+                  Uint32 color)
 {
     SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
+    SDL_Rect real_rect = *rect;
     Uint8 r, g, b, a;
 
     a = (Uint8) ((color >> 24) & 0xFF);
@@ -308,16 +331,18 @@
     b = (Uint8) (color & 0xFF);
     color = SDL_MapRGBA(data->target->format, r, g, b, a);
 
-    SDL_FillRect(data->target, rect, color);
+    SDL_FillRect(data->target, &real_rect, color);
 }
 
 static int
 SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
-                  SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode,
-                  int scaleMode)
+                  const SDL_Rect * srcrect, const SDL_Rect * dstrect,
+                  int blendMode, int scaleMode)
 {
     SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
     SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
+    SDL_Rect real_srcrect = *srcrect;
+    SDL_Rect real_dstrect = *dstrect;
 
     if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
         SDL_SetAlpha(surface, SDL_SRCALPHA, 0);
@@ -326,14 +351,16 @@
     }
     if (scaleMode != SDL_TextureScaleMode_None &&
         (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
-        return SDL_SoftStretch(surface, srcrect, data->target, dstrect);
+        return SDL_SoftStretch(surface, &real_srcrect, data->target,
+                               &real_dstrect);
     } else {
-        return SDL_LowerBlit(surface, srcrect, data->target, dstrect);
+        return SDL_LowerBlit(surface, &real_srcrect, data->target,
+                             &real_dstrect);
     }
 }
 
 static int
-SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
+SDL_SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
                         void *pixels, int pitch)
 {
     SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
@@ -356,7 +383,7 @@
 }
 
 static int
-SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
+SDL_SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
                          const void *pixels, int pitch)
 {
     SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
--- a/src/video/SDL_sysvideo.h	Wed Jun 14 08:41:13 2006 +0000
+++ b/src/video/SDL_sysvideo.h	Thu Jun 15 07:07:07 2006 +0000
@@ -70,26 +70,30 @@
     int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
                                void **pixels, int *pitch);
     int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
+                              const SDL_Color * colors, int firstcolor,
+                              int ncolors);
+    int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
                               SDL_Color * colors, int firstcolor,
                               int ncolors);
     int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
-                          SDL_Rect * rect, const void *pixels, int pitch);
+                          const SDL_Rect * rect, const void *pixels,
+                          int pitch);
     int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
-                        SDL_Rect * rect, int markDirty, void **pixels,
+                        const SDL_Rect * rect, int markDirty, void **pixels,
                         int *pitch);
     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
-                          int numrects, SDL_Rect * rects);
+                          int numrects, const SDL_Rect * rects);
     void (*SelectRenderTexture) (SDL_Renderer * renderer,
                                  SDL_Texture * texture);
-    void (*RenderFill) (SDL_Renderer * renderer, SDL_Rect * rect,
+    void (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect,
                         Uint32 color);
     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
-                       SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode,
-                       int scaleMode);
-    int (*RenderReadPixels) (SDL_Renderer * renderer, SDL_Rect * rect,
+                       const SDL_Rect * srcrect, const SDL_Rect * dstrect,
+                       int blendMode, int scaleMode);
+    int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
                              void *pixels, int pitch);
-    int (*RenderWritePixels) (SDL_Renderer * renderer, SDL_Rect * rect,
+    int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
                               const void *pixels, int pitch);
     void (*RenderPresent) (SDL_Renderer * renderer);
     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
@@ -142,6 +146,7 @@
     SDL_DisplayMode *display_modes;
     SDL_DisplayMode desktop_mode;
     SDL_DisplayMode current_mode;
+    SDL_Palette palette;
 
     int num_render_drivers;
     SDL_RenderDriver *render_drivers;
@@ -184,18 +189,17 @@
      */
     int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
 
-    /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
-       of the physical palette to those in 'colors'.  The return value
-       is 0 if all entries could be set properly or -1 otherwise.
+    /* Sets the color entries of the display palette to those in 'colors'.
+       The return value is 0 if all entries could be set properly or -1
+       otherwise.
      */
-    int (*SetDisplayColors) (_THIS, int firstcolor, int ncolors,
-                             SDL_Color * colors);
+    int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
 
     /* * * */
     /* Window functions
      */
     int (*CreateWindow) (_THIS, SDL_Window * window);
-    int (*CreateWindowFrom) (_THIS, SDL_Window * window, void *data);
+    int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
     void (*SetWindowTitle) (_THIS, SDL_Window * window);
     void (*SetWindowPosition) (_THIS, SDL_Window * window);
     void (*SetWindowSize) (_THIS, SDL_Window * window);
--- a/src/video/SDL_video.c	Wed Jun 14 08:41:13 2006 +0000
+++ b/src/video/SDL_video.c	Thu Jun 15 07:07:07 2006 +0000
@@ -559,9 +559,88 @@
         return 0;
     }
 
+    if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
+        display->palette.ncolors =
+            (1 << SDL_BITSPERPIXEL(display_mode.format));
+        display->palette.colors =
+            (SDL_Color *) SDL_realloc(display->palette.colors,
+                                      display->palette.ncolors *
+                                      sizeof(*display->palette.colors));
+        if (!display->palette.colors) {
+            SDL_OutOfMemory();
+            return -1;
+        }
+        SDL_memset(display->palette.colors, 0xff,
+                   display->palette.ncolors *
+                   sizeof(*display->palette.colors));
+    } else {
+        if (display->palette.colors) {
+            SDL_free(display->palette.colors);
+        }
+        display->palette.colors = NULL;
+        display->palette.ncolors = 0;
+    }
+
     return _this->SetDisplayMode(_this, &display_mode);
 }
 
+int
+SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors)
+{
+    SDL_Palette *palette;
+
+    if (!_this) {
+        SDL_SetError("Video subsystem has not been initialized");
+        return -1;
+    }
+
+    palette = &SDL_CurrentDisplay.palette;
+    if (!palette->ncolors) {
+        SDL_SetError("Display mode does not have a palette");
+        return -1;
+    }
+
+    if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
+        SDL_SetError("Palette indices are out of range");
+        return -1;
+    }
+
+    SDL_memcpy(&palette->colors[firstcolor], colors,
+               ncolors * sizeof(*colors));
+
+    if (_this->SetDisplayPalette) {
+        return _this->SetDisplayPalette(_this, palette);
+    } else {
+        return 0;
+    }
+}
+
+int
+SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors)
+{
+    SDL_Palette *palette;
+
+    if (!_this) {
+        SDL_SetError("Video subsystem has not been initialized");
+        return -1;
+    }
+
+    palette = &SDL_CurrentDisplay.palette;
+    if (!palette->ncolors) {
+        SDL_SetError("Display mode does not have a palette");
+        return -1;
+    }
+
+    if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
+        SDL_SetError("Palette indices are out of range");
+        return -1;
+    }
+
+    SDL_memcpy(colors, &palette->colors[firstcolor],
+               ncolors * sizeof(*colors));
+    return 0;
+}
+
 SDL_WindowID
 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
 {
@@ -620,7 +699,7 @@
 }
 
 SDL_WindowID
-SDL_CreateWindowFrom(void *data)
+SDL_CreateWindowFrom(const void *data)
 {
     SDL_Window window;
     int num_windows;
@@ -1317,7 +1396,7 @@
 }
 
 int
-SDL_SetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
+SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors,
                       int firstcolor, int ncolors)
 {
     SDL_Texture *texture = SDL_GetTextureFromID(textureID);
@@ -1336,7 +1415,26 @@
 }
 
 int
-SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect * rect,
+SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
+                      int firstcolor, int ncolors)
+{
+    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
+    SDL_Renderer *renderer;
+
+    if (!texture) {
+        return -1;
+    }
+
+    renderer = texture->renderer;
+    if (!renderer->GetTexturePalette) {
+        return -1;
+    }
+    return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
+                                       ncolors);
+}
+
+int
+SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
                   const void *pixels, int pitch)
 {
     SDL_Texture *texture = SDL_GetTextureFromID(textureID);
@@ -1354,7 +1452,7 @@
 }
 
 int
-SDL_LockTexture(SDL_TextureID textureID, SDL_Rect * rect, int markDirty,
+SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty,
                 void **pixels, int *pitch)
 {
     SDL_Texture *texture = SDL_GetTextureFromID(textureID);
@@ -1390,7 +1488,8 @@
 }
 
 void
-SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects)
+SDL_DirtyTexture(SDL_TextureID textureID, int numrects,
+                 const SDL_Rect * rects)
 {
     SDL_Texture *texture = SDL_GetTextureFromID(textureID);
     SDL_Renderer *renderer;
@@ -1423,7 +1522,7 @@
 }
 
 int
-SDL_RenderFill(SDL_Rect * rect, Uint32 color)
+SDL_RenderFill(const SDL_Rect * rect, Uint32 color)
 {
     SDL_Renderer *renderer;
 
@@ -1440,8 +1539,8 @@
 }
 
 int
-SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect * srcrect,
-               SDL_Rect * dstrect, int blendMode, int scaleMode)
+SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
+               const SDL_Rect * dstrect, int blendMode, int scaleMode)
 {
     SDL_Texture *texture = SDL_GetTextureFromID(textureID);
     SDL_Renderer *renderer;
@@ -1460,7 +1559,7 @@
 }
 
 int
-SDL_RenderReadPixels(SDL_Rect * rect, void *pixels, int pitch)
+SDL_RenderReadPixels(const SDL_Rect * rect, void *pixels, int pitch)
 {
     SDL_Renderer *renderer;
 
@@ -1477,7 +1576,7 @@
 }
 
 int
-SDL_RenderWritePixels(SDL_Rect * rect, const void *pixels, int pitch)
+SDL_RenderWritePixels(const SDL_Rect * rect, const void *pixels, int pitch)
 {
     SDL_Renderer *renderer;
 
@@ -1617,6 +1716,11 @@
             SDL_free(display->windows);
             display->windows = NULL;
         }
+        if (display->palette.colors) {
+            SDL_free(display->palette.colors);
+            display->palette.colors = NULL;
+            display->palette.ncolors = 0;
+        }
     }
     _this->VideoQuit(_this);
     if (_this->displays) {
--- a/src/video/dummy/SDL_nullvideo.c	Wed Jun 14 08:41:13 2006 +0000
+++ b/src/video/dummy/SDL_nullvideo.c	Thu Jun 15 07:07:07 2006 +0000
@@ -51,10 +51,6 @@
 /* Initialization/Query functions */
 static int DUMMY_VideoInit(_THIS);
 static int DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
-static void DUMMY_CreateWindowSurface(_THIS, SDL_Window * window,
-                                      Uint32 flags);
-static void DUMMY_UpdateWindowSurface(_THIS, SDL_Window * window,
-                                      int numrects, SDL_Rect * rects);
 static void DUMMY_VideoQuit(_THIS);
 
 /* DUMMY driver bootstrap functions */