mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Workaround for corrupted background on toolbar icons
This commit is contained in:
parent
1ab496cbf5
commit
2f85be8952
@ -1,3 +1,4 @@
|
|||||||
|
#include "CompatDirectDrawPalette.h"
|
||||||
#include "CompatDirectDrawSurface.h"
|
#include "CompatDirectDrawSurface.h"
|
||||||
#include "CompatGdi.h"
|
#include "CompatGdi.h"
|
||||||
#include "CompatGdiCaret.h"
|
#include "CompatGdiCaret.h"
|
||||||
@ -107,6 +108,39 @@ namespace
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Workaround for correctly drawing icons with a transparent background using BitBlt and a monochrome
|
||||||
|
bitmap mask. Normally black (index 0) and white (index 255) are selected as foreground and background
|
||||||
|
colors on the target DC so that a BitBlt with the SRCAND ROP would preserve the background pixels and
|
||||||
|
set the foreground pixels to 0. (Logical AND with 0xFF preserves all bits.)
|
||||||
|
But if the physical palette contains another, earlier white entry, SRCAND will be performed with the
|
||||||
|
wrong index (less than 0xFF), erasing some of the bits from all background pixels.
|
||||||
|
This workaround replaces all unwanted white entries with a similar color.
|
||||||
|
*/
|
||||||
|
void replaceDuplicateWhitePaletteEntries(const PALETTEENTRY (&entries)[256])
|
||||||
|
{
|
||||||
|
PALETTEENTRY newEntries[256] = {};
|
||||||
|
memcpy(newEntries, entries, sizeof(entries));
|
||||||
|
|
||||||
|
bool isReplacementDone = false;
|
||||||
|
for (int i = 0; i < 255; ++i)
|
||||||
|
{
|
||||||
|
if (0xFF == entries[i].peRed && 0xFF == entries[i].peGreen && 0xFF == entries[i].peBlue)
|
||||||
|
{
|
||||||
|
newEntries[i].peRed = 0xFE;
|
||||||
|
newEntries[i].peGreen = 0xFE;
|
||||||
|
newEntries[i].peBlue = 0xFE;
|
||||||
|
isReplacementDone = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isReplacementDone)
|
||||||
|
{
|
||||||
|
CompatDirectDrawPalette::s_origVtable.SetEntries(
|
||||||
|
CompatPrimarySurface::palette, 0, 0, 256, newEntries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void unlockPrimarySurface()
|
void unlockPrimarySurface()
|
||||||
{
|
{
|
||||||
GdiFlush();
|
GdiFlush();
|
||||||
@ -276,6 +310,7 @@ namespace CompatGdi
|
|||||||
|
|
||||||
if (0 != memcmp(usedPaletteEntries, g_usedPaletteEntries, sizeof(usedPaletteEntries)))
|
if (0 != memcmp(usedPaletteEntries, g_usedPaletteEntries, sizeof(usedPaletteEntries)))
|
||||||
{
|
{
|
||||||
|
replaceDuplicateWhitePaletteEntries(usedPaletteEntries);
|
||||||
invalidate(nullptr);
|
invalidate(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user