Author: jgardou Date: Mon Jun 30 18:27:44 2014 New Revision: 63677
URL: http://svn.reactos.org/svn/reactos?rev=63677&view=rev Log: [WIN32K/NTGDI] - Better semi-implementation of CreateHalftonePalette
Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.c trunk/reactos/win32ss/gdi/ntgdi/palette.h
Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.c... ============================================================================== --- trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/ntgdi/palette.c [iso-8859-1] Mon Jun 30 18:27:44 2014 @@ -65,7 +65,7 @@ // Create default palette (20 system colors) gppalDefault = PALETTE_AllocPalWithHandle(PAL_INDEXED, 20, - (PULONG)g_sysPalTemplate, + g_sysPalTemplate, 0, 0, 0); GDIOBJ_vReferenceObjectByPointer(&gppalDefault->BaseObject); PALETTE_UnlockPalette(gppalDefault); @@ -132,7 +132,7 @@ PALETTE_AllocPalette( _In_ ULONG iMode, _In_ ULONG cColors, - _In_opt_ PULONG pulColors, + _In_opt_ const PALETTEENTRY* pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue) @@ -174,12 +174,10 @@ if (iMode & PAL_INDEXED) { /* Check if we got a color array */ - if (pulColors) + if (pEntries) { /* Copy the entries */ - RtlCopyMemory(ppal->IndexedColors, - pulColors, - cColors * sizeof(ULONG)); + RtlCopyMemory(ppal->IndexedColors, pEntries, cColors * sizeof(pEntries[0])); } } else if (iMode & PAL_BITFIELDS) @@ -208,7 +206,7 @@ PALETTE_AllocPalWithHandle( _In_ ULONG iMode, _In_ ULONG cColors, - _In_opt_ PULONG pulColors, + _In_opt_ const PALETTEENTRY* pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue) @@ -216,7 +214,7 @@ PPALETTE ppal;
/* Allocate the palette without a handle */ - ppal = PALETTE_AllocPalette(iMode, cColors, pulColors, flRed, flGreen, flBlue); + ppal = PALETTE_AllocPalette(iMode, cColors, pEntries, flRed, flGreen, flBlue); if (!ppal) return NULL;
/* Insert the palette into the handle table */ @@ -382,7 +380,7 @@ PPALETTE ppal; HPALETTE hpal;
- ppal = PALETTE_AllocPalette(iMode, cColors, pulColors, flRed, flGreen, flBlue); + ppal = PALETTE_AllocPalette(iMode, cColors, (PPALETTEENTRY)pulColors, flRed, flGreen, flBlue); if (!ppal) return NULL;
hpal = GDIOBJ_hInsertObject(&ppal->BaseObject, GDI_OBJ_HMGR_PUBLIC); @@ -454,7 +452,7 @@ pLogPal->palNumEntries = cEntries; ppal = PALETTE_AllocPalWithHandle(PAL_INDEXED, cEntries, - (PULONG)pLogPal->palPalEntry, + pLogPal->palPalEntry, 0, 0, 0);
if (ppal != NULL) @@ -512,107 +510,81 @@ return hpal; }
-HPALETTE APIENTRY NtGdiCreateHalftonePalette(HDC hDC) +HPALETTE +APIENTRY +NtGdiCreateHalftonePalette(HDC hDC) { int i, r, g, b; - struct { - WORD Version; - WORD NumberOfEntries; - PALETTEENTRY aEntries[256]; - } Palette; - - Palette.Version = 0x300; - Palette.NumberOfEntries = 256; - if (IntGetSystemPaletteEntries(hDC, 0, 256, Palette.aEntries) == 0) - { - /* From WINE, more that 256 color math */ - Palette.NumberOfEntries = 20; - for (i = 0; i < Palette.NumberOfEntries; i++) - { - Palette.aEntries[i].peRed=0xff; - Palette.aEntries[i].peGreen=0xff; - Palette.aEntries[i].peBlue=0xff; - Palette.aEntries[i].peFlags=0x00; - } - - Palette.aEntries[0].peRed=0x00; - Palette.aEntries[0].peBlue=0x00; - Palette.aEntries[0].peGreen=0x00; - - /* The first 6 */ - for (i=1; i <= 6; i++) - { - Palette.aEntries[i].peRed=(i%2)?0x80:0; - Palette.aEntries[i].peGreen=(i==2)?0x80:(i==3)?0x80:(i==6)?0x80:0; - Palette.aEntries[i].peBlue=(i>3)?0x80:0; - } - - for (i=7; i <= 12; i++) - { - switch(i) + PALETTEENTRY PalEntries[256]; + PPALETTE ppal; + PDC pdc; + HPALETTE hpal = NULL; + + pdc = DC_LockDc(hDC); + if (!pdc) + { + EngSetLastError(ERROR_INVALID_HANDLE); + return NULL; + } + + RtlZeroMemory(PalEntries, sizeof(PalEntries)); + + /* First and last ten entries are default ones */ + for (i = 0; i < 10; i++) + { + PalEntries[i].peRed = g_sysPalTemplate[i].peRed; + PalEntries[i].peGreen = g_sysPalTemplate[i].peGreen; + PalEntries[i].peBlue = g_sysPalTemplate[i].peBlue; + + PalEntries[246 + i].peRed = g_sysPalTemplate[10 + i].peRed; + PalEntries[246 + i].peGreen = g_sysPalTemplate[10 + i].peGreen; + PalEntries[246 + i].peBlue = g_sysPalTemplate[10 + i].peBlue; + } + + ppal = PALETTE_ShareLockPalette(pdc->dclevel.hpal); + if (ppal && (ppal->flFlags & PAL_INDEXED)) + { + /* FIXME: optimize the palette for the current palette */ + UNIMPLEMENTED + } + else + { + for (r = 0; r < 6; r++) + { + for (g = 0; g < 6; g++) { - case 7: - Palette.aEntries[i].peRed=0xc0; - Palette.aEntries[i].peBlue=0xc0; - Palette.aEntries[i].peGreen=0xc0; - break; - case 8: - Palette.aEntries[i].peRed=0xc0; - Palette.aEntries[i].peGreen=0xdc; - Palette.aEntries[i].peBlue=0xc0; - break; - case 9: - Palette.aEntries[i].peRed=0xa6; - Palette.aEntries[i].peGreen=0xca; - Palette.aEntries[i].peBlue=0xf0; - break; - case 10: - Palette.aEntries[i].peRed=0xff; - Palette.aEntries[i].peGreen=0xfb; - Palette.aEntries[i].peBlue=0xf0; - break; - case 11: - Palette.aEntries[i].peRed=0xa0; - Palette.aEntries[i].peGreen=0xa0; - Palette.aEntries[i].peBlue=0xa4; - break; - case 12: - Palette.aEntries[i].peRed=0x80; - Palette.aEntries[i].peGreen=0x80; - Palette.aEntries[i].peBlue=0x80; - } - } - - for (i=13; i <= 18; i++) - { - Palette.aEntries[i].peRed=(i%2)?0xff:0; - Palette.aEntries[i].peGreen=(i==14)?0xff:(i==15)?0xff:(i==18)?0xff:0; - Palette.aEntries[i].peBlue=(i>15)?0xff:0x00; - } - } - else - { - /* 256 color table */ - for (r = 0; r < 6; r++) - for (g = 0; g < 6; g++) for (b = 0; b < 6; b++) { i = r + g*6 + b*36 + 10; - Palette.aEntries[i].peRed = r * 51; - Palette.aEntries[i].peGreen = g * 51; - Palette.aEntries[i].peBlue = b * 51; + PalEntries[i].peRed = r * 51; + PalEntries[i].peGreen = g * 51; + PalEntries[i].peBlue = b * 51; } + } + }
for (i = 216; i < 246; i++) { int v = (i - 216) << 3; - Palette.aEntries[i].peRed = v; - Palette.aEntries[i].peGreen = v; - Palette.aEntries[i].peBlue = v; - } - } - - return GreCreatePaletteInternal((LOGPALETTE *)&Palette, Palette.NumberOfEntries); + PalEntries[i].peRed = v; + PalEntries[i].peGreen = v; + PalEntries[i].peBlue = v; + } + } + + if (ppal) + PALETTE_ShareUnlockPalette(ppal); + + DC_UnlockDc(pdc); + + ppal = PALETTE_AllocPalWithHandle(PAL_INDEXED, 256, PalEntries, 0, 0, 0); + if (ppal) + { + hpal = ppal->BaseObject.hHmgr; + PALETTE_UnlockPalette(ppal); + } + + return hpal; }
BOOL
Modified: trunk/reactos/win32ss/gdi/ntgdi/palette.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/palette.h... ============================================================================== --- trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] (original) +++ trunk/reactos/win32ss/gdi/ntgdi/palette.h [iso-8859-1] Mon Jun 30 18:27:44 2014 @@ -65,7 +65,7 @@ PALETTE_AllocPalette( _In_ ULONG iMode, _In_ ULONG cColors, - _In_opt_ PULONG pulColors, + _In_opt_ const PALETTEENTRY* pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue); @@ -75,7 +75,7 @@ PALETTE_AllocPalWithHandle( _In_ ULONG iMode, _In_ ULONG cColors, - _In_opt_ PULONG pulColors, + _In_opt_ const PALETTEENTRY* pEntries, _In_ FLONG flRed, _In_ FLONG flGreen, _In_ FLONG flBlue);