Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Default palette entries to white, instead of black.

More palettized video mode support...
  • Loading branch information
slouken committed Jun 16, 2006
1 parent d3bfd52 commit e05df70ce6d9ee6b25be28579126457820a9302c
@@ -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 */

@@ -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);
@@ -114,7 +114,7 @@ enum
(SDL_PIXELTYPE(format) == SDL_PixelType_Index8))

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

enum
{
@@ -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
@@ -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) {
@@ -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;
@@ -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;
@@ -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) {
@@ -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 */
@@ -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) {
@@ -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;
@@ -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) {
@@ -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));
}
}
@@ -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;
}
}

@@ -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);
@@ -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;

@@ -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;
@@ -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;

@@ -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) {
@@ -159,6 +159,8 @@ struct SDL_VideoDisplay
/* The hash list of textures */
SDL_Texture *textures[64];

SDL_VideoDevice *device;

void *driverdata;
};

@@ -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();
@@ -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);

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

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

SDL_Renderer *
@@ -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;
@@ -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;
@@ -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];
@@ -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);
}

0 comments on commit e05df70

Please sign in to comment.