Date: Tue, 27 Aug 2002 16:14:11 +0200
From: Denis Oliver Kropp Subject: Palette support and 8bit color keying fix This patch adds support for 8bit palette modes dropping the RGB332 stuff. It also fixes color keying for 8bit. testsprite (without -bpp >8) looks correct again. --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40478
This commit is contained in:
parent
b653266009
commit
4a1ab27d1f
2 changed files with 96 additions and 57 deletions
|
@ -779,11 +779,11 @@ CheckDirectFB()
|
||||||
else
|
else
|
||||||
AC_MSG_CHECKING(for DirectFB support)
|
AC_MSG_CHECKING(for DirectFB support)
|
||||||
|
|
||||||
if ! $PKG_CONFIG --atleast-pkgconfig-version 0.5 ; then
|
if ! $PKG_CONFIG --atleast-pkgconfig-version 0.7 ; then
|
||||||
AC_MSG_ERROR([*** pkg-config too old; version 0.5 or better required.])
|
AC_MSG_ERROR([*** pkg-config too old; version 0.7 or better required.])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DIRECTFB_REQUIRED_VERSION=0.9.11
|
DIRECTFB_REQUIRED_VERSION=0.9.14
|
||||||
|
|
||||||
if $PKG_CONFIG --atleast-version $DIRECTFB_REQUIRED_VERSION directfb ; then
|
if $PKG_CONFIG --atleast-version $DIRECTFB_REQUIRED_VERSION directfb ; then
|
||||||
DIRECTFB_CFLAGS=`$PKG_CONFIG --cflags directfb`
|
DIRECTFB_CFLAGS=`$PKG_CONFIG --cflags directfb`
|
||||||
|
|
|
@ -158,13 +158,13 @@ static DFBSurfacePixelFormat GetFormatForBpp (int bpp, IDirectFBDisplayLayer *la
|
||||||
|
|
||||||
layer->GetConfiguration (layer, &dlc);
|
layer->GetConfiguration (layer, &dlc);
|
||||||
|
|
||||||
if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat))
|
if (bytes == DFB_BYTES_PER_PIXEL(dlc.pixelformat) && bytes > 1)
|
||||||
return dlc.pixelformat;
|
return dlc.pixelformat;
|
||||||
|
|
||||||
switch (bytes)
|
switch (bytes)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
return DSPF_RGB332;
|
return DSPF_LUT8;
|
||||||
case 2:
|
case 2:
|
||||||
return DSPF_RGB16;
|
return DSPF_RGB16;
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -204,6 +204,7 @@ static DFBEnumerationResult EnumModesCallback (unsigned int width,
|
||||||
|
|
||||||
struct private_hwdata {
|
struct private_hwdata {
|
||||||
IDirectFBSurface *surface;
|
IDirectFBSurface *surface;
|
||||||
|
IDirectFBPalette *palette;
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetDirectFBerror (const char *function, DFBResult code)
|
void SetDirectFBerror (const char *function, DFBResult code)
|
||||||
|
@ -222,6 +223,9 @@ static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format)
|
||||||
{
|
{
|
||||||
switch (format->BitsPerPixel)
|
switch (format->BitsPerPixel)
|
||||||
{
|
{
|
||||||
|
case 8:
|
||||||
|
return DSPF_LUT8;
|
||||||
|
|
||||||
case 16:
|
case 16:
|
||||||
if (format->Rmask == 0xF800 &&
|
if (format->Rmask == 0xF800 &&
|
||||||
format->Gmask == 0x07E0 &&
|
format->Gmask == 0x07E0 &&
|
||||||
|
@ -236,13 +240,6 @@ static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format)
|
||||||
return DSPF_RGB15;
|
return DSPF_RGB15;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
|
||||||
if (format->Rmask == 0xE0 &&
|
|
||||||
format->Gmask == 0x1C &&
|
|
||||||
format->Bmask == 0x03)
|
|
||||||
return DSPF_RGB332;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 24:
|
case 24:
|
||||||
if (format->Rmask == 0xFF0000 &&
|
if (format->Rmask == 0xFF0000 &&
|
||||||
format->Gmask == 0x00FF00 &&
|
format->Gmask == 0x00FF00 &&
|
||||||
|
@ -268,7 +265,7 @@ static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format)
|
||||||
switch (format->BitsPerPixel)
|
switch (format->BitsPerPixel)
|
||||||
{
|
{
|
||||||
case 8:
|
case 8:
|
||||||
return DSPF_RGB332;
|
return DSPF_LUT8;
|
||||||
case 15:
|
case 15:
|
||||||
return DSPF_RGB15;
|
return DSPF_RGB15;
|
||||||
case 16:
|
case 16:
|
||||||
|
@ -283,12 +280,8 @@ static DFBSurfacePixelFormat SDLToDFBPixelFormat (SDL_PixelFormat *format)
|
||||||
return DSPF_UNKNOWN;
|
return DSPF_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const __u8 lookup3to8[] = { 0x00, 0x24, 0x49, 0x6d, 0x92, 0xb6, 0xdb, 0xff };
|
static SDL_Palette *AllocatePalette(int size)
|
||||||
static const __u8 lookup2to8[] = { 0x00, 0x55, 0xaa, 0xff };
|
|
||||||
|
|
||||||
static SDL_Palette *GenerateRGB332Palette()
|
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
SDL_Palette *palette;
|
SDL_Palette *palette;
|
||||||
SDL_Color *colors;
|
SDL_Color *colors;
|
||||||
|
|
||||||
|
@ -299,21 +292,14 @@ static SDL_Palette *GenerateRGB332Palette()
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
colors = calloc (256, sizeof(SDL_Color));
|
colors = calloc (size, sizeof(SDL_Color));
|
||||||
if (!colors)
|
if (!colors)
|
||||||
{
|
{
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<256; i++)
|
palette->ncolors = size;
|
||||||
{
|
|
||||||
colors[i].r = lookup3to8[ i >> 5 ];
|
|
||||||
colors[i].g = lookup3to8[ (i >> 2) & 7 ];
|
|
||||||
colors[i].g = lookup2to8[ i & 3 ];
|
|
||||||
}
|
|
||||||
|
|
||||||
palette->ncolors = 256;
|
|
||||||
palette->colors = colors;
|
palette->colors = colors;
|
||||||
|
|
||||||
return palette;
|
return palette;
|
||||||
|
@ -352,15 +338,17 @@ static int DFBToSDLPixelFormat (DFBSurfacePixelFormat pixelformat, SDL_PixelForm
|
||||||
format->Bmask = 0x000000FF;
|
format->Bmask = 0x000000FF;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DSPF_RGB332:
|
case DSPF_LUT8:
|
||||||
format->Rmask = 0x000000E0;
|
format->Rmask = 0x000000FF;
|
||||||
format->Gmask = 0x0000001C;
|
format->Gmask = 0x000000FF;
|
||||||
format->Bmask = 0x00000003;
|
format->Bmask = 0x000000FF;
|
||||||
|
|
||||||
format->palette = GenerateRGB332Palette();
|
if (!format->palette)
|
||||||
|
format->palette = AllocatePalette(256);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
fprintf (stderr, "SDL_DirectFB: Unsupported pixelformat (0x%08x)!\n", pixelformat);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +365,6 @@ int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
|
||||||
DFBResult ret;
|
DFBResult ret;
|
||||||
DFBCardCapabilities caps;
|
DFBCardCapabilities caps;
|
||||||
DFBDisplayLayerConfig dlc;
|
DFBDisplayLayerConfig dlc;
|
||||||
DFBSurfacePixelFormat format;
|
|
||||||
struct DirectFBEnumRect *rect;
|
struct DirectFBEnumRect *rect;
|
||||||
IDirectFB *dfb = NULL;
|
IDirectFB *dfb = NULL;
|
||||||
IDirectFBDisplayLayer *layer = NULL;
|
IDirectFBDisplayLayer *layer = NULL;
|
||||||
|
@ -417,15 +404,9 @@ int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
|
||||||
/* Query layer configuration to determine the current mode and pixelformat */
|
/* Query layer configuration to determine the current mode and pixelformat */
|
||||||
layer->GetConfiguration (layer, &dlc);
|
layer->GetConfiguration (layer, &dlc);
|
||||||
|
|
||||||
/* FIXME: Returning RGB332 as the default mode doesn't work (everything is black) */
|
/* If current format is not supported use LUT8 as the default */
|
||||||
if ((format = dlc.pixelformat) == DSPF_RGB332)
|
if (DFBToSDLPixelFormat (dlc.pixelformat, vformat))
|
||||||
format = DSPF_RGB16;
|
DFBToSDLPixelFormat (DSPF_LUT8, vformat);
|
||||||
|
|
||||||
if (DFBToSDLPixelFormat (format, vformat))
|
|
||||||
{
|
|
||||||
SDL_SetError ("Unsupported pixelformat");
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Enumerate the available fullscreen modes */
|
/* Enumerate the available fullscreen modes */
|
||||||
ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this);
|
ret = dfb->EnumVideoModes (dfb, EnumModesCallback, this);
|
||||||
|
@ -494,9 +475,10 @@ static SDL_Rect **DirectFB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flag
|
||||||
|
|
||||||
static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
|
static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
|
||||||
{
|
{
|
||||||
DFBResult ret;
|
DFBResult ret;
|
||||||
DFBSurfaceDescription dsc;
|
DFBSurfaceDescription dsc;
|
||||||
DFBSurfacePixelFormat pixelformat;
|
DFBSurfacePixelFormat pixelformat;
|
||||||
|
IDirectFBSurface *surface;
|
||||||
|
|
||||||
fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
|
fprintf (stderr, "SDL DirectFB_SetVideoMode: %dx%d@%d, flags: 0x%08x\n",
|
||||||
width, height, bpp, flags);
|
width, height, bpp, flags);
|
||||||
|
@ -508,6 +490,13 @@ static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width
|
||||||
{
|
{
|
||||||
current->hwdata->surface->Release (current->hwdata->surface);
|
current->hwdata->surface->Release (current->hwdata->surface);
|
||||||
current->hwdata->surface = NULL;
|
current->hwdata->surface = NULL;
|
||||||
|
|
||||||
|
/* And its palette if present */
|
||||||
|
if (current->hwdata->palette)
|
||||||
|
{
|
||||||
|
current->hwdata->palette->Release (current->hwdata->palette);
|
||||||
|
current->hwdata->palette = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!current->hwdata)
|
else if (!current->hwdata)
|
||||||
{
|
{
|
||||||
|
@ -556,17 +545,16 @@ static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width
|
||||||
dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
|
dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0);
|
||||||
dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
|
dsc.pixelformat = GetFormatForBpp (bpp, HIDDEN->layer);
|
||||||
|
|
||||||
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, ¤t->hwdata->surface);
|
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface);
|
||||||
if (ret && (flags & SDL_DOUBLEBUF))
|
if (ret && (flags & SDL_DOUBLEBUF))
|
||||||
{
|
{
|
||||||
/* Try without double buffering */
|
/* Try without double buffering */
|
||||||
dsc.caps &= ~DSCAPS_FLIPPING;
|
dsc.caps &= ~DSCAPS_FLIPPING;
|
||||||
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, ¤t->hwdata->surface);
|
ret = HIDDEN->dfb->CreateSurface (HIDDEN->dfb, &dsc, &surface);
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
SetDirectFBerror ("dfb->CreateSurface", ret);
|
SetDirectFBerror ("dfb->CreateSurface", ret);
|
||||||
current->hwdata->surface = NULL;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,9 +573,20 @@ static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width
|
||||||
if (dsc.caps & DSCAPS_FLIPPING)
|
if (dsc.caps & DSCAPS_FLIPPING)
|
||||||
current->flags |= SDL_DOUBLEBUF;
|
current->flags |= SDL_DOUBLEBUF;
|
||||||
|
|
||||||
current->hwdata->surface->GetPixelFormat (current->hwdata->surface, &pixelformat);
|
surface->GetPixelFormat (surface, &pixelformat);
|
||||||
|
|
||||||
DFBToSDLPixelFormat (pixelformat, current->format);
|
DFBToSDLPixelFormat (pixelformat, current->format);
|
||||||
|
|
||||||
|
/* Get the surface palette (if supported) */
|
||||||
|
if (DFB_PIXELFORMAT_IS_INDEXED( pixelformat ))
|
||||||
|
{
|
||||||
|
surface->GetPalette (surface, ¤t->hwdata->palette);
|
||||||
|
|
||||||
|
current->flags |= SDL_HWPALETTE;
|
||||||
|
}
|
||||||
|
|
||||||
|
current->hwdata->surface = surface;
|
||||||
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,11 +711,14 @@ static int DirectFB_SetHWColorKey(_THIS, SDL_Surface *src, Uint32 key)
|
||||||
SDL_PixelFormat *fmt = src->format;
|
SDL_PixelFormat *fmt = src->format;
|
||||||
IDirectFBSurface *surface = src->hwdata->surface;
|
IDirectFBSurface *surface = src->hwdata->surface;
|
||||||
|
|
||||||
/* ugly */
|
if (fmt->BitsPerPixel == 8)
|
||||||
surface->SetSrcColorKey (surface,
|
surface->SetSrcColorKeyIndex (surface, key);
|
||||||
(key & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
|
else
|
||||||
(key & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
|
/* ugly */
|
||||||
(key & fmt->Bmask) << (fmt->Bloss - fmt->Bshift));
|
surface->SetSrcColorKey (surface,
|
||||||
|
(key & fmt->Rmask) >> (fmt->Rshift - fmt->Rloss),
|
||||||
|
(key & fmt->Gmask) >> (fmt->Gshift - fmt->Gloss),
|
||||||
|
(key & fmt->Bmask) << (fmt->Bloss - fmt->Bshift));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -809,13 +811,50 @@ static void DirectFB_WindowedUpdate(_THIS, int numrects, SDL_Rect *rects)
|
||||||
|
|
||||||
int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
|
int DirectFB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "SDL: Unimplemented DirectFB_SetColors!\n");
|
IDirectFBPalette *palette = this->screen->hwdata->palette;
|
||||||
return -1;
|
|
||||||
|
if (!palette)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (firstcolor > 255)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (firstcolor + ncolors > 256)
|
||||||
|
ncolors = 256 - firstcolor;
|
||||||
|
|
||||||
|
if (ncolors > 0)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
DFBColor entries[ncolors];
|
||||||
|
|
||||||
|
for (i=0; i<ncolors; i++)
|
||||||
|
{
|
||||||
|
entries[i].a = 0xff;
|
||||||
|
entries[i].r = colors[i].r;
|
||||||
|
entries[i].g = colors[i].g;
|
||||||
|
entries[i].b = colors[i].b;
|
||||||
|
}
|
||||||
|
|
||||||
|
palette->SetEntries (palette, entries, ncolors, firstcolor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectFB_VideoQuit(_THIS)
|
void DirectFB_VideoQuit(_THIS)
|
||||||
{
|
{
|
||||||
struct DirectFBEnumRect *rect = enumlist;
|
struct DirectFBEnumRect *rect = enumlist;
|
||||||
|
IDirectFBSurface *surface = this->screen->hwdata->surface;
|
||||||
|
IDirectFBPalette *palette = this->screen->hwdata->palette;
|
||||||
|
|
||||||
|
if (palette)
|
||||||
|
palette->Release (palette);
|
||||||
|
|
||||||
|
if (surface)
|
||||||
|
surface->Release (surface);
|
||||||
|
|
||||||
|
this->screen->hwdata->surface = NULL;
|
||||||
|
this->screen->hwdata->palette = NULL;
|
||||||
|
|
||||||
if (HIDDEN->eventbuffer)
|
if (HIDDEN->eventbuffer)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue