Skip to content

Commit

Permalink
assign default palette to primary surface
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Dec 14, 2024
1 parent ac19dec commit 806924f
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 3 deletions.
261 changes: 261 additions & 0 deletions inc/ddpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,265 @@ HRESULT ddp_GetEntries(IDirectDrawPaletteImpl* This, DWORD dwFlags, DWORD dwBase
HRESULT ddp_SetEntries(IDirectDrawPaletteImpl* This, DWORD dwFlags, DWORD dwStartingEntry, DWORD dwCount, LPPALETTEENTRY lpEntries);
HRESULT dd_CreatePalette(DWORD dwFlags, LPPALETTEENTRY lpDDColorArray, IDirectDrawPaletteImpl** lpDDPalette, IUnknown FAR* unkOuter);

// Original palette copied from Windows ME
static PALETTEENTRY g_ddp_me_palette[] =
{
{ 0, 0, 0, 0 },
{ 128, 0, 0, 0 },
{ 0, 128, 0, 0 },
{ 128, 128, 0, 0 },
{ 0, 0, 128, 0 },
{ 128, 0, 128, 0 },
{ 0, 128, 128, 0 },
{ 192, 192, 192, 0 },
{ 192, 220, 192, 0 },
{ 166, 202, 240, 0 },
{ 95, 63, 63, 0 },
{ 127, 63, 63, 0 },
{ 159, 63, 63, 0 },
{ 191, 63, 63, 0 },
{ 223, 63, 63, 0 },
{ 255, 63, 63, 0 },
{ 63, 95, 63, 0 },
{ 95, 95, 63, 0 },
{ 127, 95, 63, 0 },
{ 159, 95, 63, 0 },
{ 191, 95, 63, 0 },
{ 223, 95, 63, 0 },
{ 255, 95, 63, 0 },
{ 63, 127, 63, 0 },
{ 95, 127, 63, 0 },
{ 127, 127, 63, 0 },
{ 159, 127, 63, 0 },
{ 191, 127, 63, 0 },
{ 223, 127, 63, 0 },
{ 255, 127, 63, 0 },
{ 63, 159, 63, 0 },
{ 95, 159, 63, 0 },
{ 127, 159, 63, 0 },
{ 159, 159, 63, 0 },
{ 191, 159, 63, 0 },
{ 223, 159, 63, 0 },
{ 255, 159, 63, 0 },
{ 63, 191, 63, 0 },
{ 95, 191, 63, 0 },
{ 127, 191, 63, 0 },
{ 159, 191, 63, 0 },
{ 191, 191, 63, 0 },
{ 223, 191, 63, 0 },
{ 255, 191, 63, 0 },
{ 63, 223, 63, 0 },
{ 95, 223, 63, 0 },
{ 127, 223, 63, 0 },
{ 159, 223, 63, 0 },
{ 191, 223, 63, 0 },
{ 223, 223, 63, 0 },
{ 255, 223, 63, 0 },
{ 63, 255, 63, 0 },
{ 95, 255, 63, 0 },
{ 127, 255, 63, 0 },
{ 159, 255, 63, 0 },
{ 191, 255, 63, 0 },
{ 223, 255, 63, 0 },
{ 255, 255, 63, 0 },
{ 63, 63, 95, 0 },
{ 95, 63, 95, 0 },
{ 127, 63, 95, 0 },
{ 159, 63, 95, 0 },
{ 191, 63, 95, 0 },
{ 223, 63, 95, 0 },
{ 255, 63, 95, 0 },
{ 63, 95, 95, 0 },
{ 95, 95, 95, 0 },
{ 127, 95, 95, 0 },
{ 159, 95, 95, 0 },
{ 191, 95, 95, 0 },
{ 223, 95, 95, 0 },
{ 255, 95, 95, 0 },
{ 63, 127, 95, 0 },
{ 95, 127, 95, 0 },
{ 127, 127, 95, 0 },
{ 159, 127, 95, 0 },
{ 191, 127, 95, 0 },
{ 223, 127, 95, 0 },
{ 255, 127, 95, 0 },
{ 63, 159, 95, 0 },
{ 95, 159, 95, 0 },
{ 127, 159, 95, 0 },
{ 159, 159, 95, 0 },
{ 191, 159, 95, 0 },
{ 223, 159, 95, 0 },
{ 255, 159, 95, 0 },
{ 63, 191, 95, 0 },
{ 95, 191, 95, 0 },
{ 127, 191, 95, 0 },
{ 159, 191, 95, 0 },
{ 191, 191, 95, 0 },
{ 223, 191, 95, 0 },
{ 255, 191, 95, 0 },
{ 63, 223, 95, 0 },
{ 95, 223, 95, 0 },
{ 127, 223, 95, 0 },
{ 159, 223, 95, 0 },
{ 191, 223, 95, 0 },
{ 223, 223, 95, 0 },
{ 255, 223, 95, 0 },
{ 63, 255, 95, 0 },
{ 95, 255, 95, 0 },
{ 127, 255, 95, 0 },
{ 159, 255, 95, 0 },
{ 191, 255, 95, 0 },
{ 223, 255, 95, 0 },
{ 255, 255, 95, 0 },
{ 63, 63, 127, 0 },
{ 95, 63, 127, 0 },
{ 127, 63, 127, 0 },
{ 159, 63, 127, 0 },
{ 191, 63, 127, 0 },
{ 223, 63, 127, 0 },
{ 255, 63, 127, 0 },
{ 63, 95, 127, 0 },
{ 95, 95, 127, 0 },
{ 127, 95, 127, 0 },
{ 159, 95, 127, 0 },
{ 191, 95, 127, 0 },
{ 223, 95, 127, 0 },
{ 255, 95, 127, 0 },
{ 63, 127, 127, 0 },
{ 95, 127, 127, 0 },
{ 127, 127, 127, 0 },
{ 159, 127, 127, 0 },
{ 191, 127, 127, 0 },
{ 223, 127, 127, 0 },
{ 255, 127, 127, 0 },
{ 63, 159, 127, 0 },
{ 95, 159, 127, 0 },
{ 127, 159, 127, 0 },
{ 159, 159, 127, 0 },
{ 191, 159, 127, 0 },
{ 223, 159, 127, 0 },
{ 255, 159, 127, 0 },
{ 63, 191, 127, 0 },
{ 95, 191, 127, 0 },
{ 127, 191, 127, 0 },
{ 159, 191, 127, 0 },
{ 191, 191, 127, 0 },
{ 223, 191, 127, 0 },
{ 255, 191, 127, 0 },
{ 63, 223, 127, 0 },
{ 95, 223, 127, 0 },
{ 127, 223, 127, 0 },
{ 159, 223, 127, 0 },
{ 191, 223, 127, 0 },
{ 223, 223, 127, 0 },
{ 255, 223, 127, 0 },
{ 63, 255, 127, 0 },
{ 95, 255, 127, 0 },
{ 127, 255, 127, 0 },
{ 159, 255, 127, 0 },
{ 191, 255, 127, 0 },
{ 223, 255, 127, 0 },
{ 255, 255, 127, 0 },
{ 63, 63, 159, 0 },
{ 95, 63, 159, 0 },
{ 127, 63, 159, 0 },
{ 159, 63, 159, 0 },
{ 191, 63, 159, 0 },
{ 223, 63, 159, 0 },
{ 255, 63, 159, 0 },
{ 63, 95, 159, 0 },
{ 95, 95, 159, 0 },
{ 127, 95, 159, 0 },
{ 159, 95, 159, 0 },
{ 191, 95, 159, 0 },
{ 223, 95, 159, 0 },
{ 255, 95, 159, 0 },
{ 63, 127, 159, 0 },
{ 95, 127, 159, 0 },
{ 127, 127, 159, 0 },
{ 159, 127, 159, 0 },
{ 191, 127, 159, 0 },
{ 223, 127, 159, 0 },
{ 255, 127, 159, 0 },
{ 63, 159, 159, 0 },
{ 95, 159, 159, 0 },
{ 127, 159, 159, 0 },
{ 159, 159, 159, 0 },
{ 191, 159, 159, 0 },
{ 223, 159, 159, 0 },
{ 255, 159, 159, 0 },
{ 63, 191, 159, 0 },
{ 95, 191, 159, 0 },
{ 127, 191, 159, 0 },
{ 159, 191, 159, 0 },
{ 191, 191, 159, 0 },
{ 223, 191, 159, 0 },
{ 255, 191, 159, 0 },
{ 63, 223, 159, 0 },
{ 95, 223, 159, 0 },
{ 127, 223, 159, 0 },
{ 159, 223, 159, 0 },
{ 191, 223, 159, 0 },
{ 223, 223, 159, 0 },
{ 255, 223, 159, 0 },
{ 63, 255, 159, 0 },
{ 95, 255, 159, 0 },
{ 127, 255, 159, 0 },
{ 159, 255, 159, 0 },
{ 191, 255, 159, 0 },
{ 223, 255, 159, 0 },
{ 255, 255, 159, 0 },
{ 63, 63, 191, 0 },
{ 95, 63, 191, 0 },
{ 127, 63, 191, 0 },
{ 159, 63, 191, 0 },
{ 191, 63, 191, 0 },
{ 223, 63, 191, 0 },
{ 255, 63, 191, 0 },
{ 63, 95, 191, 0 },
{ 95, 95, 191, 0 },
{ 127, 95, 191, 0 },
{ 159, 95, 191, 0 },
{ 191, 95, 191, 0 },
{ 223, 95, 191, 0 },
{ 255, 95, 191, 0 },
{ 63, 127, 191, 0 },
{ 95, 127, 191, 0 },
{ 127, 127, 191, 0 },
{ 159, 127, 191, 0 },
{ 191, 127, 191, 0 },
{ 223, 127, 191, 0 },
{ 255, 127, 191, 0 },
{ 63, 159, 191, 0 },
{ 95, 159, 191, 0 },
{ 127, 159, 191, 0 },
{ 159, 159, 191, 0 },
{ 191, 159, 191, 0 },
{ 223, 159, 191, 0 },
{ 255, 159, 191, 0 },
{ 63, 191, 191, 0 },
{ 95, 191, 191, 0 },
{ 127, 191, 191, 0 },
{ 159, 191, 191, 0 },
{ 191, 191, 191, 0 },
{ 223, 191, 191, 0 },
{ 255, 191, 191, 0 },
{ 63, 223, 191, 0 },
{ 95, 223, 191, 0 },
{ 127, 223, 191, 0 },
{ 159, 223, 191, 0 },
{ 191, 223, 191, 0 },
{ 223, 223, 191, 0 },
{ 255, 251, 240, 0 },
{ 58, 109, 165, 0 },
{ 128, 128, 128, 0 },
{ 255, 0, 0, 0 },
{ 0, 255, 0, 0 },
{ 255, 255, 0, 0 },
{ 0, 0, 255, 0 },
{ 255, 0, 255, 0 },
{ 0, 255, 255, 0 },
{ 255, 255, 255, 0 }
};

#endif
2 changes: 1 addition & 1 deletion src/ddpalette.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ HRESULT dd_CreatePalette(

p->lpVtbl = &g_ddp_vtbl;
p->flags = dwFlags;
ddp_SetEntries(p, dwFlags, 0, 256, lpDDColorArray);
ddp_SetEntries(p, dwFlags, 0, 256, lpDDColorArray);
IDirectDrawPalette_AddRef(p);

*lpDDPalette = p;
Expand Down
17 changes: 15 additions & 2 deletions src/ddsurface.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ddclipper.h"
#include "utils.h"
#include "versionhelpers.h"
#include "ddpalette.h"


LONG g_dds_gdi_handles;
Expand Down Expand Up @@ -1093,8 +1094,7 @@ HRESULT dds_SetPalette(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* lpD
if (lpDDPalette)
IDirectDrawPalette_AddRef(lpDDPalette);

if (This->palette)
IDirectDrawPalette_Release(This->palette);
IDirectDrawPaletteImpl* old_palette = This->palette;

if ((This->caps & DDSCAPS_PRIMARYSURFACE) && g_ddraw.ref)
{
Expand All @@ -1113,6 +1113,9 @@ HRESULT dds_SetPalette(IDirectDrawSurfaceImpl* This, IDirectDrawPaletteImpl* lpD
This->palette = lpDDPalette;
}

if (old_palette)
IDirectDrawPalette_Release(old_palette);

return DD_OK;
}

Expand Down Expand Up @@ -1574,6 +1577,16 @@ HRESULT dd_CreateSurface(
{
g_ddraw.primary = dst_surface;
FakePrimarySurface = dst_surface->surface;

if (dst_surface->bpp == 8)
{
IDirectDrawPaletteImpl* lpDDPalette;
dd_CreatePalette(DDPCAPS_ALLOW256, g_ddp_me_palette, &lpDDPalette, NULL);
dds_SetPalette(dst_surface, lpDDPalette);

// Make sure temp palette will be released once replaced
IDirectDrawPalette_Release(lpDDPalette);
}
}
}

Expand Down

0 comments on commit 806924f

Please sign in to comment.