diff --git a/reactos/lib/comctl32/toolbar.c b/reactos/lib/comctl32/toolbar.c index 5856f44b000..381182805b6 100644 --- a/reactos/lib/comctl32/toolbar.c +++ b/reactos/lib/comctl32/toolbar.c @@ -2270,7 +2270,7 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam) TRACE ("creating default image list!\n"); himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, - ILC_COLOR, nButtons, 2); + ILC_COLOR | ILC_MASK, nButtons, 2); TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0); infoPtr->himlInt = himlDef; } @@ -2314,7 +2314,7 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam) DeleteDC (hdcImage); DeleteDC (hdcBitmap); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); } else if (lpAddBmp->hInst == HINST_COMMCTRL) @@ -2325,42 +2325,48 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam) case IDB_STD_SMALL_COLOR: hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDB_STD_SMALL)); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, + hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); break; case IDB_STD_LARGE_COLOR: hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDB_STD_LARGE)); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, + hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); break; case IDB_VIEW_SMALL_COLOR: hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDB_VIEW_SMALL)); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, + hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); break; case IDB_VIEW_LARGE_COLOR: hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDB_VIEW_LARGE)); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, + hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); break; case IDB_HIST_SMALL_COLOR: hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDB_HIST_SMALL)); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, + hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); break; case IDB_HIST_LARGE_COLOR: hbmLoad = LoadBitmapA (COMCTL32_hModule, MAKEINTRESOURCEA(IDB_HIST_LARGE)); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, + hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); break; @@ -2373,7 +2379,7 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam) else { hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID); - nIndex = ImageList_Add (himlDef, hbmLoad, NULL); + nIndex = ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace); DeleteObject (hbmLoad); } @@ -3924,7 +3930,7 @@ TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam) DeleteDC (hdcImage); DeleteDC (hdcBitmap); - ImageList_Add (himlDef, hbmLoad, NULL); + ImageList_AddMasked (himlDef, hbmLoad, comctl32_color.clrBtnFace); nNewBitmaps = ImageList_GetImageCount(himlDef); DeleteObject (hbmLoad); } diff --git a/reactos/subsys/win32k/eng/objects.h b/reactos/subsys/win32k/eng/objects.h index abbbb42eac1..3ebce56183e 100644 --- a/reactos/subsys/win32k/eng/objects.h +++ b/reactos/subsys/win32k/eng/objects.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: objects.h,v 1.21 2003/12/08 18:07:56 fireball Exp $ +/* $Id: objects.h,v 1.22 2003/12/19 22:58:47 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -207,16 +207,24 @@ typedef struct _XLATEGDI { XLATEOBJ XlateObj; HPALETTE DestPal; HPALETTE SourcePal; - - ULONG *translationTable; - - ULONG RedMask; - ULONG GreenMask; - ULONG BlueMask; - INT RedShift; - INT GreenShift; - INT BlueShift; BOOL UseShiftAndMask; + + union { + struct { /* For Shift Translations */ + ULONG RedMask; + ULONG GreenMask; + ULONG BlueMask; + INT RedShift; + INT GreenShift; + INT BlueShift; + }; + struct { /* For Table Translations */ + ULONG *translationTable; + }; + struct { /* For Color -> Mono Translations */ + ULONG BackgroundColor; + }; + }; } XLATEGDI; // List of GDI objects diff --git a/reactos/subsys/win32k/eng/xlate.c b/reactos/subsys/win32k/eng/xlate.c index c386630f705..d0a35121ff1 100644 --- a/reactos/subsys/win32k/eng/xlate.c +++ b/reactos/subsys/win32k/eng/xlate.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: xlate.c,v 1.25 2003/09/26 10:45:44 gvg Exp $ +/* $Id: xlate.c,v 1.26 2003/12/19 22:58:47 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -36,6 +36,7 @@ #include #include #include "handle.h" +#include #define NDEBUG #include @@ -410,6 +411,65 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType, return XlateObj; } +XLATEOBJ * STDCALL IntEngCreateMonoXlate( + USHORT SourcePalType, HPALETTE PaletteDest, HPALETTE PaletteSource, + ULONG BackgroundColor) +{ + HPALETTE NewXlate; + XLATEOBJ *XlateObj; + XLATEGDI *XlateGDI; + PALGDI *SourcePalGDI; + + NewXlate = (HPALETTE)CreateGDIHandle(sizeof(XLATEGDI), sizeof(XLATEOBJ)); + if (!ValidEngHandle(NewXlate)) + return NULL; + + XlateObj = (XLATEOBJ *)AccessUserObject((ULONG)NewXlate); + XlateGDI = (XLATEGDI *)AccessInternalObject((ULONG)NewXlate); + ASSERT(XlateObj); + ASSERT(XlateGDI); + + XlateObj->iSrcType = SourcePalType; + XlateObj->iDstType = PAL_INDEXED; + + // Store handles of palettes in internal Xlate GDI object (or NULLs) + XlateGDI->DestPal = PaletteDest; + XlateGDI->SourcePal = PaletteSource; + + XlateObj->flXlate = XO_TO_MONO; + /* FIXME: Map into source palette type */ + switch (SourcePalType) + { + case PAL_INDEXED: + XlateGDI->BackgroundColor = NtGdiGetNearestPaletteIndex( + PaletteSource, BackgroundColor); + break; + case PAL_RGB: + XlateGDI->BackgroundColor = BackgroundColor; + break; + case PAL_BGR: + XlateGDI->BackgroundColor = + ((BackgroundColor & 0xFF) << 16) | + ((BackgroundColor & 0xFF0000) >> 16) | + (BackgroundColor & 0xFF00); + break; + case PAL_BITFIELDS: + { + SourcePalGDI = PALETTE_LockPalette(PaletteSource); + BitMasksFromPal(SourcePalType, SourcePalGDI, &XlateGDI->RedMask, + &XlateGDI->BlueMask, &XlateGDI->GreenMask); + XlateGDI->RedShift = CalculateShift(0xFF0000) - CalculateShift(XlateGDI->RedMask); + XlateGDI->GreenShift = CalculateShift(0xFF00) - CalculateShift(XlateGDI->GreenMask); + XlateGDI->BlueShift = CalculateShift(0xFF) - CalculateShift(XlateGDI->BlueMask); + XlateGDI->BackgroundColor = ShiftAndMask(XlateGDI, BackgroundColor); + PALETTE_UnlockPalette(PaletteSource); + } + break; + } + + return XlateObj; +} + /* * @implemented */ @@ -434,7 +494,6 @@ XLATEOBJ_iXlate(XLATEOBJ *XlateObj, ULONG Color) { PALGDI *PalGDI; - XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj); ULONG Closest; // Return the original color if there's no color translation object @@ -444,27 +503,35 @@ XLATEOBJ_iXlate(XLATEOBJ *XlateObj, { return Color; } else - if(XlateGDI->UseShiftAndMask) { - return ShiftAndMask(XlateGDI, Color); - } else - if (PAL_RGB == XlateObj->iSrcType || PAL_BGR == XlateObj->iSrcType - || PAL_BITFIELDS == XlateObj->iSrcType) - { - // FIXME: should we cache colors used often? - // FIXME: won't work if destination isn't indexed + XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObjectFromUserObject(XlateObj); - // Extract the destination palette - PalGDI = PALETTE_LockPalette(XlateGDI->DestPal); + if(XlateObj->flXlate & XO_TO_MONO) + { + return Color == XlateGDI->BackgroundColor; + } else + if(XlateGDI->UseShiftAndMask) + { + return ShiftAndMask(XlateGDI, Color); + } else + if (PAL_RGB == XlateObj->iSrcType || PAL_BGR == XlateObj->iSrcType + || PAL_BITFIELDS == XlateObj->iSrcType) + { + // FIXME: should we cache colors used often? + // FIXME: won't work if destination isn't indexed - // Return closest match for the given color - Closest = ClosestColorMatch(XlateGDI, Color, PalGDI->IndexedColors, PalGDI->NumColors); - PALETTE_UnlockPalette(XlateGDI->DestPal); - return Closest; - } else - if(XlateObj->iSrcType == PAL_INDEXED) - { - return XlateGDI->translationTable[Color]; + // Extract the destination palette + PalGDI = PALETTE_LockPalette(XlateGDI->DestPal); + + // Return closest match for the given color + Closest = ClosestColorMatch(XlateGDI, Color, PalGDI->IndexedColors, PalGDI->NumColors); + PALETTE_UnlockPalette(XlateGDI->DestPal); + return Closest; + } else + if(XlateObj->iSrcType == PAL_INDEXED) + { + return XlateGDI->translationTable[Color]; + } } return 0; diff --git a/reactos/subsys/win32k/include/inteng.h b/reactos/subsys/win32k/include/inteng.h index 09760dabd4a..0e5ba2b1526 100644 --- a/reactos/subsys/win32k/include/inteng.h +++ b/reactos/subsys/win32k/include/inteng.h @@ -40,6 +40,10 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType, HPALETTE PaletteDest, HPALETTE PaletteSource); + +XLATEOBJ * STDCALL IntEngCreateMonoXlate( + USHORT SourcePalType, HPALETTE PaletteDest, HPALETTE PaletteSource, + ULONG BackgroundColor); BOOL STDCALL IntEngPolyline(SURFOBJ *DestSurf, CLIPOBJ *Clip, diff --git a/reactos/subsys/win32k/objects/bitmaps.c b/reactos/subsys/win32k/objects/bitmaps.c index fcb73cd2b8f..a9d31b8f0a6 100644 --- a/reactos/subsys/win32k/objects/bitmaps.c +++ b/reactos/subsys/win32k/objects/bitmaps.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: bitmaps.c,v 1.48 2003/12/08 18:09:08 fireball Exp $ */ +/* $Id: bitmaps.c,v 1.49 2003/12/19 22:58:47 navaraf Exp $ */ #undef WIN32_LEAN_AND_MEAN #include #include @@ -194,7 +194,15 @@ BOOL STDCALL NtGdiBitBlt(HDC hDCDest, PALETTE_UnlockPalette(DestPalette); } - XlateObj = (PXLATEOBJ)IntEngCreateXlate(DestMode, SourceMode, DestPalette, SourcePalette); + if (DCDest->w.bitsPerPixel == 1) + { + XlateObj = (PXLATEOBJ)IntEngCreateMonoXlate(SourceMode, DestPalette, + SourcePalette, DCSrc->w.backgroundColor); + } + else + { + XlateObj = (PXLATEOBJ)IntEngCreateXlate(DestMode, SourceMode, DestPalette, SourcePalette); + } if (NULL == XlateObj) { if (UsesSource && hDCSrc != hDCDest) diff --git a/reactos/subsys/win32k/objects/color.c b/reactos/subsys/win32k/objects/color.c index a7fdbbacd98..53a66d39dc2 100644 --- a/reactos/subsys/win32k/objects/color.c +++ b/reactos/subsys/win32k/objects/color.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: color.c,v 1.29 2003/12/14 21:32:52 navaraf Exp $ */ +/* $Id: color.c,v 1.30 2003/12/19 22:58:47 navaraf Exp $ */ // FIXME: Use PXLATEOBJ logicalToSystem instead of int *mapping @@ -302,17 +302,32 @@ COLORREF STDCALL NtGdiGetNearestColor(HDC hDC, UINT STDCALL NtGdiGetNearestPaletteIndex(HPALETTE hpal, COLORREF Color) { +#if 1 + PPALGDI palGDI = (PPALGDI) PALETTE_LockPalette(hpal); + UINT index = 0; + + if (NULL != palGDI) + { + /* Return closest match for the given RGB color */ + index = COLOR_PaletteLookupPixel((LPPALETTEENTRY)palGDI->IndexedColors, palGDI->NumColors, NULL, Color, FALSE); + PALETTE_UnlockPalette(hpal); + } + + return index; +#else PPALOBJ palObj = (PPALOBJ) PALETTE_LockPalette(hpal); UINT index = 0; if (NULL != palObj) { /* Return closest match for the given RGB color */ + ASSERT(palObj->logpalette != NULL); index = COLOR_PaletteLookupPixel(palObj->logpalette->palPalEntry, palObj->logpalette->palNumEntries, NULL, Color, FALSE); PALETTE_UnlockPalette(hpal); } return index; +#endif } UINT STDCALL NtGdiGetPaletteEntries(HPALETTE hpal,