Roderick Colenbrander : wined3d: When DDCAPS_ALLOW256 is set, palette entry 0 and 255 are filled with black and white.
Alexandre Julliard
julliard at winehq.org
Tue Feb 19 08:05:12 CST 2008
Module: wine
Branch: master
Commit: 1079f3740780ba078e9490650eb03f384a5e28b6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1079f3740780ba078e9490650eb03f384a5e28b6
Author: Roderick Colenbrander <thunderbird2k at gmx.net>
Date: Sun Feb 17 17:02:17 2008 +0000
wined3d: When DDCAPS_ALLOW256 is set, palette entry 0 and 255 are filled with black and white.
---
dlls/ddraw/tests/dsurface.c | 74 +++++++++++++++++++++++++++++++++++++++++++
dlls/wined3d/palette.c | 14 ++++++++
2 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c
index 0f522db..cc7760e 100644
--- a/dlls/ddraw/tests/dsurface.c
+++ b/dlls/ddraw/tests/dsurface.c
@@ -2364,6 +2364,79 @@ static void BltParamTest(void)
IDirectDrawSurface_Release(surface2);
}
+static void PaletteTest(void)
+{
+ HRESULT hr;
+ IDirectDrawPalette *palette;
+ PALETTEENTRY Table[256];
+ PALETTEENTRY palEntries[256];
+ int i;
+
+ for(i=0; i<256; i++)
+ {
+ Table[i].peRed = 0xff;
+ Table[i].peGreen = 0;
+ Table[i].peBlue = 0;
+ Table[i].peFlags = 0;
+ }
+
+ /* Create a 8bit palette without DDPCAPS_ALLOW256 set */
+ hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_8BIT, Table, &palette, NULL);
+ ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
+
+ /* Read back the palette and verify the entries. Without DDPCAPS_ALLOW256 set
+ / entry 0 and 255 should have been overwritten with black and white */
+ IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
+ ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
+ if(hr == DD_OK)
+ {
+ ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
+ "Palette entry 0 of a palette without DDPCAPS_ALLOW256 set should be (0,0,0) but it is (%d,%d,%d)\n",
+ palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
+ ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
+ "Palette entry 255 of a palette without DDPCAPS_ALLOW256 set should be (255,255,255) but it is (%d,%d,%d)\n",
+ palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
+
+ /* Entry 1-254 should contain red */
+ for(i=1; i<255; i++)
+ ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
+ "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
+ i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
+ }
+
+ /* CreatePalette without DDPCAPS_ALLOW256 ignores entry 0 and 255,
+ / now check we are able to update the entries afterwards. */
+ IDirectDrawPalette_SetEntries(palette , 0, 0, 256, &Table[0]);
+ ok(hr == DD_OK, "SetEntries failed with %08x\n", hr);
+ IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
+ ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
+ if(hr == DD_OK)
+ {
+ ok((palEntries[0].peRed == 0) && (palEntries[0].peGreen == 0) && (palEntries[0].peBlue == 0),
+ "Palette entry 0 should have been set to (0,0,0) but it contains (%d,%d,%d)\n",
+ palEntries[0].peRed, palEntries[0].peGreen, palEntries[0].peBlue);
+ ok((palEntries[255].peRed == 255) && (palEntries[255].peGreen == 255) && (palEntries[255].peBlue == 255),
+ "Palette entry 255 should have been set to (255,255,255) but it contains (%d,%d,%d)\n",
+ palEntries[255].peRed, palEntries[255].peGreen, palEntries[255].peBlue);
+ }
+ IDirectDrawPalette_Release(palette);
+
+ /* Create a 8bit palette with DDPCAPS_ALLOW256 set */
+ hr = IDirectDraw_CreatePalette(lpDD, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, Table, &palette, NULL);
+ ok(hr == DD_OK, "CreatePalette failed with %08x\n", hr);
+ IDirectDrawPalette_GetEntries(palette , 0, 0, 256, &palEntries[0]);
+ ok(hr == DD_OK, "GetEntries failed with %08x\n", hr);
+ if(hr == DD_OK)
+ {
+ /* All entries should contain red */
+ for(i=0; i<256; i++)
+ ok((palEntries[i].peRed == 255) && (palEntries[i].peGreen == 0) && (palEntries[i].peBlue == 0),
+ "Palette entry %d should have contained (255,0,0) but was set to %d,%d,%d)\n",
+ i, palEntries[i].peRed, palEntries[i].peGreen, palEntries[i].peBlue);
+ }
+ IDirectDrawPalette_Release(palette);
+}
+
static void StructSizeTest(void)
{
IDirectDrawSurface *surface1;
@@ -2491,5 +2564,6 @@ START_TEST(dsurface)
PrivateDataTest();
BltParamTest();
StructSizeTest();
+ PaletteTest();
ReleaseDirectDraw();
}
diff --git a/dlls/wined3d/palette.c b/dlls/wined3d/palette.c
index 6548c97..df72246 100644
--- a/dlls/wined3d/palette.c
+++ b/dlls/wined3d/palette.c
@@ -111,6 +111,7 @@ static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface, DW
IWineD3DResourceImpl *res;
TRACE("(%p)->(%08x,%d,%d,%p)\n",This,Flags,Start,Count,PalEnt);
+ TRACE("Palette flags: %#x\n", This->Flags);
if (This->Flags & WINEDDPCAPS_8BITENTRIES) {
unsigned int i;
@@ -122,6 +123,19 @@ static HRESULT WINAPI IWineD3DPaletteImpl_SetEntries(IWineD3DPalette *iface, DW
else {
memcpy(This->palents+Start, PalEnt, Count * sizeof(PALETTEENTRY));
+ /* When WINEDDCAPS_ALLOW256 isn't set we need to override entry 0 with black and 255 with white */
+ if(!(This->Flags & WINEDDPCAPS_ALLOW256))
+ {
+ TRACE("WINEDDPCAPS_ALLOW256 set, overriding palette entry 0 with black and 255 with white\n");
+ This->palents[0].peRed = 0;
+ This->palents[0].peGreen = 0;
+ This->palents[0].peBlue = 0;
+
+ This->palents[255].peRed = 255;
+ This->palents[255].peGreen = 255;
+ This->palents[255].peBlue = 255;
+ }
+
if (This->hpal)
SetPaletteEntries(This->hpal, Start, Count, This->palents+Start);
}
More information about the wine-cvs
mailing list