From 86d248e99b7d34f0b3786ba935f8b688b1b4862e Mon Sep 17 00:00:00 2001 From: Jason Filby Date: Sat, 5 Oct 2002 17:13:16 +0000 Subject: [PATCH] DIB color fix, palette fix svn path=/trunk/; revision=3626 --- reactos/subsys/win32k/eng/palette.c | 1 - reactos/subsys/win32k/objects/dib.c | 31 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/reactos/subsys/win32k/eng/palette.c b/reactos/subsys/win32k/eng/palette.c index 22cf0741851..327cbe3d386 100644 --- a/reactos/subsys/win32k/eng/palette.c +++ b/reactos/subsys/win32k/eng/palette.c @@ -44,7 +44,6 @@ EngCreatePalette(ULONG Mode, if(Mode==PAL_INDEXED) { PalGDI->NumColors = NumColors; - PalGDI->IndexedColors = (PULONG)Colors; } else if(Mode==PAL_BITFIELDS) { diff --git a/reactos/subsys/win32k/objects/dib.c b/reactos/subsys/win32k/objects/dib.c index a78f63c9dfe..2e2e86e8f97 100644 --- a/reactos/subsys/win32k/objects/dib.c +++ b/reactos/subsys/win32k/objects/dib.c @@ -719,10 +719,26 @@ RGBQUAD *DIB_MapPaletteColors(PDC dc, LPBITMAPINFO lpbmi) return lpRGB; } +PALETTEENTRY *DIBColorTableToPaletteEntries(PALETTEENTRY *palEntries, const RGBQUAD *DIBColorTable, ULONG ColorCount) +{ + ULONG i; + + for(i=0; ipeRed = DIBColorTable->rgbRed; + palEntries->peGreen = DIBColorTable->rgbGreen; + palEntries->peBlue = DIBColorTable->rgbBlue; + palEntries++; + DIBColorTable++; + } +} + HPALETTE BuildDIBPalette(BITMAPINFO *bmi, PINT paletteType) { BYTE bits; - ULONG ColourCount; + ULONG ColorCount; + PALETTEENTRY *palEntries; + HPALETTE hPal; // Determine Bits Per Pixel bits = bmi->bmiHeader.biBitCount; @@ -736,18 +752,23 @@ HPALETTE BuildDIBPalette(BITMAPINFO *bmi, PINT paletteType) { *paletteType = PAL_BITFIELDS; } else { - *paletteType = PAL_RGB; // FIXME: This could be BGR, must still check + *paletteType = PAL_RGB; // Would it be BGR, considering the BGR nature of the DIB color table? } if (bmi->bmiHeader.biClrUsed == 0 && bmi->bmiHeader.biBitCount <= 8) { - ColourCount = 1 << bmi->bmiHeader.biBitCount; + ColorCount = 1 << bmi->bmiHeader.biBitCount; } else { - ColourCount = bmi->bmiHeader.biClrUsed; + ColorCount = bmi->bmiHeader.biClrUsed; } - return EngCreatePalette(*paletteType, ColourCount, bmi->bmiColors, 0, 0, 0); + palEntries = ExAllocatePool(NonPagedPool, sizeof(PALETTEENTRY)*ColorCount); + DIBColorTableToPaletteEntries(palEntries, bmi->bmiColors, ColorCount); + hPal = EngCreatePalette(*paletteType, ColorCount, palEntries, 0, 0, 0); + ExFreePool(palEntries); + + return hPal; }