Working on paletted display and texture support (two different issues) SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Thu, 15 Jun 2006 07:07:07 +0000
branchSDL-1.3
changeset 168180a5e6a4e1e2
parent 1680 9488fca10677
child 1682 7ae8018b2e5d
Working on paletted display and texture support (two different issues)
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
     1.1 --- a/include/SDL_pixels.h	Wed Jun 14 08:41:13 2006 +0000
     1.2 +++ b/include/SDL_pixels.h	Thu Jun 15 07:07:07 2006 +0000
     1.3 @@ -108,7 +108,13 @@
     1.4  #define SDL_BITSPERPIXEL(X)	(((X) >> 8) & 0xFF)
     1.5  #define SDL_BYTESPERPIXEL(X)	(((X) >> 0) & 0xFF)
     1.6  
     1.7 -#define SDL_ISPIXELFORMAT_FOURCC(format)    (((format) & 0x8000000) != 0)
     1.8 +#define SDL_ISPIXELFORMAT_INDEXED(format)   \
     1.9 +    ((SDL_PIXELTYPE(format) == SDL_PixelType_Index1) || \
    1.10 +     (SDL_PIXELTYPE(format) == SDL_PixelType_Index4) || \
    1.11 +     (SDL_PIXELTYPE(format) == SDL_PixelType_Index8))
    1.12 +
    1.13 +#define SDL_ISPIXELFORMAT_FOURCC(format)    \
    1.14 +    ((format) && !((format) & 0x8000000))
    1.15  
    1.16  enum
    1.17  {
     2.1 --- a/include/SDL_video.h	Wed Jun 14 08:41:13 2006 +0000
     2.2 +++ b/include/SDL_video.h	Thu Jun 15 07:07:07 2006 +0000
     2.3 @@ -462,14 +462,26 @@
     2.4  extern DECLSPEC int SDLCALL SDL_SetDisplayMode(const SDL_DisplayMode * mode);
     2.5  
     2.6  /**
     2.7 - * \fn int SDL_SetDisplayColormap(SDL_Color *colors, int firstcolor, int ncolors)
     2.8 + * \fn int SDL_SetDisplayPalette(const SDL_Color *colors, int firstcolor, int ncolors)
     2.9   *
    2.10 - * \brief Set the colormap for indexed display modes.
    2.11 + * \brief Set the palette entries for indexed display modes.
    2.12   *
    2.13 - * \return 0 on success, or -1 if not all the colors could be set.
    2.14 + * \return 0 on success, or -1 if the display mode isn't palettized or the colors couldn't be set.
    2.15   */
    2.16 -extern DECLSPEC int SDLCALL SDL_SetDisplayColors(SDL_Color * colors,
    2.17 -                                                 int firstcolor, int ncolors);
    2.18 +extern DECLSPEC int SDLCALL SDL_SetDisplayPalette(const SDL_Color * colors,
    2.19 +                                                  int firstcolor,
    2.20 +                                                  int ncolors);
    2.21 +
    2.22 +/**
    2.23 + * \fn int SDL_GetDisplayPalette(SDL_Color *colors, int firstcolor, int ncolors)
    2.24 + *
    2.25 + * \brief Gets the palette entries for indexed display modes.
    2.26 + *
    2.27 + * \return 0 on success, or -1 if the display mode isn't palettized
    2.28 + */
    2.29 +extern DECLSPEC int SDLCALL SDL_GetDisplayPalette(SDL_Color * colors,
    2.30 +                                                  int firstcolor,
    2.31 +                                                  int ncolors);
    2.32  
    2.33  /**
    2.34   * \fn SDL_WindowID SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
    2.35 @@ -506,7 +518,7 @@
    2.36   *
    2.37   * \sa SDL_DestroyWindow()
    2.38   */
    2.39 -extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindowFrom(void *data);
    2.40 +extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindowFrom(const void *data);
    2.41  
    2.42  /**
    2.43   * \fn Uint32 SDL_GetWindowFlags(SDL_WindowID windowID)
    2.44 @@ -818,7 +830,7 @@
    2.45                                                     void **pixels, int *pitch);
    2.46  
    2.47  /**
    2.48 - * \fn int SDL_SetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, int firstcolor, int ncolors)
    2.49 + * \fn int SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors, int firstcolor, int ncolors)
    2.50   *
    2.51   * \brief Update an indexed texture with a color palette
    2.52   *
    2.53 @@ -830,12 +842,29 @@
    2.54   * \return 0 on success, or -1 if the texture is not valid or not an indexed texture
    2.55   */
    2.56  extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_TextureID textureID,
    2.57 +                                                  const SDL_Color * colors,
    2.58 +                                                  int firstcolor,
    2.59 +                                                  int ncolors);
    2.60 +
    2.61 +/**
    2.62 + * \fn int SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, int firstcolor, int ncolors)
    2.63 + *
    2.64 + * \brief Update an indexed texture with a color palette
    2.65 + *
    2.66 + * \param texture The texture to update
    2.67 + * \param colors The array to fill with RGB color data
    2.68 + * \param firstcolor The first index to retrieve
    2.69 + * \param ncolors The number of palette entries to retrieve
    2.70 + *
    2.71 + * \return 0 on success, or -1 if the texture is not valid or not an indexed texture
    2.72 + */
    2.73 +extern DECLSPEC int SDLCALL SDL_GetTexturePalette(SDL_TextureID textureID,
    2.74                                                    SDL_Color * colors,
    2.75                                                    int firstcolor,
    2.76                                                    int ncolors);
    2.77  
    2.78  /**
    2.79 - * \fn int SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect *rect, const void *pixels, int pitch)
    2.80 + * \fn int SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect *rect, const void *pixels, int pitch)
    2.81   *
    2.82   * \brief Update the given texture rectangle with new pixel data.
    2.83   *
    2.84 @@ -849,11 +878,11 @@
    2.85   * \note This is a very slow function for textures not created with SDL_TextureAccess_Local.
    2.86   */
    2.87  extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_TextureID textureID,
    2.88 -                                              SDL_Rect * rect,
    2.89 +                                              const SDL_Rect * rect,
    2.90                                                const void *pixels, int pitch);
    2.91  
    2.92  /**
    2.93 - * \fn void SDL_LockTexture(SDL_TextureID textureID, SDL_Rect *rect, int markDirty, void **pixels, int *pitch)
    2.94 + * \fn void SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect *rect, int markDirty, void **pixels, int *pitch)
    2.95   *
    2.96   * \brief Lock a portion of the texture for pixel access.
    2.97   *
    2.98 @@ -869,8 +898,9 @@
    2.99   * \sa SDL_UnlockTexture()
   2.100   */
   2.101  extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_TextureID textureID,
   2.102 -                                            SDL_Rect * rect, int markDirty,
   2.103 -                                            void **pixels, int *pitch);
   2.104 +                                            const SDL_Rect * rect,
   2.105 +                                            int markDirty, void **pixels,
   2.106 +                                            int *pitch);
   2.107  
   2.108  /**
   2.109   * \fn void SDL_UnlockTexture(SDL_TextureID textureID)
   2.110 @@ -883,7 +913,7 @@
   2.111  extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_TextureID textureID);
   2.112  
   2.113  /**
   2.114 - * \fn void SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects)
   2.115 + * \fn void SDL_DirtyTexture(SDL_TextureID textureID, int numrects, const SDL_Rect * rects)
   2.116   *
   2.117   * \brief Mark the specified rectangles of the texture as dirty.
   2.118   *
   2.119 @@ -893,7 +923,8 @@
   2.120   * \sa SDL_UnlockTexture()
   2.121   */
   2.122  extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_TextureID textureID,
   2.123 -                                              int numrects, SDL_Rect * rects);
   2.124 +                                              int numrects,
   2.125 +                                              const SDL_Rect * rects);
   2.126  
   2.127  /**
   2.128   * \fn void SDL_SelectRenderTexture(SDL_TextureID textureID)
   2.129 @@ -905,7 +936,7 @@
   2.130  extern DECLSPEC void SDLCALL SDL_SelectRenderTexture(SDL_TextureID textureID);
   2.131  
   2.132  /**
   2.133 - * \fn void SDL_RenderFill(SDL_Rect *rect, Uint32 color)
   2.134 + * \fn void SDL_RenderFill(const SDL_Rect *rect, Uint32 color)
   2.135   *
   2.136   * \brief Fill the current rendering target with the specified color.
   2.137   *
   2.138 @@ -914,10 +945,11 @@
   2.139   *
   2.140   * \return 0 on success, or -1 if there is no renderer current
   2.141   */
   2.142 -extern DECLSPEC int SDLCALL SDL_RenderFill(SDL_Rect * rect, Uint32 color);
   2.143 +extern DECLSPEC int SDLCALL SDL_RenderFill(const SDL_Rect * rect,
   2.144 +                                           Uint32 color);
   2.145  
   2.146  /**
   2.147 - * \fn int SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect *srcrect, SDL_Rect *dstrect, Uint32 blendMode, Uint32 scaleMode)
   2.148 + * \fn int SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect *srcrect, const SDL_Rect *dstrect, Uint32 blendMode, Uint32 scaleMode)
   2.149   *
   2.150   * \brief Copy a portion of the texture to the current rendering target.
   2.151   *
   2.152 @@ -932,12 +964,12 @@
   2.153   * \note You can check the video driver info to see what operations are supported.
   2.154   */
   2.155  extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_TextureID textureID,
   2.156 -                                           SDL_Rect * srcrect,
   2.157 -                                           SDL_Rect * dstrect, int blendMode,
   2.158 -                                           int scaleMode);
   2.159 +                                           const SDL_Rect * srcrect,
   2.160 +                                           const SDL_Rect * dstrect,
   2.161 +                                           int blendMode, int scaleMode);
   2.162  
   2.163  /**
   2.164 - * \fn int SDL_RenderReadPixels(SDL_Rect *rect, void *pixels, int pitch)
   2.165 + * \fn int SDL_RenderReadPixels(const SDL_Rect *rect, void *pixels, int pitch)
   2.166   *
   2.167   * \brief Read pixels from the current rendering target.
   2.168   *
   2.169 @@ -949,11 +981,11 @@
   2.170   *
   2.171   * \warning This is a very slow operation, and should not be used frequently.
   2.172   */
   2.173 -extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Rect * rect,
   2.174 +extern DECLSPEC int SDLCALL SDL_RenderReadPixels(const SDL_Rect * rect,
   2.175                                                   void *pixels, int pitch);
   2.176  
   2.177  /**
   2.178 - * \fn int SDL_RenderWritePixels(SDL_Rect *rect, const void *pixels, int pitch)
   2.179 + * \fn int SDL_RenderWritePixels(const SDL_Rect *rect, const void *pixels, int pitch)
   2.180   *
   2.181   * \brief Write pixels to the current rendering target.
   2.182   *
   2.183 @@ -965,7 +997,7 @@
   2.184   *
   2.185   * \warning This is a very slow operation, and should not be used frequently.
   2.186   */
   2.187 -extern DECLSPEC int SDLCALL SDL_RenderWritePixels(SDL_Rect * rect,
   2.188 +extern DECLSPEC int SDLCALL SDL_RenderWritePixels(const SDL_Rect * rect,
   2.189                                                    const void *pixels,
   2.190                                                    int pitch);
   2.191  
     3.1 --- a/src/SDL_compat.c	Wed Jun 14 08:41:13 2006 +0000
     3.2 +++ b/src/SDL_compat.c	Thu Jun 15 07:07:07 2006 +0000
     3.3 @@ -666,6 +666,8 @@
     3.4          SDL_SetTexturePalette(SDL_VideoTexture,
     3.5                                SDL_VideoSurface->format->palette->colors, 0,
     3.6                                SDL_VideoSurface->format->palette->ncolors);
     3.7 +        SDL_SetDisplayPalette(SDL_VideoSurface->format->palette->colors, 0,
     3.8 +                              SDL_VideoSurface->format->palette->ncolors);
     3.9      }
    3.10  
    3.11      return gotall;
     4.1 --- a/src/video/SDL_renderer_sw.c	Wed Jun 14 08:41:13 2006 +0000
     4.2 +++ b/src/video/SDL_renderer_sw.c	Thu Jun 15 07:07:07 2006 +0000
     4.3 @@ -34,30 +34,37 @@
     4.4                                       SDL_Texture * texture, void **pixels,
     4.5                                       int *pitch);
     4.6  static int SDL_SW_SetTexturePalette(SDL_Renderer * renderer,
     4.7 +                                    SDL_Texture * texture,
     4.8 +                                    const SDL_Color * colors, int firstcolor,
     4.9 +                                    int ncolors);
    4.10 +static int SDL_SW_GetTexturePalette(SDL_Renderer * renderer,
    4.11                                      SDL_Texture * texture, SDL_Color * colors,
    4.12                                      int firstcolor, int ncolors);
    4.13  static int SDL_SW_UpdateTexture(SDL_Renderer * renderer,
    4.14 -                                SDL_Texture * texture, SDL_Rect * rect,
    4.15 +                                SDL_Texture * texture, const SDL_Rect * rect,
    4.16                                  const void *pixels, int pitch);
    4.17  static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    4.18 -                              SDL_Rect * rect, int markDirty, void **pixels,
    4.19 -                              int *pitch);
    4.20 +                              const SDL_Rect * rect, int markDirty,
    4.21 +                              void **pixels, int *pitch);
    4.22  static void SDL_SW_UnlockTexture(SDL_Renderer * renderer,
    4.23                                   SDL_Texture * texture);
    4.24  static void SDL_SW_DirtyTexture(SDL_Renderer * renderer,
    4.25                                  SDL_Texture * texture, int numrects,
    4.26 -                                SDL_Rect * rects);
    4.27 +                                const SDL_Rect * rects);
    4.28  static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer,
    4.29                                         SDL_Texture * texture);
    4.30 -static void SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect,
    4.31 +static void SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    4.32                                Uint32 color);
    4.33  static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    4.34 -                             SDL_Rect * srcrect, SDL_Rect * dstrect,
    4.35 -                             int blendMode, int scaleMode);
    4.36 -static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
    4.37 -                                   void *pixels, int pitch);
    4.38 -static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
    4.39 -                                    const void *pixels, int pitch);
    4.40 +                             const SDL_Rect * srcrect,
    4.41 +                             const SDL_Rect * dstrect, int blendMode,
    4.42 +                             int scaleMode);
    4.43 +static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer,
    4.44 +                                   const SDL_Rect * rect, void *pixels,
    4.45 +                                   int pitch);
    4.46 +static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer,
    4.47 +                                    const SDL_Rect * rect, const void *pixels,
    4.48 +                                    int pitch);
    4.49  static void SDL_SW_RenderPresent(SDL_Renderer * renderer);
    4.50  static void SDL_SW_DestroyTexture(SDL_Renderer * renderer,
    4.51                                    SDL_Texture * texture);
    4.52 @@ -134,6 +141,7 @@
    4.53      renderer->CreateTexture = SDL_SW_CreateTexture;
    4.54      renderer->QueryTexturePixels = SDL_SW_QueryTexturePixels;
    4.55      renderer->SetTexturePalette = SDL_SW_SetTexturePalette;
    4.56 +    renderer->GetTexturePalette = SDL_SW_GetTexturePalette;
    4.57      renderer->UpdateTexture = SDL_SW_UpdateTexture;
    4.58      renderer->LockTexture = SDL_SW_LockTexture;
    4.59      renderer->UnlockTexture = SDL_SW_UnlockTexture;
    4.60 @@ -235,7 +243,8 @@
    4.61  
    4.62  static int
    4.63  SDL_SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
    4.64 -                         SDL_Color * colors, int firstcolor, int ncolors)
    4.65 +                         const SDL_Color * colors, int firstcolor,
    4.66 +                         int ncolors)
    4.67  {
    4.68      SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
    4.69  
    4.70 @@ -244,8 +253,19 @@
    4.71  }
    4.72  
    4.73  static int
    4.74 +SDL_SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
    4.75 +                         SDL_Color * colors, int firstcolor, int ncolors)
    4.76 +{
    4.77 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
    4.78 +
    4.79 +    SDL_memcpy(colors, &surface->format->palette->colors[firstcolor],
    4.80 +               ncolors * sizeof(*colors));
    4.81 +    return 0;
    4.82 +}
    4.83 +
    4.84 +static int
    4.85  SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    4.86 -                     SDL_Rect * rect, const void *pixels, int pitch)
    4.87 +                     const SDL_Rect * rect, const void *pixels, int pitch)
    4.88  {
    4.89      SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
    4.90      Uint8 *src, *dst;
    4.91 @@ -267,7 +287,8 @@
    4.92  
    4.93  static int
    4.94  SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    4.95 -                   SDL_Rect * rect, int markDirty, void **pixels, int *pitch)
    4.96 +                   const SDL_Rect * rect, int markDirty, void **pixels,
    4.97 +                   int *pitch)
    4.98  {
    4.99      SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   4.100  
   4.101 @@ -285,7 +306,7 @@
   4.102  
   4.103  static void
   4.104  SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   4.105 -                    int numrects, SDL_Rect * rects)
   4.106 +                    int numrects, const SDL_Rect * rects)
   4.107  {
   4.108  }
   4.109  
   4.110 @@ -297,9 +318,11 @@
   4.111  }
   4.112  
   4.113  static void
   4.114 -SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, Uint32 color)
   4.115 +SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   4.116 +                  Uint32 color)
   4.117  {
   4.118      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   4.119 +    SDL_Rect real_rect = *rect;
   4.120      Uint8 r, g, b, a;
   4.121  
   4.122      a = (Uint8) ((color >> 24) & 0xFF);
   4.123 @@ -308,16 +331,18 @@
   4.124      b = (Uint8) (color & 0xFF);
   4.125      color = SDL_MapRGBA(data->target->format, r, g, b, a);
   4.126  
   4.127 -    SDL_FillRect(data->target, rect, color);
   4.128 +    SDL_FillRect(data->target, &real_rect, color);
   4.129  }
   4.130  
   4.131  static int
   4.132  SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   4.133 -                  SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode,
   4.134 -                  int scaleMode)
   4.135 +                  const SDL_Rect * srcrect, const SDL_Rect * dstrect,
   4.136 +                  int blendMode, int scaleMode)
   4.137  {
   4.138      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   4.139      SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   4.140 +    SDL_Rect real_srcrect = *srcrect;
   4.141 +    SDL_Rect real_dstrect = *dstrect;
   4.142  
   4.143      if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
   4.144          SDL_SetAlpha(surface, SDL_SRCALPHA, 0);
   4.145 @@ -326,14 +351,16 @@
   4.146      }
   4.147      if (scaleMode != SDL_TextureScaleMode_None &&
   4.148          (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
   4.149 -        return SDL_SoftStretch(surface, srcrect, data->target, dstrect);
   4.150 +        return SDL_SoftStretch(surface, &real_srcrect, data->target,
   4.151 +                               &real_dstrect);
   4.152      } else {
   4.153 -        return SDL_LowerBlit(surface, srcrect, data->target, dstrect);
   4.154 +        return SDL_LowerBlit(surface, &real_srcrect, data->target,
   4.155 +                             &real_dstrect);
   4.156      }
   4.157  }
   4.158  
   4.159  static int
   4.160 -SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
   4.161 +SDL_SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   4.162                          void *pixels, int pitch)
   4.163  {
   4.164      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   4.165 @@ -356,7 +383,7 @@
   4.166  }
   4.167  
   4.168  static int
   4.169 -SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
   4.170 +SDL_SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   4.171                           const void *pixels, int pitch)
   4.172  {
   4.173      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
     5.1 --- a/src/video/SDL_sysvideo.h	Wed Jun 14 08:41:13 2006 +0000
     5.2 +++ b/src/video/SDL_sysvideo.h	Thu Jun 15 07:07:07 2006 +0000
     5.3 @@ -70,26 +70,30 @@
     5.4      int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
     5.5                                 void **pixels, int *pitch);
     5.6      int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
     5.7 +                              const SDL_Color * colors, int firstcolor,
     5.8 +                              int ncolors);
     5.9 +    int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.10                                SDL_Color * colors, int firstcolor,
    5.11                                int ncolors);
    5.12      int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.13 -                          SDL_Rect * rect, const void *pixels, int pitch);
    5.14 +                          const SDL_Rect * rect, const void *pixels,
    5.15 +                          int pitch);
    5.16      int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.17 -                        SDL_Rect * rect, int markDirty, void **pixels,
    5.18 +                        const SDL_Rect * rect, int markDirty, void **pixels,
    5.19                          int *pitch);
    5.20      void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    5.21      void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.22 -                          int numrects, SDL_Rect * rects);
    5.23 +                          int numrects, const SDL_Rect * rects);
    5.24      void (*SelectRenderTexture) (SDL_Renderer * renderer,
    5.25                                   SDL_Texture * texture);
    5.26 -    void (*RenderFill) (SDL_Renderer * renderer, SDL_Rect * rect,
    5.27 +    void (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect,
    5.28                          Uint32 color);
    5.29      int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.30 -                       SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode,
    5.31 -                       int scaleMode);
    5.32 -    int (*RenderReadPixels) (SDL_Renderer * renderer, SDL_Rect * rect,
    5.33 +                       const SDL_Rect * srcrect, const SDL_Rect * dstrect,
    5.34 +                       int blendMode, int scaleMode);
    5.35 +    int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    5.36                               void *pixels, int pitch);
    5.37 -    int (*RenderWritePixels) (SDL_Renderer * renderer, SDL_Rect * rect,
    5.38 +    int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    5.39                                const void *pixels, int pitch);
    5.40      void (*RenderPresent) (SDL_Renderer * renderer);
    5.41      void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    5.42 @@ -142,6 +146,7 @@
    5.43      SDL_DisplayMode *display_modes;
    5.44      SDL_DisplayMode desktop_mode;
    5.45      SDL_DisplayMode current_mode;
    5.46 +    SDL_Palette palette;
    5.47  
    5.48      int num_render_drivers;
    5.49      SDL_RenderDriver *render_drivers;
    5.50 @@ -184,18 +189,17 @@
    5.51       */
    5.52      int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
    5.53  
    5.54 -    /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
    5.55 -       of the physical palette to those in 'colors'.  The return value
    5.56 -       is 0 if all entries could be set properly or -1 otherwise.
    5.57 +    /* Sets the color entries of the display palette to those in 'colors'.
    5.58 +       The return value is 0 if all entries could be set properly or -1
    5.59 +       otherwise.
    5.60       */
    5.61 -    int (*SetDisplayColors) (_THIS, int firstcolor, int ncolors,
    5.62 -                             SDL_Color * colors);
    5.63 +    int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
    5.64  
    5.65      /* * * */
    5.66      /* Window functions
    5.67       */
    5.68      int (*CreateWindow) (_THIS, SDL_Window * window);
    5.69 -    int (*CreateWindowFrom) (_THIS, SDL_Window * window, void *data);
    5.70 +    int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
    5.71      void (*SetWindowTitle) (_THIS, SDL_Window * window);
    5.72      void (*SetWindowPosition) (_THIS, SDL_Window * window);
    5.73      void (*SetWindowSize) (_THIS, SDL_Window * window);
     6.1 --- a/src/video/SDL_video.c	Wed Jun 14 08:41:13 2006 +0000
     6.2 +++ b/src/video/SDL_video.c	Thu Jun 15 07:07:07 2006 +0000
     6.3 @@ -559,9 +559,88 @@
     6.4          return 0;
     6.5      }
     6.6  
     6.7 +    if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
     6.8 +        display->palette.ncolors =
     6.9 +            (1 << SDL_BITSPERPIXEL(display_mode.format));
    6.10 +        display->palette.colors =
    6.11 +            (SDL_Color *) SDL_realloc(display->palette.colors,
    6.12 +                                      display->palette.ncolors *
    6.13 +                                      sizeof(*display->palette.colors));
    6.14 +        if (!display->palette.colors) {
    6.15 +            SDL_OutOfMemory();
    6.16 +            return -1;
    6.17 +        }
    6.18 +        SDL_memset(display->palette.colors, 0xff,
    6.19 +                   display->palette.ncolors *
    6.20 +                   sizeof(*display->palette.colors));
    6.21 +    } else {
    6.22 +        if (display->palette.colors) {
    6.23 +            SDL_free(display->palette.colors);
    6.24 +        }
    6.25 +        display->palette.colors = NULL;
    6.26 +        display->palette.ncolors = 0;
    6.27 +    }
    6.28 +
    6.29      return _this->SetDisplayMode(_this, &display_mode);
    6.30  }
    6.31  
    6.32 +int
    6.33 +SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors)
    6.34 +{
    6.35 +    SDL_Palette *palette;
    6.36 +
    6.37 +    if (!_this) {
    6.38 +        SDL_SetError("Video subsystem has not been initialized");
    6.39 +        return -1;
    6.40 +    }
    6.41 +
    6.42 +    palette = &SDL_CurrentDisplay.palette;
    6.43 +    if (!palette->ncolors) {
    6.44 +        SDL_SetError("Display mode does not have a palette");
    6.45 +        return -1;
    6.46 +    }
    6.47 +
    6.48 +    if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
    6.49 +        SDL_SetError("Palette indices are out of range");
    6.50 +        return -1;
    6.51 +    }
    6.52 +
    6.53 +    SDL_memcpy(&palette->colors[firstcolor], colors,
    6.54 +               ncolors * sizeof(*colors));
    6.55 +
    6.56 +    if (_this->SetDisplayPalette) {
    6.57 +        return _this->SetDisplayPalette(_this, palette);
    6.58 +    } else {
    6.59 +        return 0;
    6.60 +    }
    6.61 +}
    6.62 +
    6.63 +int
    6.64 +SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors)
    6.65 +{
    6.66 +    SDL_Palette *palette;
    6.67 +
    6.68 +    if (!_this) {
    6.69 +        SDL_SetError("Video subsystem has not been initialized");
    6.70 +        return -1;
    6.71 +    }
    6.72 +
    6.73 +    palette = &SDL_CurrentDisplay.palette;
    6.74 +    if (!palette->ncolors) {
    6.75 +        SDL_SetError("Display mode does not have a palette");
    6.76 +        return -1;
    6.77 +    }
    6.78 +
    6.79 +    if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) {
    6.80 +        SDL_SetError("Palette indices are out of range");
    6.81 +        return -1;
    6.82 +    }
    6.83 +
    6.84 +    SDL_memcpy(colors, &palette->colors[firstcolor],
    6.85 +               ncolors * sizeof(*colors));
    6.86 +    return 0;
    6.87 +}
    6.88 +
    6.89  SDL_WindowID
    6.90  SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
    6.91  {
    6.92 @@ -620,7 +699,7 @@
    6.93  }
    6.94  
    6.95  SDL_WindowID
    6.96 -SDL_CreateWindowFrom(void *data)
    6.97 +SDL_CreateWindowFrom(const void *data)
    6.98  {
    6.99      SDL_Window window;
   6.100      int num_windows;
   6.101 @@ -1317,7 +1396,7 @@
   6.102  }
   6.103  
   6.104  int
   6.105 -SDL_SetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
   6.106 +SDL_SetTexturePalette(SDL_TextureID textureID, const SDL_Color * colors,
   6.107                        int firstcolor, int ncolors)
   6.108  {
   6.109      SDL_Texture *texture = SDL_GetTextureFromID(textureID);
   6.110 @@ -1336,7 +1415,26 @@
   6.111  }
   6.112  
   6.113  int
   6.114 -SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect * rect,
   6.115 +SDL_GetTexturePalette(SDL_TextureID textureID, SDL_Color * colors,
   6.116 +                      int firstcolor, int ncolors)
   6.117 +{
   6.118 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
   6.119 +    SDL_Renderer *renderer;
   6.120 +
   6.121 +    if (!texture) {
   6.122 +        return -1;
   6.123 +    }
   6.124 +
   6.125 +    renderer = texture->renderer;
   6.126 +    if (!renderer->GetTexturePalette) {
   6.127 +        return -1;
   6.128 +    }
   6.129 +    return renderer->GetTexturePalette(renderer, texture, colors, firstcolor,
   6.130 +                                       ncolors);
   6.131 +}
   6.132 +
   6.133 +int
   6.134 +SDL_UpdateTexture(SDL_TextureID textureID, const SDL_Rect * rect,
   6.135                    const void *pixels, int pitch)
   6.136  {
   6.137      SDL_Texture *texture = SDL_GetTextureFromID(textureID);
   6.138 @@ -1354,7 +1452,7 @@
   6.139  }
   6.140  
   6.141  int
   6.142 -SDL_LockTexture(SDL_TextureID textureID, SDL_Rect * rect, int markDirty,
   6.143 +SDL_LockTexture(SDL_TextureID textureID, const SDL_Rect * rect, int markDirty,
   6.144                  void **pixels, int *pitch)
   6.145  {
   6.146      SDL_Texture *texture = SDL_GetTextureFromID(textureID);
   6.147 @@ -1390,7 +1488,8 @@
   6.148  }
   6.149  
   6.150  void
   6.151 -SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects)
   6.152 +SDL_DirtyTexture(SDL_TextureID textureID, int numrects,
   6.153 +                 const SDL_Rect * rects)
   6.154  {
   6.155      SDL_Texture *texture = SDL_GetTextureFromID(textureID);
   6.156      SDL_Renderer *renderer;
   6.157 @@ -1423,7 +1522,7 @@
   6.158  }
   6.159  
   6.160  int
   6.161 -SDL_RenderFill(SDL_Rect * rect, Uint32 color)
   6.162 +SDL_RenderFill(const SDL_Rect * rect, Uint32 color)
   6.163  {
   6.164      SDL_Renderer *renderer;
   6.165  
   6.166 @@ -1440,8 +1539,8 @@
   6.167  }
   6.168  
   6.169  int
   6.170 -SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect * srcrect,
   6.171 -               SDL_Rect * dstrect, int blendMode, int scaleMode)
   6.172 +SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
   6.173 +               const SDL_Rect * dstrect, int blendMode, int scaleMode)
   6.174  {
   6.175      SDL_Texture *texture = SDL_GetTextureFromID(textureID);
   6.176      SDL_Renderer *renderer;
   6.177 @@ -1460,7 +1559,7 @@
   6.178  }
   6.179  
   6.180  int
   6.181 -SDL_RenderReadPixels(SDL_Rect * rect, void *pixels, int pitch)
   6.182 +SDL_RenderReadPixels(const SDL_Rect * rect, void *pixels, int pitch)
   6.183  {
   6.184      SDL_Renderer *renderer;
   6.185  
   6.186 @@ -1477,7 +1576,7 @@
   6.187  }
   6.188  
   6.189  int
   6.190 -SDL_RenderWritePixels(SDL_Rect * rect, const void *pixels, int pitch)
   6.191 +SDL_RenderWritePixels(const SDL_Rect * rect, const void *pixels, int pitch)
   6.192  {
   6.193      SDL_Renderer *renderer;
   6.194  
   6.195 @@ -1617,6 +1716,11 @@
   6.196              SDL_free(display->windows);
   6.197              display->windows = NULL;
   6.198          }
   6.199 +        if (display->palette.colors) {
   6.200 +            SDL_free(display->palette.colors);
   6.201 +            display->palette.colors = NULL;
   6.202 +            display->palette.ncolors = 0;
   6.203 +        }
   6.204      }
   6.205      _this->VideoQuit(_this);
   6.206      if (_this->displays) {
     7.1 --- a/src/video/dummy/SDL_nullvideo.c	Wed Jun 14 08:41:13 2006 +0000
     7.2 +++ b/src/video/dummy/SDL_nullvideo.c	Thu Jun 15 07:07:07 2006 +0000
     7.3 @@ -51,10 +51,6 @@
     7.4  /* Initialization/Query functions */
     7.5  static int DUMMY_VideoInit(_THIS);
     7.6  static int DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
     7.7 -static void DUMMY_CreateWindowSurface(_THIS, SDL_Window * window,
     7.8 -                                      Uint32 flags);
     7.9 -static void DUMMY_UpdateWindowSurface(_THIS, SDL_Window * window,
    7.10 -                                      int numrects, SDL_Rect * rects);
    7.11  static void DUMMY_VideoQuit(_THIS);
    7.12  
    7.13  /* DUMMY driver bootstrap functions */