Commit 75823323 authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug #398

You can use SetColors() before the video mode has been set.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402401
parent 17349bcd
...@@ -1142,6 +1142,7 @@ static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, ...@@ -1142,6 +1142,7 @@ static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors,
ncolors * sizeof(*colors)); ncolors * sizeof(*colors));
} }
if ( current_video && SDL_VideoSurface ) {
vidpal = SDL_VideoSurface->format->palette; vidpal = SDL_VideoSurface->format->palette;
if ( (screen == SDL_ShadowSurface) && vidpal ) { if ( (screen == SDL_ShadowSurface) && vidpal ) {
/* /*
...@@ -1153,6 +1154,7 @@ static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, ...@@ -1153,6 +1154,7 @@ static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors,
SDL_memcpy(vidpal->colors + firstcolor, colors, SDL_memcpy(vidpal->colors + firstcolor, colors,
ncolors * sizeof(*colors)); ncolors * sizeof(*colors));
} }
}
SDL_FormatChanged(screen); SDL_FormatChanged(screen);
} }
...@@ -1244,13 +1246,13 @@ int SDL_SetPalette(SDL_Surface *screen, int which, ...@@ -1244,13 +1246,13 @@ int SDL_SetPalette(SDL_Surface *screen, int which,
int gotall; int gotall;
int palsize; int palsize;
if ( ! current_video ) { if ( !screen ) {
return 0; return 0;
} }
if ( screen != SDL_PublicSurface ) { if ( !current_video || screen != SDL_PublicSurface ) {
/* only screens have physical palettes */ /* only screens have physical palettes */
which &= ~SDL_PHYSPAL; which &= ~SDL_PHYSPAL;
} else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) { } else if ( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) {
/* hardware palettes required for split colormaps */ /* hardware palettes required for split colormaps */
which |= SDL_PHYSPAL | SDL_LOGPAL; which |= SDL_PHYSPAL | SDL_LOGPAL;
} }
...@@ -1283,16 +1285,14 @@ int SDL_SetPalette(SDL_Surface *screen, int which, ...@@ -1283,16 +1285,14 @@ int SDL_SetPalette(SDL_Surface *screen, int which,
* program's idea of what the screen looks like, but changes * program's idea of what the screen looks like, but changes
* its actual appearance. * its actual appearance.
*/ */
if(!video) if ( !video->physpal && !(which & SDL_LOGPAL) ) {
return gotall; /* video not yet initialized */
if(!video->physpal && !(which & SDL_LOGPAL) ) {
/* Lazy physical palette allocation */ /* Lazy physical palette allocation */
int size; int size;
SDL_Palette *pp = SDL_malloc(sizeof(*pp)); SDL_Palette *pp = SDL_malloc(sizeof(*pp));
if ( !pp ) { if ( !pp ) {
return 0; return 0;
} }
current_video->physpal = pp; video->physpal = pp;
pp->ncolors = pal->ncolors; pp->ncolors = pal->ncolors;
size = pp->ncolors * sizeof(SDL_Color); size = pp->ncolors * sizeof(SDL_Color);
pp->colors = SDL_malloc(size); pp->colors = SDL_malloc(size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment