Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Working on paletted display and texture support (two different issues)
  • Loading branch information
slouken committed Jun 15, 2006
1 parent b4cdcb8 commit d3bfd52
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 76 deletions.
8 changes: 7 additions & 1 deletion include/SDL_pixels.h
Expand Up @@ -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
{
Expand Down
80 changes: 56 additions & 24 deletions include/SDL_video.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
*
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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)
Expand All @@ -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.
*
Expand All @@ -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)
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/SDL_compat.c
Expand Up @@ -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;
Expand Down
73 changes: 50 additions & 23 deletions src/video/SDL_renderer_sw.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -235,17 +243,29 @@ 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;

SDL_SetColors(surface, colors, firstcolor, ncolors);
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;
Expand All @@ -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;

Expand All @@ -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)
{
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit d3bfd52

Please sign in to comment.