From 7d726b95193aa95204ae1beef9cd1facf476198e Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Tue, 16 Mar 2004 02:15:06 +0000 Subject: [PATCH] NtGdiGetPixel cleanup - fixed small bug with rect boundary checking, and cleaned up code to only unlock DC in one place. svn path=/trunk/; revision=8760 --- reactos/include/rosrtl/gdimacro.h | 24 ++++++++ reactos/subsys/win32k/objects/bitmaps.c | 81 +++++++++++-------------- 2 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 reactos/include/rosrtl/gdimacro.h diff --git a/reactos/include/rosrtl/gdimacro.h b/reactos/include/rosrtl/gdimacro.h new file mode 100644 index 00000000000..36093a9f735 --- /dev/null +++ b/reactos/include/rosrtl/gdimacro.h @@ -0,0 +1,24 @@ +/* + * gdimacro.h + */ + +#ifndef ROSRTL_GDIMACRO_H +#define ROSRTL_GDIMACRO_H + +#define IN_RECT(r,x,y) \ +( \ + (x) >= (r).left && \ + (y) >= (r).top && \ + (x) < (r).right && \ + (y) < (r).bottom \ +) + +#define RECT_OVERLAP(a,b) \ +( \ + (a).left < (b).right && \ + (b).left < (a).right && \ + (a).top < (b).bottom && \ + (b).top < (a).bottom \ +) + +#endif /* ROSRTL_GDIMACRO_H */ diff --git a/reactos/subsys/win32k/objects/bitmaps.c b/reactos/subsys/win32k/objects/bitmaps.c index bcd662db230..de38d9e09d3 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.62 2004/03/15 22:06:55 gvg Exp $ */ +/* $Id: bitmaps.c,v 1.63 2004/03/16 02:15:06 royce Exp $ */ #undef WIN32_LEAN_AND_MEAN #include #include @@ -33,6 +33,7 @@ #include #include #include +#include #define NDEBUG #include @@ -467,66 +468,52 @@ BOOL STDCALL NtGdiGetBitmapDimensionEx(HBITMAP hBitmap, return TRUE; } -COLORREF STDCALL NtGdiGetPixel(HDC hDC, INT XPos, INT YPos) +COLORREF +STDCALL +NtGdiGetPixel(HDC hDC, INT XPos, INT YPos) { PDC dc = NULL; - COLORREF Result = (COLORREF) 0; + COLORREF clrSource, Result = (COLORREF)CLR_INVALID; // default to failure PSURFGDI Surface; PSURFOBJ SurfaceObject; HPALETTE Pal; PPALGDI PalGDI; USHORT PalMode; - PXLATEOBJ XlateObj = NULL; + PXLATEOBJ XlateObj; dc = DC_LockDc (hDC); - if (dc == NULL) + if (dc != NULL) { - return (COLORREF)CLR_INVALID; - } - if (XPos < dc->CombinedClip->rclBounds.left || - XPos > dc->CombinedClip->rclBounds.right || - YPos < dc->CombinedClip->rclBounds.top || - YPos > dc->CombinedClip->rclBounds.bottom) - { - DC_UnlockDc(hDC); - return (COLORREF)CLR_INVALID; - } - SurfaceObject = (PSURFOBJ)AccessUserObject((ULONG)dc->Surface); - Surface = (PSURFGDI)AccessInternalObjectFromUserObject(SurfaceObject); - if (Surface == NULL || Surface->DIB_GetPixel == NULL) - { - DC_UnlockDc(hDC); - return (COLORREF)CLR_INVALID; - } - Result = Surface->DIB_GetPixel(SurfaceObject, XPos, YPos); + if ( IN_RECT(dc->CombinedClip->rclBounds,XPos,YPos) ) + { + SurfaceObject = (PSURFOBJ)AccessUserObject((ULONG)dc->Surface); + ASSERT(SurfaceObject); + Surface = (PSURFGDI)AccessInternalObjectFromUserObject(SurfaceObject); + if ( Surface && Surface->DIB_GetPixel ) + { + clrSource = Surface->DIB_GetPixel(SurfaceObject, XPos, YPos); + if (dc->w.hPalette != 0) + Pal = dc->w.hPalette; + else + Pal = NtGdiGetStockObject(DEFAULT_PALETTE); + PalGDI = PALETTE_LockPalette(Pal); + if ( PalGDI ) + { + PalMode = PalGDI->Mode; + PALETTE_UnlockPalette(Pal); - if (dc->w.hPalette != 0) - { - Pal = dc->w.hPalette; - } - else - { - Pal = NtGdiGetStockObject(DEFAULT_PALETTE); - } - PalGDI = PALETTE_LockPalette(Pal); - if (NULL == PalGDI) - { + XlateObj = (PXLATEOBJ)IntEngCreateXlate ( PAL_RGB, PalMode, NULL, Pal ); + if ( XlateObj ) + { + Result = XLATEOBJ_iXlate(XlateObj, clrSource); + EngDeleteXlate(XlateObj); + } + } + } + } DC_UnlockDc(hDC); - return (COLORREF)CLR_INVALID; } - PalMode = PalGDI->Mode; - PALETTE_UnlockPalette(Pal); - XlateObj = (PXLATEOBJ) IntEngCreateXlate(PAL_RGB, PalMode, NULL, Pal); - if (NULL == XlateObj) - { - DC_UnlockDc(hDC); - return (COLORREF)CLR_INVALID; - } - Result = XLATEOBJ_iXlate(XlateObj, Result); - EngDeleteXlate(XlateObj); - - DC_UnlockDc(hDC); return Result; }