From 4309d1082eab8aadd5ba2f51a852b95f23e83fd8 Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Sun, 28 Mar 2004 21:46:26 +0000 Subject: [PATCH] Partly (not working) implementation of TransparentBlt() svn path=/trunk/; revision=8912 --- reactos/iface/addsys/w32ksvc.db | 1 + reactos/include/win32k/bitmaps.h | 17 ++++ reactos/lib/gdi32/objects/bitblt.c | 90 ++---------------- reactos/subsys/win32k/ntuser/msgqueue.c | 4 +- reactos/subsys/win32k/ntuser/window.c | 4 +- reactos/subsys/win32k/objects/bitmaps.c | 119 +++++++++++++++++++++++- 6 files changed, 145 insertions(+), 90 deletions(-) diff --git a/reactos/iface/addsys/w32ksvc.db b/reactos/iface/addsys/w32ksvc.db index 3a28544c83a..7d408072e4d 100644 --- a/reactos/iface/addsys/w32ksvc.db +++ b/reactos/iface/addsys/w32ksvc.db @@ -274,6 +274,7 @@ NtGdiStrokeAndFillPath 1 NtGdiStrokePath 1 NtGdiSwapBuffers 1 NtGdiTextOut 5 +NtGdiTransparentBlt 11 NtGdiTranslateCharsetInfo 3 NtGdiUnrealizeObject 2 NtGdiUpdateColors 1 diff --git a/reactos/include/win32k/bitmaps.h b/reactos/include/win32k/bitmaps.h index bbd9f917e87..3e2282fb6bb 100644 --- a/reactos/include/win32k/bitmaps.h +++ b/reactos/include/win32k/bitmaps.h @@ -304,5 +304,22 @@ NtGdiStretchDIBits ( UINT Usage, DWORD ROP ); + +BOOL +STDCALL +NtGdiTransparentBlt( + HDC hdcDst, + INT xDst, + INT yDst, + INT cxDst, + INT cyDst, + HDC hdcSrc, + INT xSrc, + INT ySrc, + INT cxSrc, + INT cySrc, + COLORREF TransColor + ); + #endif diff --git a/reactos/lib/gdi32/objects/bitblt.c b/reactos/lib/gdi32/objects/bitblt.c index acd6804f487..fa811ce72e0 100644 --- a/reactos/lib/gdi32/objects/bitblt.c +++ b/reactos/lib/gdi32/objects/bitblt.c @@ -1,13 +1,10 @@ -/* $Id: bitblt.c,v 1.19 2004/03/24 00:13:31 royce Exp $ +/* $Id: bitblt.c,v 1.20 2004/03/28 21:46:26 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/gdi32/object/bitblt.c * PURPOSE: * PROGRAMMER: - * - * GdiTransparentBlt Copyright Kevin Koltzau - * adapted from WINE 2-13-04 */ #ifdef UNICODE @@ -396,87 +393,12 @@ PolyPatBlt(HDC hDC,DWORD dwRop,PPATRECT pRects,int cRects,ULONG Reserved) */ WINBOOL STDCALL -GdiTransparentBlt( HDC hdcDst, int xDst, int yDst, int cxDst, int cyDst, - HDC hdcSrc, int xSrc, int ySrc, int cxSrc, int cySrc, - COLORREF TransColor ) +GdiTransparentBlt(HDC hdcDst, int xDst, int yDst, int cxDst, int cyDst, + HDC hdcSrc, int xSrc, int ySrc, int cxSrc, int cySrc, + COLORREF TransColor) { - BOOL ret = FALSE; - HDC hdcWork; - HBITMAP bmpWork; - HGDIOBJ oldWork; - HDC hdcMask = NULL; - HBITMAP bmpMask = NULL; - HBITMAP oldMask = NULL; - COLORREF oldBackground; - COLORREF oldForeground; - int oldStretchMode; - - if(cxDst < 0 || cyDst < 0 || cxSrc < 0 || cySrc < 0) { - DPRINT("Can not mirror\n"); - return FALSE; - } - - oldBackground = SetBkColor(hdcDst, RGB(255,255,255)); - oldForeground = SetTextColor(hdcDst, RGB(0,0,0)); - - /* Stretch bitmap */ - oldStretchMode = GetStretchBltMode(hdcSrc); - if(oldStretchMode == BLACKONWHITE || oldStretchMode == WHITEONBLACK) - SetStretchBltMode(hdcSrc, COLORONCOLOR); - hdcWork = CreateCompatibleDC(hdcDst); - bmpWork = CreateCompatibleBitmap(hdcDst, cxDst, cyDst); - oldWork = SelectObject(hdcWork, bmpWork); - if(!StretchBlt(hdcWork, 0, 0, cxDst, cyDst, hdcSrc, xSrc, ySrc, cxSrc, cySrc, SRCCOPY)) { - DPRINT("Failed to stretch\n"); - goto error; - } - SetBkColor(hdcWork, TransColor); - - /* Create mask */ - hdcMask = CreateCompatibleDC(hdcDst); - bmpMask = CreateCompatibleBitmap(hdcMask, cxDst, cyDst); - oldMask = SelectObject(hdcMask, bmpMask); - if(!BitBlt(hdcMask, 0, 0, cxDst, cyDst, hdcWork, 0, 0, SRCCOPY)) { - DPRINT("Failed to create mask\n"); - goto error; - } - - /* Replace transparent color with black */ - SetBkColor(hdcWork, RGB(0,0,0)); - SetTextColor(hdcWork, RGB(255,255,255)); - if(!BitBlt(hdcWork, 0, 0, cxDst, cyDst, hdcMask, 0, 0, SRCAND)) { - DPRINT("Failed to mask out background\n"); - goto error; - } - - /* Replace non-transparent area on destination with black */ - if(!BitBlt(hdcDst, xDst, yDst, cxDst, cyDst, hdcMask, 0, 0, SRCAND)) { - DPRINT("Failed to clear destination area\n"); - goto error; - } - - /* Draw the image */ - if(!BitBlt(hdcDst, xDst, yDst, cxDst, cyDst, hdcWork, 0, 0, SRCPAINT)) { - DPRINT("Failed to paint image\n"); - goto error; - } - - ret = TRUE; -error: - SetStretchBltMode(hdcSrc, oldStretchMode); - SetBkColor(hdcDst, oldBackground); - SetTextColor(hdcDst, oldForeground); - if(hdcWork) { - SelectObject(hdcWork, oldWork); - DeleteDC(hdcWork); - } - if(bmpWork) DeleteObject(bmpWork); - if(hdcMask) { - SelectObject(hdcMask, oldMask); - DeleteDC(hdcMask); - } - if(bmpMask) DeleteObject(bmpMask); - return ret; + return (WINBOOL)NtGdiTransparentBlt(hdcDst, xDst, yDst, cxDst, cyDst, hdcSrc, + xSrc, ySrc, cxSrc, cySrc, TransColor); } /* diff --git a/reactos/subsys/win32k/ntuser/msgqueue.c b/reactos/subsys/win32k/ntuser/msgqueue.c index bc1c335253b..7e8acfd9f40 100644 --- a/reactos/subsys/win32k/ntuser/msgqueue.c +++ b/reactos/subsys/win32k/ntuser/msgqueue.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: msgqueue.c,v 1.78 2004/03/28 16:21:58 weiden Exp $ +/* $Id: msgqueue.c,v 1.79 2004/03/28 21:46:26 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -842,7 +842,7 @@ MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue) IntLockMessageQueue(MessageQueue); if (IsListEmpty(&MessageQueue->SentMessagesListHead)) { - ExReleaseFastMutex(&MessageQueue->Lock); + IntUnLockMessageQueue(MessageQueue); return(FALSE); } Entry = RemoveHeadList(&MessageQueue->SentMessagesListHead); diff --git a/reactos/subsys/win32k/ntuser/window.c b/reactos/subsys/win32k/ntuser/window.c index 6eb1d317579..6592b00d3cf 100644 --- a/reactos/subsys/win32k/ntuser/window.c +++ b/reactos/subsys/win32k/ntuser/window.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: window.c,v 1.201 2004/03/23 21:47:37 weiden Exp $ +/* $Id: window.c,v 1.202 2004/03/28 21:46:26 weiden Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -3410,7 +3410,6 @@ IntGetWindowRgn(HWND hWnd, HRGN hRgn) if(!hRgn) { IntReleaseWindowObject(WindowObject); - SetLastWin32Error(ERROR_INVALID_PARAMETER); return ERROR; } @@ -3453,7 +3452,6 @@ IntGetWindowRgnBox(HWND hWnd, RECT *Rect) if(!Rect) { IntReleaseWindowObject(WindowObject); - SetLastWin32Error(ERROR_INVALID_PARAMETER); return ERROR; } diff --git a/reactos/subsys/win32k/objects/bitmaps.c b/reactos/subsys/win32k/objects/bitmaps.c index 9de50b601c8..77a8a77ac63 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.64 2004/03/22 20:46:33 royce Exp $ */ +/* $Id: bitmaps.c,v 1.65 2004/03/28 21:46:26 weiden Exp $ */ #undef WIN32_LEAN_AND_MEAN #include #include @@ -263,6 +263,123 @@ NtGdiBitBlt( return Status; } +BOOL STDCALL +NtGdiTransparentBlt( + HDC hdcDst, + INT xDst, + INT yDst, + INT cxDst, + INT cyDst, + HDC hdcSrc, + INT xSrc, + INT ySrc, + INT cxSrc, + INT cySrc, + COLORREF TransColor) +{ + PDC DCDest, DCSrc; + RECT rcDest, rcSrc; + PSURFOBJ SurfDest, SurfSrc; + PSURFGDI SurfGDIDest, SurfGDISrc; + PXLATEOBJ XlateObj; + HPALETTE SourcePalette, DestPalette; + PPALGDI PalDestGDI, PalSourceGDI; + USHORT PalDestMode, PalSrcMode; + + if(!(DCDest = DC_LockDc(hdcDst))) + { + DPRINT1("Invalid destination dc handle (0x%08x) passed to NtGdiTransparentBlt\n", hdcDst); + SetLastWin32Error(ERROR_INVALID_HANDLE); + return FALSE; + } + + if((hdcDst != hdcSrc) && !(DCSrc = DC_LockDc(hdcSrc))) + { + DC_UnlockDc(hdcDst); + DPRINT1("Invalid source dc handle (0x%08x) passed to NtGdiTransparentBlt\n", hdcSrc); + SetLastWin32Error(ERROR_INVALID_HANDLE); + return FALSE; + } + if(hdcDst == hdcSrc) + { + DCSrc = DCDest; + } + + if(DCDest->w.hPalette) + DestPalette = DCDest->w.hPalette; + else + DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE); + + if(DCSrc->w.hPalette) + SourcePalette = DCSrc->w.hPalette; + else + SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE); + + if(!(PalSourceGDI = PALETTE_LockPalette(SourcePalette))) + { + DC_UnlockDc(hdcSrc); + DC_UnlockDc(hdcDst); + SetLastWin32Error(ERROR_INVALID_HANDLE); + return FALSE; + } + if((DestPalette != SourcePalette) && !(PalDestGDI = PALETTE_LockPalette(DestPalette))) + { + PALETTE_UnlockPalette(SourcePalette); + DC_UnlockDc(hdcSrc); + DC_UnlockDc(hdcDst); + SetLastWin32Error(ERROR_INVALID_HANDLE); + return FALSE; + } + if(DestPalette != SourcePalette) + { + PalDestMode = PalDestGDI->Mode; + PalSrcMode = PalSourceGDI->Mode; + PALETTE_UnlockPalette(DestPalette); + } + else + { + PalDestMode = PalSrcMode = PalSourceGDI->Mode; + } + PALETTE_UnlockPalette(SourcePalette); + + XlateObj = (PXLATEOBJ)IntEngCreateXlate(PalDestMode, PalSrcMode, DestPalette, SourcePalette); + + SurfDest = (PSURFOBJ)AccessUserObject((ULONG)DCDest->Surface); + ASSERT(SurfDest); + SurfGDIDest = (PSURFGDI)AccessInternalObjectFromUserObject(SurfDest); + ASSERT(SurfGDIDest); + SurfSrc = (PSURFOBJ)AccessUserObject((ULONG)DCSrc->Surface); + ASSERT(SurfSrc); + SurfGDISrc = (PSURFGDI)AccessInternalObjectFromUserObject(SurfSrc); + ASSERT(SurfGDISrc); + + rcDest.left = xDst; + rcDest.top = yDst; + rcDest.right = rcDest.left + cxDst; + rcDest.bottom = rcDest.bottom + cyDst; + rcSrc.left = xSrc; + rcSrc.top = ySrc; + rcSrc.right = rcDest.left + cxSrc; + rcSrc.bottom = rcDest.bottom + cySrc; + + if((cxDst != cxSrc) || (cyDst != cySrc)) + { + /* FIXME - Create a temporary bitmap and stretchblt it */ + } + + + DC_UnlockDc(hdcSrc); + if(hdcDst != hdcSrc) + { + DC_UnlockDc(hdcDst); + } + if(XlateObj) + { + EngDeleteXlate(XlateObj); + } + return TRUE; +} + HBITMAP STDCALL NtGdiCreateBitmap( INT Width,