From d3bfd52c0c258b3fb0e45bef2fd1cad9a451d678 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 15 Jun 2006 07:07:07 +0000 Subject: [PATCH] Working on paletted display and texture support (two different issues) --- include/SDL_pixels.h | 8 ++- include/SDL_video.h | 80 ++++++++++++++------- src/SDL_compat.c | 2 + src/video/SDL_renderer_sw.c | 73 +++++++++++++------ src/video/SDL_sysvideo.h | 32 +++++---- src/video/SDL_video.c | 124 +++++++++++++++++++++++++++++--- src/video/dummy/SDL_nullvideo.c | 4 -- 7 files changed, 247 insertions(+), 76 deletions(-) diff --git a/include/SDL_pixels.h b/include/SDL_pixels.h index 9ba8b99fd..210e2969b 100644 --- a/include/SDL_pixels.h +++ b/include/SDL_pixels.h @@ -108,7 +108,13 @@ enum #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 { diff --git a/include/SDL_video.h b/include/SDL_video.h index d08a95871..5642b3921 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -462,14 +462,26 @@ extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(const 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 @@ extern DECLSPEC SDL_WindowID SDLCALL SDL_CreateWindow(const char *title, * * \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 @@ extern DECLSPEC int SDLCALL SDL_QueryTexturePixels(SDL_TextureID textureID, 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 @@ extern DECLSPEC int SDLCALL SDL_QueryTexturePixels(SDL_TextureID textureID, * \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 @@ extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_TextureID textureID, * \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 @@ extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_TextureID textureID, * \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 int SDLCALL SDL_LockTexture(SDL_TextureID textureID, 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 @@ extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_TextureID textureID); * \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_DirtyTexture(SDL_TextureID textureID, 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 @@ extern DECLSPEC void SDLCALL SDL_SelectRenderTexture(SDL_TextureID textureID); * * \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 @@ extern DECLSPEC int SDLCALL SDL_RenderFill(SDL_Rect * rect, Uint32 color); * \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 @@ extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_TextureID textureID, * * \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 @@ extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Rect * rect, * * \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); diff --git a/src/SDL_compat.c b/src/SDL_compat.c index 838a1f72f..94b7d79d7 100644 --- a/src/SDL_compat.c +++ b/src/SDL_compat.c @@ -666,6 +666,8 @@ SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor, 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; diff --git a/src/video/SDL_renderer_sw.c b/src/video/SDL_renderer_sw.c index fdda066fd..34b1b87c6 100644 --- a/src/video/SDL_renderer_sw.c +++ b/src/video/SDL_renderer_sw.c @@ -34,30 +34,37 @@ static int SDL_SW_QueryTexturePixels(SDL_Renderer * renderer, 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 @@ SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags) 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 @@ SDL_SW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, 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; @@ -243,9 +252,20 @@ SDL_SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, return 0; } +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 @@ SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 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 @@ 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) + int numrects, const SDL_Rect * rects) { } @@ -297,9 +318,11 @@ SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture) } 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 @@ SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, Uint32 color) 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 @@ SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, } 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 @@ SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, } 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; diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 7dd24d098..bc3ac7cc5 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -70,26 +70,30 @@ struct SDL_Renderer 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 @@ struct SDL_VideoDisplay 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 @@ struct SDL_VideoDevice */ 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); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 0f13d0857..73046fb4a 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -559,9 +559,88 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode) 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_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) } SDL_WindowID -SDL_CreateWindowFrom(void *data) +SDL_CreateWindowFrom(const void *data) { SDL_Window window; int num_windows; @@ -1317,7 +1396,7 @@ SDL_QueryTexturePixels(SDL_TextureID textureID, void **pixels, int *pitch) } 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 @@ SDL_SetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, } 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 @@ SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect * rect, } 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 @@ SDL_UnlockTexture(SDL_TextureID textureID) } 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 @@ SDL_SelectRenderTexture(SDL_TextureID textureID) } int -SDL_RenderFill(SDL_Rect * rect, Uint32 color) +SDL_RenderFill(const SDL_Rect * rect, Uint32 color) { SDL_Renderer *renderer; @@ -1440,8 +1539,8 @@ SDL_RenderFill(SDL_Rect * rect, Uint32 color) } 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 @@ SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect * srcrect, } 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 @@ SDL_RenderReadPixels(SDL_Rect * rect, void *pixels, int pitch) } 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_VideoQuit(void) 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) { diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c index 017b64bb7..03cf894cd 100644 --- a/src/video/dummy/SDL_nullvideo.c +++ b/src/video/dummy/SDL_nullvideo.c @@ -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 */