Commit 86cb73f3 authored by Sam Lantinga's avatar Sam Lantinga

Date: Mon, 02 May 2005 04:23:16 -0500

From: Jonathan Atkins
Subject: Re: [PATCH] *CRITICAL* 8bit direct RGB palette not being created

I think that SDL_AllocFormat should create the palette for all 8bit
surfaces.  And when the RGBAmasks match the normal 3:3:2:0 we need to
apply the old behavior.  If the mask doesn't match that, then we need
to make the right palette assuming the masks are valid (I don't think
we validate any masks for high color surfaces...so we wouldn't here)
Then there's always a palette available for the 8bit surfaces.
This restores the normal behavior and allows for masks to create
palettes automatically for odd masks even, which would be a neato
thing to have in there, as SDL never did this before.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401058
parent 00bc47ce
...@@ -452,6 +452,10 @@ SDL_loblit SDL_CalculateBlit0(SDL_Surface *surface, int blit_index) ...@@ -452,6 +452,10 @@ SDL_loblit SDL_CalculateBlit0(SDL_Surface *surface, int blit_index)
{ {
int which; int which;
if ( surface->format->BitsPerPixel > 1 ) {
/* We don't support sub 8-bit packed pixel modes */
return NULL;
}
if ( surface->map->dst->format->BitsPerPixel < 8 ) { if ( surface->map->dst->format->BitsPerPixel < 8 ) {
which = 0; which = 0;
} else { } else {
......
...@@ -112,11 +112,26 @@ SDL_PixelFormat *SDL_AllocFormat(int bpp, ...@@ -112,11 +112,26 @@ SDL_PixelFormat *SDL_AllocFormat(int bpp,
format->Rmask = ((0xFF>>format->Rloss)<<format->Rshift); format->Rmask = ((0xFF>>format->Rloss)<<format->Rshift);
format->Gmask = ((0xFF>>format->Gloss)<<format->Gshift); format->Gmask = ((0xFF>>format->Gloss)<<format->Gshift);
format->Bmask = ((0xFF>>format->Bloss)<<format->Bshift); format->Bmask = ((0xFF>>format->Bloss)<<format->Bshift);
} else { /* Palettized mode */ } else {
int i, ncolors = 1; /* Palettized formats have no mask info */
for ( i = 0; i < bpp; ++i ) { format->Rloss = 8;
ncolors *= 2; format->Gloss = 8;
} format->Bloss = 8;
format->Aloss = 8;
format->Rshift = 0;
format->Gshift = 0;
format->Bshift = 0;
format->Ashift = 0;
format->Rmask = 0;
format->Gmask = 0;
format->Bmask = 0;
format->Amask = 0;
}
if ( bpp <= 8 ) { /* Palettized mode */
int ncolors = 1<<bpp;
#ifdef DEBUG_PALETTE
fprintf(stderr,"bpp=%d ncolors=%d\n",bpp,ncolors);
#endif
format->palette = (SDL_Palette *)malloc(sizeof(SDL_Palette)); format->palette = (SDL_Palette *)malloc(sizeof(SDL_Palette));
if ( format->palette == NULL ) { if ( format->palette == NULL ) {
SDL_FreeFormat(format); SDL_FreeFormat(format);
...@@ -131,7 +146,75 @@ SDL_PixelFormat *SDL_AllocFormat(int bpp, ...@@ -131,7 +146,75 @@ SDL_PixelFormat *SDL_AllocFormat(int bpp,
SDL_OutOfMemory(); SDL_OutOfMemory();
return(NULL); return(NULL);
} }
if ( ncolors == 2 ) { if ( Rmask || Bmask || Gmask ) {
/* create palette according to masks */
int i;
int Rm=0,Gm=0,Bm=0;
int Rw=0,Gw=0,Bw=0;
#ifdef ENABLE_PALETTE_ALPHA
int Am=0,Aw=0;
#endif
if(Rmask)
{
Rw=8-format->Rloss;
for(i=format->Rloss;i>0;i-=Rw)
Rm|=1<<i;
}
#ifdef DEBUG_PALETTE
fprintf(stderr,"Rw=%d Rm=0x%02X\n",Rw,Rm);
#endif
if(Gmask)
{
Gw=8-format->Gloss;
for(i=format->Gloss;i>0;i-=Gw)
Gm|=1<<i;
}
#ifdef DEBUG_PALETTE
fprintf(stderr,"Gw=%d Gm=0x%02X\n",Gw,Gm);
#endif
if(Bmask)
{
Bw=8-format->Bloss;
for(i=format->Bloss;i>0;i-=Bw)
Bm|=1<<i;
}
#ifdef DEBUG_PALETTE
fprintf(stderr,"Bw=%d Bm=0x%02X\n",Bw,Bm);
#endif
#ifdef ENABLE_PALETTE_ALPHA
if(Amask)
{
Aw=8-format->Aloss;
for(i=format->Aloss;i>0;i-=Aw)
Am|=1<<i;
}
# ifdef DEBUG_PALETTE
fprintf(stderr,"Aw=%d Am=0x%02X\n",Aw,Am);
# endif
#endif
for(i=0; i < ncolors; ++i) {
int r,g,b;
r=(i&Rmask)>>format->Rshift;
r=(r<<format->Rloss)|((r*Rm)>>Rw);
format->palette->colors[i].r=r;
g=(i&Gmask)>>format->Gshift;
g=(g<<format->Gloss)|((g*Gm)>>Gw);
format->palette->colors[i].g=g;
b=(i&Bmask)>>format->Bshift;
b=(b<<format->Bloss)|((b*Bm)>>Bw);
format->palette->colors[i].b=b;
#ifdef ENABLE_PALETTE_ALPHA
a=(i&Amask)>>format->Ashift;
a=(a<<format->Aloss)|((a*Am)>>Aw);
format->palette->colors[i].unused=a;
#else
format->palette->colors[i].unused=0;
#endif
}
} else if ( ncolors == 2 ) {
/* Create a black and white bitmap palette */ /* Create a black and white bitmap palette */
format->palette->colors[0].r = 0xFF; format->palette->colors[0].r = 0xFF;
format->palette->colors[0].g = 0xFF; format->palette->colors[0].g = 0xFF;
...@@ -144,20 +227,6 @@ SDL_PixelFormat *SDL_AllocFormat(int bpp, ...@@ -144,20 +227,6 @@ SDL_PixelFormat *SDL_AllocFormat(int bpp,
memset((format->palette)->colors, 0, memset((format->palette)->colors, 0,
(format->palette)->ncolors*sizeof(SDL_Color)); (format->palette)->ncolors*sizeof(SDL_Color));
} }
/* Palettized formats have no mask info */
format->Rloss = 8;
format->Gloss = 8;
format->Bloss = 8;
format->Aloss = 8;
format->Rshift = 0;
format->Gshift = 0;
format->Bshift = 0;
format->Ashift = 0;
format->Rmask = 0;
format->Gmask = 0;
format->Bmask = 0;
format->Amask = 0;
} }
return(format); return(format);
} }
......
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