mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
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
This commit is contained in:
parent
ba96bd3821
commit
7d726b9519
2 changed files with 58 additions and 47 deletions
24
reactos/include/rosrtl/gdimacro.h
Normal file
24
reactos/include/rosrtl/gdimacro.h
Normal file
|
@ -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 */
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* 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
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -33,6 +33,7 @@
|
||||||
#include <include/surface.h>
|
#include <include/surface.h>
|
||||||
#include <include/palette.h>
|
#include <include/palette.h>
|
||||||
#include <include/tags.h>
|
#include <include/tags.h>
|
||||||
|
#include <rosrtl/gdimacro.h>
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <win32k/debug1.h>
|
#include <win32k/debug1.h>
|
||||||
|
@ -467,66 +468,52 @@ BOOL STDCALL NtGdiGetBitmapDimensionEx(HBITMAP hBitmap,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
COLORREF STDCALL NtGdiGetPixel(HDC hDC, INT XPos, INT YPos)
|
COLORREF
|
||||||
|
STDCALL
|
||||||
|
NtGdiGetPixel(HDC hDC, INT XPos, INT YPos)
|
||||||
{
|
{
|
||||||
PDC dc = NULL;
|
PDC dc = NULL;
|
||||||
COLORREF Result = (COLORREF) 0;
|
COLORREF clrSource, Result = (COLORREF)CLR_INVALID; // default to failure
|
||||||
PSURFGDI Surface;
|
PSURFGDI Surface;
|
||||||
PSURFOBJ SurfaceObject;
|
PSURFOBJ SurfaceObject;
|
||||||
HPALETTE Pal;
|
HPALETTE Pal;
|
||||||
PPALGDI PalGDI;
|
PPALGDI PalGDI;
|
||||||
USHORT PalMode;
|
USHORT PalMode;
|
||||||
PXLATEOBJ XlateObj = NULL;
|
PXLATEOBJ XlateObj;
|
||||||
|
|
||||||
dc = DC_LockDc (hDC);
|
dc = DC_LockDc (hDC);
|
||||||
if (dc == NULL)
|
if (dc != NULL)
|
||||||
{
|
{
|
||||||
return (COLORREF)CLR_INVALID;
|
if ( IN_RECT(dc->CombinedClip->rclBounds,XPos,YPos) )
|
||||||
}
|
{
|
||||||
if (XPos < dc->CombinedClip->rclBounds.left ||
|
SurfaceObject = (PSURFOBJ)AccessUserObject((ULONG)dc->Surface);
|
||||||
XPos > dc->CombinedClip->rclBounds.right ||
|
ASSERT(SurfaceObject);
|
||||||
YPos < dc->CombinedClip->rclBounds.top ||
|
Surface = (PSURFGDI)AccessInternalObjectFromUserObject(SurfaceObject);
|
||||||
YPos > dc->CombinedClip->rclBounds.bottom)
|
if ( Surface && Surface->DIB_GetPixel )
|
||||||
{
|
{
|
||||||
DC_UnlockDc(hDC);
|
clrSource = Surface->DIB_GetPixel(SurfaceObject, XPos, YPos);
|
||||||
return (COLORREF)CLR_INVALID;
|
if (dc->w.hPalette != 0)
|
||||||
}
|
Pal = dc->w.hPalette;
|
||||||
SurfaceObject = (PSURFOBJ)AccessUserObject((ULONG)dc->Surface);
|
else
|
||||||
Surface = (PSURFGDI)AccessInternalObjectFromUserObject(SurfaceObject);
|
Pal = NtGdiGetStockObject(DEFAULT_PALETTE);
|
||||||
if (Surface == NULL || Surface->DIB_GetPixel == NULL)
|
PalGDI = PALETTE_LockPalette(Pal);
|
||||||
{
|
if ( PalGDI )
|
||||||
DC_UnlockDc(hDC);
|
{
|
||||||
return (COLORREF)CLR_INVALID;
|
PalMode = PalGDI->Mode;
|
||||||
}
|
PALETTE_UnlockPalette(Pal);
|
||||||
Result = Surface->DIB_GetPixel(SurfaceObject, XPos, YPos);
|
|
||||||
|
|
||||||
if (dc->w.hPalette != 0)
|
XlateObj = (PXLATEOBJ)IntEngCreateXlate ( PAL_RGB, PalMode, NULL, Pal );
|
||||||
{
|
if ( XlateObj )
|
||||||
Pal = dc->w.hPalette;
|
{
|
||||||
}
|
Result = XLATEOBJ_iXlate(XlateObj, clrSource);
|
||||||
else
|
EngDeleteXlate(XlateObj);
|
||||||
{
|
}
|
||||||
Pal = NtGdiGetStockObject(DEFAULT_PALETTE);
|
}
|
||||||
}
|
}
|
||||||
PalGDI = PALETTE_LockPalette(Pal);
|
}
|
||||||
if (NULL == PalGDI)
|
|
||||||
{
|
|
||||||
DC_UnlockDc(hDC);
|
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;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue