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

Commit

Permalink
Default palette entries to white, instead of black.
Browse files Browse the repository at this point in the history
More palettized video mode support...
  • Loading branch information
slouken committed Jun 16, 2006
1 parent d3bfd52 commit e05df70
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 32 deletions.
8 changes: 4 additions & 4 deletions include/SDL_compat.h
Expand Up @@ -44,8 +44,8 @@ extern "C" {
#define SDL_RESIZABLE 0x01000000
#define SDL_NOFRAME 0x02000000
#define SDL_OPENGL 0x04000000
#define SDL_ASYNCBLIT 0x00000000
#define SDL_HWACCEL 0x00000000
#define SDL_ASYNCBLIT 0x08000000 /* Not used */
#define SDL_HWACCEL 0x08000000 /* Not used */
#define SDL_SCREEN_SURFACE 0x10000000 /* Surface is a window screen surface */
#define SDL_SHADOW_SURFACE 0x20000000 /* Surface is a window shadow surface */

Expand Down Expand Up @@ -146,10 +146,10 @@ extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow(void);
extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen(SDL_Surface * surface);
extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput(SDL_GrabMode mode);
extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, int flags,
SDL_Color * colors,
const SDL_Color * colors,
int firstcolor, int ncolors);
extern DECLSPEC int SDLCALL SDL_SetScreenColors(SDL_Surface * screen,
SDL_Color * colors,
const SDL_Color * colors,
int firstcolor, int ncolors);
extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo * info);
extern DECLSPEC Uint8 SDLCALL SDL_GetAppState(void);
Expand Down
2 changes: 1 addition & 1 deletion include/SDL_pixels.h
Expand Up @@ -114,7 +114,7 @@ enum
(SDL_PIXELTYPE(format) == SDL_PixelType_Index8))

#define SDL_ISPIXELFORMAT_FOURCC(format) \
((format) && !((format) & 0x8000000))
((format) && !((format) & 0x80000000))

enum
{
Expand Down
4 changes: 2 additions & 2 deletions include/SDL_video.h
Expand Up @@ -1082,8 +1082,8 @@ extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green,
* emulation.
*/
extern DECLSPEC int SDLCALL SDL_SetColors(SDL_Surface * surface,
SDL_Color * colors, int firstcolor,
int ncolors);
const SDL_Color * colors,
int firstcolor, int ncolors);

/*
* Maps an RGB triple to an opaque pixel value for a given pixel format
Expand Down
40 changes: 37 additions & 3 deletions src/SDL_compat.c
Expand Up @@ -218,6 +218,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
Uint32 desktop_format;
Uint32 desired_format;
Uint32 texture_format;
Uint32 surface_flags;

if (!SDL_GetVideoDevice()) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
Expand Down Expand Up @@ -264,6 +265,21 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
return NULL;
}

window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
surface_flags = SDL_SCREEN_SURFACE;
if (window_flags & SDL_WINDOW_FULLSCREEN) {
surface_flags |= SDL_FULLSCREEN;
}
if (window_flags & SDL_WINDOW_OPENGL) {
surface_flags |= SDL_OPENGL;
}
if (window_flags & SDL_WINDOW_RESIZABLE) {
surface_flags |= SDL_RESIZABLE;
}
if (window_flags & SDL_WINDOW_BORDERLESS) {
surface_flags |= SDL_NOFRAME;
}

/* Set up the desired display mode */
desktop_mode = SDL_GetDesktopDisplayMode();
desktop_format = desktop_mode->format;
Expand Down Expand Up @@ -323,6 +339,18 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
return NULL;
}

/* If we're in OpenGL mode, just create a stub surface and we're done! */
if (flags & SDL_OPENGL) {
SDL_VideoSurface =
SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
if (!SDL_VideoSurface) {
return NULL;
}
SDL_VideoSurface->flags |= surface_flags;
SDL_PublicSurface = SDL_VideoSurface;
return SDL_PublicSurface;
}

/* Create a renderer for the window */
if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
return NULL;
Expand All @@ -345,6 +373,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
if (!SDL_VideoSurface) {
return NULL;
}
SDL_VideoSurface->flags |= surface_flags;

/* Set a default screen palette */
if (SDL_VideoSurface->format->palette) {
Expand All @@ -354,6 +383,8 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
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);
}

/* Create a shadow surface if necessary */
Expand All @@ -377,6 +408,9 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
if (!SDL_ShadowSurface) {
return NULL;
}
surface_flags &= ~SDL_SCREEN_SURFACE;
surface_flags |= SDL_SHADOW_SURFACE;
SDL_ShadowSurface->flags |= surface_flags;

/* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
if (SDL_ShadowSurface->format->palette) {
Expand Down Expand Up @@ -615,15 +649,15 @@ SDL_Linked_Version(void)
}

int
SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors,
SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
int firstcolor, int ncolors)
{
SDL_SetColors(surface, colors, firstcolor, ncolors);
}

int
SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
int ncolors)
SDL_SetScreenColors(SDL_Surface * screen, const SDL_Color * colors,
int firstcolor, int ncolors)
{
SDL_Palette *pal;
int gotall;
Expand Down
7 changes: 4 additions & 3 deletions src/video/SDL_pixels.c
Expand Up @@ -386,7 +386,7 @@ SDL_AllocFormat(int bpp,
a = (a << format->Aloss) | ((a * Am) >> Aw);
format->palette->colors[i].unused = a;
#else
format->palette->colors[i].unused = 0;
format->palette->colors[i].unused = SDL_ALPHA_OPAQUE;
#endif
}
} else if (ncolors == 2) {
Expand All @@ -399,7 +399,7 @@ SDL_AllocFormat(int bpp,
format->palette->colors[1].b = 0x00;
} else {
/* Create an empty palette */
SDL_memset((format->palette)->colors, 0,
SDL_memset((format->palette)->colors, 0xFF,
(format->palette)->ncolors * sizeof(SDL_Color));
}
}
Expand Down Expand Up @@ -474,6 +474,7 @@ SDL_DitherColors(SDL_Color * colors, int bpp)
b |= b << 2;
b |= b << 4;
colors[i].b = b;
colors[i].unused = SDL_ALPHA_OPAQUE;
}
}

Expand Down Expand Up @@ -696,7 +697,7 @@ MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical)

/* SDL_DitherColors does not initialize the 'unused' component of colors,
but Map1to1 compares it against pal, so we should initialize it. */
SDL_memset(colors, 0, sizeof(colors));
SDL_memset(colors, 0xFF, sizeof(colors));

dithered.ncolors = 256;
SDL_DitherColors(colors, 8);
Expand Down
10 changes: 4 additions & 6 deletions src/video/SDL_surface.c
Expand Up @@ -39,7 +39,6 @@ SDL_CreateRGBSurface(Uint32 flags,
int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
SDL_Surface *screen;
SDL_Surface *surface;

Expand Down Expand Up @@ -170,7 +169,7 @@ SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID)
* Set the palette in a blittable surface
*/
int
SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor,
SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
int ncolors)
{
SDL_Palette *pal;
Expand Down Expand Up @@ -557,7 +556,6 @@ SDL_FillRect4(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
int
SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
int x, y;
Uint8 *row;

Expand Down Expand Up @@ -789,9 +787,9 @@ SDL_ConvertSurface(SDL_Surface * surface,
if (format->palette != NULL) {
int i;
for (i = 0; i < format->palette->ncolors; ++i) {
if ((format->palette->colors[i].r != 0) ||
(format->palette->colors[i].g != 0) ||
(format->palette->colors[i].b != 0))
if ((format->palette->colors[i].r != 0xFF) ||
(format->palette->colors[i].g != 0xFF) ||
(format->palette->colors[i].b != 0xFF))
break;
}
if (i == format->palette->ncolors) {
Expand Down
2 changes: 2 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -159,6 +159,8 @@ struct SDL_VideoDisplay
/* The hash list of textures */
SDL_Texture *textures[64];

SDL_VideoDevice *device;

void *driverdata;
};

Expand Down
1 change: 1 addition & 0 deletions src/video/SDL_video.c
Expand Up @@ -333,6 +333,7 @@ SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
if (displays) {
index = _this->num_displays++;
displays[index] = *display;
displays[index].device = _this;
_this->displays = displays;
} else {
SDL_OutOfMemory();
Expand Down
37 changes: 24 additions & 13 deletions src/video/dummy/SDL_nullrender.c
Expand Up @@ -32,11 +32,11 @@ static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
SDL_Rect * rect, void *pixels,
const SDL_Rect * rect, void *pixels,
int pitch);
static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
SDL_Rect * rect, const void *pixels,
int pitch);
const SDL_Rect * rect,
const void *pixels, int pitch);
static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);

Expand All @@ -57,7 +57,7 @@ SDL_RenderDriver SDL_DUMMY_RenderDriver = {

typedef struct
{
SDL_Surface *screen;
SDL_Surface *surface;
} SDL_DUMMY_RenderData;

SDL_Renderer *
Expand Down Expand Up @@ -99,24 +99,34 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->window = window;
renderer->driverdata = data;

data->screen =
data->surface =
SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
Bmask, Amask);
if (!data->screen) {
if (!data->surface) {
SDL_DUMMY_DestroyRenderer(renderer);
return NULL;
}

/* If the display has a palette, use it for the window surfaces */
if (window->display->palette.ncolors) {
SDL_PixelFormat *format = data->surface->format;
if (format->palette->colors) {
SDL_free(format->palette->colors);
}
SDL_free(format->palette);
format->palette = &window->display->palette;
}

return renderer;
}

int
SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
void *pixels, int pitch)
{
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
SDL_Surface *surface = data->screen;
SDL_Surface *surface = data->surface;
Uint8 *src, *dst;
int row;
size_t length;
Expand All @@ -135,12 +145,12 @@ SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
}

int
SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
const void *pixels, int pitch)
{
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
SDL_Surface *surface = data->screen;
SDL_Surface *surface = data->surface;
Uint8 *src, *dst;
int row;
size_t length;
Expand All @@ -164,7 +174,7 @@ SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
static int frame_number;
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
SDL_Surface *surface = data->screen;
SDL_Surface *surface = data->surface;

if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
char file[128];
Expand All @@ -181,8 +191,9 @@ SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer)
(SDL_DUMMY_RenderData *) renderer->driverdata;

if (data) {
if (data->screen) {
SDL_FreeSurface(data->screen);
if (data->surface) {
data->surface->format->palette = NULL;
SDL_FreeSurface(data->surface);
}
SDL_free(data);
}
Expand Down

0 comments on commit e05df70

Please sign in to comment.