Commit in reactos/subsys/win32k/objects on MAIN
bitmaps.c+1122-10441.63 -> 1.64
Reformatting plus change to NtGdiGetPixel to handle device DCs in addition to DIB DCs. This fixes bug #264.

reactos/subsys/win32k/objects
bitmaps.c 1.63 -> 1.64
diff -u -r1.63 -r1.64
--- bitmaps.c	16 Mar 2004 02:15:06 -0000	1.63
+++ bitmaps.c	22 Mar 2004 20:46:33 -0000	1.64
@@ -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.63 2004/03/16 02:15:06 royce Exp $ */
+/* $Id: bitmaps.c,v 1.64 2004/03/22 20:46:33 royce Exp $ */
 #undef WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <stdlib.h>
@@ -38,496 +38,558 @@
 #define NDEBUG
 #include <win32k/debug1.h>
 
-BOOL STDCALL NtGdiBitBlt(HDC  hDCDest,
-                 INT  XDest,
-                 INT  YDest,
-                 INT  Width,
-                 INT  Height,
-                 HDC  hDCSrc,
-                 INT  XSrc,
-                 INT  YSrc,
-                 DWORD  ROP)
-{
-  PDC DCDest = NULL;
-  PDC DCSrc  = NULL;
-  PSURFOBJ SurfDest, SurfSrc;
-  PSURFGDI SurfGDIDest, SurfGDISrc;
-  RECTL DestRect;
-  POINTL SourcePoint;
-  BOOL Status;
-  PPALGDI PalDestGDI, PalSourceGDI;
-  PXLATEOBJ XlateObj = NULL;
-  HPALETTE SourcePalette, DestPalette;
-  ULONG SourceMode, DestMode;
-  PBRUSHOBJ BrushObj;
-  BOOL UsesSource = ((ROP & 0xCC0000) >> 2) != (ROP & 0x330000);
-  BOOL UsesPattern = TRUE;//((ROP & 0xF00000) >> 4) != (ROP & 0x0F0000);  
-  HPALETTE Mono = NULL;
-
-  DCDest = DC_LockDc(hDCDest);
-  if (NULL == DCDest)
-    {
-      DPRINT1("Invalid destination dc handle (0x%08x) passed to NtGdiBitBlt\n", hDCDest);
-      SetLastWin32Error(ERROR_INVALID_HANDLE);
-      return FALSE;
-    }
-
-  if (UsesSource)
-    {
-      if (hDCSrc != hDCDest)
-        {
-          DCSrc = DC_LockDc(hDCSrc);
-          if (NULL == DCSrc)
-            {
-              DC_UnlockDc(hDCDest);
-              DPRINT1("Invalid source dc handle (0x%08x) passed to NtGdiBitBlt\n", hDCSrc);
-              SetLastWin32Error(ERROR_INVALID_HANDLE);
-              return FALSE;
-            }
-        }
-      else
-        {
-           DCSrc = DCDest;
-        }
-    }
-  else
-    {
-      DCSrc = NULL;
-    }
-
-  /* Offset the destination and source by the origin of their DCs. */
-  XDest += DCDest->w.DCOrgX;
-  YDest += DCDest->w.DCOrgY;
-  if (UsesSource)
-    {
-      XSrc += DCSrc->w.DCOrgX;
-      YSrc += DCSrc->w.DCOrgY;
-    }
-
-  DestRect.left   = XDest;
-  DestRect.top    = YDest;
-  DestRect.right  = XDest+Width;
-  DestRect.bottom = YDest+Height;
-
-  SourcePoint.x = XSrc;
-  SourcePoint.y = YSrc;
-
-  /* Determine surfaces to be used in the bitblt */
-  SurfDest = (PSURFOBJ)AccessUserObject((ULONG)DCDest->Surface);
-  SurfGDIDest = (PSURFGDI)AccessInternalObjectFromUserObject(SurfDest);
-  if (UsesSource)
-    {
-      SurfSrc  = (PSURFOBJ)AccessUserObject((ULONG)DCSrc->Surface);
-      SurfGDISrc  = (PSURFGDI)AccessInternalObjectFromUserObject(SurfSrc);
-    }
-  else
-    {
-      SurfSrc  = NULL;
-      SurfGDISrc  = NULL;
-    }
-
-  if (UsesPattern)
-    {
-      BrushObj = BRUSHOBJ_LockBrush(DCDest->w.hBrush);
-      if (NULL == BrushObj)
-        {
-          if (UsesSource && hDCSrc != hDCDest)
-            {
-              DC_UnlockDc(hDCSrc);
-            }
-          DC_UnlockDc(hDCDest);
-          SetLastWin32Error(ERROR_INVALID_HANDLE);
-          return FALSE;
-        }
-    }
-  else
-    {
-      BrushObj = NULL;
-    }
-
-  if (DCDest->w.hPalette != 0)
-    {
-      DestPalette = DCDest->w.hPalette;
-    }
-  else
-    {
-      DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE);
-    }
-
-  if (UsesSource && DCSrc->w.hPalette != 0)
-    {
-      SourcePalette = DCSrc->w.hPalette;
-    }
-  else
-    {
-      SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE);
-    }
-
-  PalSourceGDI = PALETTE_LockPalette(SourcePalette);
-  if (NULL == PalSourceGDI)
-    {
-      if (UsesSource && hDCSrc != hDCDest)
-        {
-          DC_UnlockDc(hDCSrc);
-        }
-      DC_UnlockDc(hDCDest);
-      SetLastWin32Error(ERROR_INVALID_HANDLE);
-      return FALSE;
-    }
-  SourceMode = PalSourceGDI->Mode;
-  PALETTE_UnlockPalette(SourcePalette);
-
-  if (DestPalette == SourcePalette)
-    {
-      DestMode = SourceMode;
-    }
-  else
-    {
-      PalDestGDI = PALETTE_LockPalette(DestPalette);
-      if (NULL == PalDestGDI)
-        {
-          if (UsesSource && hDCSrc != hDCDest)
-            {
-              DC_UnlockDc(hDCSrc);
-            }
-          DC_UnlockDc(hDCDest);
-          SetLastWin32Error(ERROR_INVALID_HANDLE);
-          return FALSE;
-        }
-      DestMode = PalDestGDI->Mode;
-      PALETTE_UnlockPalette(DestPalette);
-    }
-
-  /* KB41464 details how to convert between mono and color */
-  if (DCDest->w.bitsPerPixel == 1)
-    {
-      XlateObj = (PXLATEOBJ)IntEngCreateMonoXlate(SourceMode, DestPalette,
-         SourcePalette, DCSrc->w.backgroundColor);
-    }
-  else if (UsesSource && 1 == DCSrc->w.bitsPerPixel)
-    {
-      ULONG Colors[2];
-
-      Colors[0] = DCSrc->w.textColor;
-      Colors[1] = DCSrc->w.backgroundColor;
-      Mono = EngCreatePalette(PAL_INDEXED, 2, Colors, 0, 0, 0);
-      if (NULL != Mono)
-        {
-          XlateObj = (PXLATEOBJ)IntEngCreateXlate(DestMode, PAL_INDEXED, DestPalette, Mono);
-        }
-      else
-        {
-          XlateObj = NULL;
-        }
-    }
-  else
-    {
-      XlateObj = (PXLATEOBJ)IntEngCreateXlate(DestMode, SourceMode, DestPalette, SourcePalette);
-    }
-  if (NULL == XlateObj)
-    {
-      if (NULL != Mono)
-        {
-          EngDeletePalette(Mono);
-        }
-      if (UsesSource && hDCSrc != hDCDest)
-        {
-          DC_UnlockDc(hDCSrc);
-        }
-      DC_UnlockDc(hDCDest);
-      SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
-      return FALSE;
-    }
-
-  /* Perform the bitblt operation */
-  Status = IntEngBitBlt(SurfDest, SurfSrc, NULL, DCDest->CombinedClip, XlateObj,
-                        &DestRect, &SourcePoint, NULL, BrushObj, NULL, ROP);
-
-  EngDeleteXlate(XlateObj);
-  if (NULL != Mono)
-    {
-      EngDeletePalette(Mono);
-    }
-  if (UsesPattern)
-    {
-      BRUSHOBJ_UnlockBrush(DCDest->w.hBrush);
-    }
-  if (UsesSource && hDCSrc != hDCDest)
-    {
-      DC_UnlockDc(hDCSrc);
-    }
-  DC_UnlockDc(hDCDest);
-
-  return Status;
-}
-
-HBITMAP STDCALL NtGdiCreateBitmap(INT  Width,
-                          INT  Height,
-                          UINT  Planes,
-                          UINT  BitsPerPel,
-                          CONST VOID *Bits)
-{
-  PBITMAPOBJ  bmp;
-  HBITMAP  hBitmap;
-
-  Planes = (BYTE) Planes;
-  BitsPerPel = (BYTE) BitsPerPel;
-
-  /* Check parameters */
-  if (!Height || !Width)
-  {
-    Width = 1;
-    Height = 1;
-  }
-  if (Planes != 1)
-  {
-    DPRINT("NtGdiCreateBitmap - UNIMPLEMENTED\n");
-    return  0;
-  }
-  if (Height < 0)
-  {
-    Height = -Height;
-  }
-  if (Width < 0)
-  {
-    Width = -Width;
-  }
-
-  /* Create the BITMAPOBJ */
-  hBitmap = BITMAPOBJ_AllocBitmap ();
-  if (!hBitmap)
-  {
-	DPRINT("NtGdiCreateBitmap: BITMAPOBJ_AllocBitmap returned 0\n");
-    return 0;
-  }
-
-  bmp = BITMAPOBJ_LockBitmap( hBitmap );
-
-  DPRINT("NtGdiCreateBitmap:%dx%d, %d (%d BPP) colors returning %08x\n", Width, Height,
-         1 << (Planes * BitsPerPel), BitsPerPel, bmp);
-
-  bmp->dimension.cx = 0;
-  bmp->dimension.cy = 0;
-  bmp->bitmap.bmType = 0;
-  bmp->bitmap.bmWidth = Width;
-  bmp->bitmap.bmHeight = Height;
-  bmp->bitmap.bmPlanes = Planes;
-  bmp->bitmap.bmBitsPixel = BitsPerPel;
-  bmp->bitmap.bmWidthBytes = BITMAPOBJ_GetWidthBytes (Width, BitsPerPel);
-  bmp->bitmap.bmBits = NULL;
-  bmp->DDBitmap = NULL;
-  bmp->dib = NULL;
-
-  // Allocate memory for bitmap bits
-  bmp->bitmap.bmBits = ExAllocatePoolWithTag(PagedPool, bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight, TAG_BITMAP);
-
-  BITMAPOBJ_UnlockBitmap( hBitmap );
-  
-  if (Bits) /* Set bitmap bits */
-  {   
-    NtGdiSetBitmapBits(hBitmap, Height * bmp->bitmap.bmWidthBytes, Bits);
-  }
-  else
-  {
-    // Initialize the bitmap (fixes bug 244?)
-    RtlZeroMemory(bmp->bitmap.bmBits, Height * bmp->bitmap.bmWidthBytes);
-  }
-
-  return  hBitmap;
-}
-
-BOOL FASTCALL Bitmap_InternalDelete( PBITMAPOBJ pBmp )
-{
-  ASSERT( pBmp );
-
-  if (NULL != pBmp->bitmap.bmBits)
-    {
-      if (NULL != pBmp->dib)
-	{
-	  if (NULL == pBmp->dib->dshSection)
-	    {
-	      EngFreeUserMem(pBmp->bitmap.bmBits);
-	    }
-	  else
-	    {
-	      /* This is a file-mapped section */
-	      UNIMPLEMENTED;
-	    }
+BOOL STDCALL
+NtGdiBitBlt(
+	HDC  hDCDest,
+	INT  XDest,
+	INT  YDest,
+	INT  Width,
+	INT  Height,
+	HDC  hDCSrc,
+	INT  XSrc,
+	INT  YSrc,
+	DWORD  ROP)
+{
+	PDC DCDest = NULL;
+	PDC DCSrc  = NULL;
+	PSURFOBJ SurfDest, SurfSrc;
+	PSURFGDI SurfGDIDest, SurfGDISrc;
+	RECTL DestRect;
+	POINTL SourcePoint;
+	BOOL Status;
+	PPALGDI PalDestGDI, PalSourceGDI;
+	PXLATEOBJ XlateObj = NULL;
+	HPALETTE SourcePalette, DestPalette;
+	ULONG SourceMode, DestMode;
+	PBRUSHOBJ BrushObj;
+	BOOL UsesSource = ((ROP & 0xCC0000) >> 2) != (ROP & 0x330000);
+	BOOL UsesPattern = TRUE;//((ROP & 0xF00000) >> 4) != (ROP & 0x0F0000);
+	HPALETTE Mono = NULL;
+
+	DCDest = DC_LockDc(hDCDest);
+	if (NULL == DCDest)
+	{
+		DPRINT1("Invalid destination dc handle (0x%08x) passed to NtGdiBitBlt\n", hDCDest);
+		SetLastWin32Error(ERROR_INVALID_HANDLE);
+		return FALSE;
+	}
+
+	if (UsesSource)
+	{
+		if (hDCSrc != hDCDest)
+		{
+			DCSrc = DC_LockDc(hDCSrc);
+			if (NULL == DCSrc)
+			{
+				DC_UnlockDc(hDCDest);
+				DPRINT1("Invalid source dc handle (0x%08x) passed to NtGdiBitBlt\n", hDCSrc);
+				SetLastWin32Error(ERROR_INVALID_HANDLE);
+				return FALSE;
+			}
+		}
+		else
+		{
+			DCSrc = DCDest;
+		}
+	}
+	else
+	{
+		DCSrc = NULL;
+	}
+
+	/* Offset the destination and source by the origin of their DCs. */
+	XDest += DCDest->w.DCOrgX;
+	YDest += DCDest->w.DCOrgY;
+	if (UsesSource)
+	{
+		XSrc += DCSrc->w.DCOrgX;
+		YSrc += DCSrc->w.DCOrgY;
+	}
+
+	DestRect.left   = XDest;
+	DestRect.top    = YDest;
+	DestRect.right  = XDest+Width;
+	DestRect.bottom = YDest+Height;
+
+	SourcePoint.x = XSrc;
+	SourcePoint.y = YSrc;
+
+	/* Determine surfaces to be used in the bitblt */
+	SurfDest = (PSURFOBJ)AccessUserObject((ULONG)DCDest->Surface);
+	SurfGDIDest = (PSURFGDI)AccessInternalObjectFromUserObject(SurfDest);
+	if (UsesSource)
+	{
+		SurfSrc  = (PSURFOBJ)AccessUserObject((ULONG)DCSrc->Surface);
+		SurfGDISrc  = (PSURFGDI)AccessInternalObjectFromUserObject(SurfSrc);
+	}
+	else
+	{
+		SurfSrc  = NULL;
+		SurfGDISrc  = NULL;
+	}
+
+	if (UsesPattern)
+	{
+		BrushObj = BRUSHOBJ_LockBrush(DCDest->w.hBrush);
+		if (NULL == BrushObj)
+		{
+			if (UsesSource && hDCSrc != hDCDest)
+			{
+				DC_UnlockDc(hDCSrc);
+			}
+			DC_UnlockDc(hDCDest);
+			SetLastWin32Error(ERROR_INVALID_HANDLE);
+			return FALSE;
+		}
+	}
+	else
+	{
+		BrushObj = NULL;
+	}
+
+	if (DCDest->w.hPalette != 0)
+	{
+		DestPalette = DCDest->w.hPalette;
+	}
+	else
+	{
+		DestPalette = NtGdiGetStockObject(DEFAULT_PALETTE);
+	}
+
+	if (UsesSource && DCSrc->w.hPalette != 0)
+	{
+		SourcePalette = DCSrc->w.hPalette;
+	}
+	else
+	{
+		SourcePalette = NtGdiGetStockObject(DEFAULT_PALETTE);
+	}
+
+	PalSourceGDI = PALETTE_LockPalette(SourcePalette);
+	if (NULL == PalSourceGDI)
+	{
+		if (UsesSource && hDCSrc != hDCDest)
+		{
+			DC_UnlockDc(hDCSrc);
+		}
+		DC_UnlockDc(hDCDest);
+		SetLastWin32Error(ERROR_INVALID_HANDLE);
+		return FALSE;
+	}
+	SourceMode = PalSourceGDI->Mode;
+	PALETTE_UnlockPalette(SourcePalette);
+
+	if (DestPalette == SourcePalette)
+	{
+		DestMode = SourceMode;
+	}
+	else
+	{
+		PalDestGDI = PALETTE_LockPalette(DestPalette);
+		if (NULL == PalDestGDI)
+		{
+			if (UsesSource && hDCSrc != hDCDest)
+			{
+				DC_UnlockDc(hDCSrc);
+			}
+			DC_UnlockDc(hDCDest);
+			SetLastWin32Error(ERROR_INVALID_HANDLE);
+			return FALSE;
+		}
+		DestMode = PalDestGDI->Mode;
+		PALETTE_UnlockPalette(DestPalette);
+	}
+
+	/* KB41464 details how to convert between mono and color */
+	if (DCDest->w.bitsPerPixel == 1)
+	{
+		XlateObj = (PXLATEOBJ)IntEngCreateMonoXlate(SourceMode, DestPalette,
+			SourcePalette, DCSrc->w.backgroundColor);
+	}
+	else if (UsesSource && 1 == DCSrc->w.bitsPerPixel)
+	{
+		ULONG Colors[2];
+
+		Colors[0] = DCSrc->w.textColor;
+		Colors[1] = DCSrc->w.backgroundColor;
+		Mono = EngCreatePalette(PAL_INDEXED, 2, Colors, 0, 0, 0);
+		if (NULL != Mono)
+		{
+			XlateObj = (PXLATEOBJ)IntEngCreateXlate(DestMode, PAL_INDEXED, DestPalette, Mono);
+		}
+		else
+		{
+			XlateObj = NULL;
+		}
+	}
+	else
+	{
+		XlateObj = (PXLATEOBJ)IntEngCreateXlate(DestMode, SourceMode, DestPalette, SourcePalette);
+	}
+	if (NULL == XlateObj)
+	{
+		if (NULL != Mono)
+		{
+			EngDeletePalette(Mono);
+		}
+		if (UsesSource && hDCSrc != hDCDest)
+		{
+			DC_UnlockDc(hDCSrc);
+		}
+		DC_UnlockDc(hDCDest);
+		SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES);
+		return FALSE;
+	}
+
+	/* Perform the bitblt operation */
+	Status = IntEngBitBlt(SurfDest, SurfSrc, NULL, DCDest->CombinedClip, XlateObj,
+		&DestRect, &SourcePoint, NULL, BrushObj, NULL, ROP);
+
+	EngDeleteXlate(XlateObj);
+	if (NULL != Mono)
+	{
+		EngDeletePalette(Mono);
+	}
+	if (UsesPattern)
+	{
+		BRUSHOBJ_UnlockBrush(DCDest->w.hBrush);
+	}
+	if (UsesSource && hDCSrc != hDCDest)
+	{
+		DC_UnlockDc(hDCSrc);
+	}
+	DC_UnlockDc(hDCDest);
+
+	return Status;
+}
+
+HBITMAP STDCALL
+NtGdiCreateBitmap(
+	INT  Width,
+	INT  Height,
+	UINT  Planes,
+	UINT  BitsPerPel,
+	CONST VOID *Bits)
+{
+	PBITMAPOBJ  bmp;
+	HBITMAP  hBitmap;
+
+	Planes = (BYTE) Planes;
+	BitsPerPel = (BYTE) BitsPerPel;
+
+	/* Check parameters */
+	if (!Height || !Width)
+	{
+		Width = 1;
+		Height = 1;
+	}
+	if (Planes != 1)
+	{
+		DPRINT("NtGdiCreateBitmap - UNIMPLEMENTED\n");
+		return  0;
+	}
+	if (Height < 0)
+	{
+		Height = -Height;
 	}
-      else
+	if (Width < 0)
 	{
-	  ExFreePool(pBmp->bitmap.bmBits);
+		Width = -Width;
 	}
-    }
 
-  return TRUE;
+	/* Create the BITMAPOBJ */
+	hBitmap = BITMAPOBJ_AllocBitmap ();
+	if (!hBitmap)
+	{
+		DPRINT("NtGdiCreateBitmap: BITMAPOBJ_AllocBitmap returned 0\n");
+		return 0;
+	}
+
+	bmp = BITMAPOBJ_LockBitmap( hBitmap );
+
+	DPRINT("NtGdiCreateBitmap:%dx%d, %d (%d BPP) colors returning %08x\n", Width, Height,
+		1 << (Planes * BitsPerPel), BitsPerPel, bmp);
+
+	bmp->dimension.cx = 0;
+	bmp->dimension.cy = 0;
+	bmp->bitmap.bmType = 0;
+	bmp->bitmap.bmWidth = Width;
+	bmp->bitmap.bmHeight = Height;
+	bmp->bitmap.bmPlanes = Planes;
+	bmp->bitmap.bmBitsPixel = BitsPerPel;
+	bmp->bitmap.bmWidthBytes = BITMAPOBJ_GetWidthBytes (Width, BitsPerPel);
+	bmp->bitmap.bmBits = NULL;
+	bmp->DDBitmap = NULL;
+	bmp->dib = NULL;
+
+	// Allocate memory for bitmap bits
+	bmp->bitmap.bmBits = ExAllocatePoolWithTag(PagedPool, bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight, TAG_BITMAP);
+
+	BITMAPOBJ_UnlockBitmap( hBitmap );
+
+	if (Bits) /* Set bitmap bits */
+	{
+		NtGdiSetBitmapBits(hBitmap, Height * bmp->bitmap.bmWidthBytes, Bits);
+	}
+	else
+	{
+		// Initialize the bitmap (fixes bug 244?)
+		RtlZeroMemory(bmp->bitmap.bmBits, Height * bmp->bitmap.bmWidthBytes);
+	}
+
+	return  hBitmap;
+}
+
+BOOL FASTCALL
+Bitmap_InternalDelete( PBITMAPOBJ pBmp )
+{
+	ASSERT( pBmp );
+
+	if (NULL != pBmp->bitmap.bmBits)
+	{
+		if (NULL != pBmp->dib)
+		{
+			if (NULL == pBmp->dib->dshSection)
+			{
+				EngFreeUserMem(pBmp->bitmap.bmBits);
+			}
+			else
+			{
+				/* This is a file-mapped section */
+				UNIMPLEMENTED;
+			}
+		}
+		else
+		{
+			ExFreePool(pBmp->bitmap.bmBits);
+		}
+	}
+
+	return TRUE;
 }
 
 
 HBITMAP FASTCALL
-IntCreateCompatibleBitmap(PDC Dc,
-                          INT Width,
-                          INT Height)
-{
-  HBITMAP Bmp;
-
-  Bmp = NULL;
-
-  if ((Width >= 0x10000) || (Height >= 0x10000))
-    {
-      DPRINT1("got bad width %d or height %d, please look for reason\n", Width, Height);
-      return NULL;
-    }
-
-  /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
-  if (0 == Width || 0 == Height)
-    {
-      Bmp = NtGdiCreateBitmap (1, 1, 1, 1, NULL);
-    }
-  else
-    {
-      Bmp = NtGdiCreateBitmap(Width, Height, 1, Dc->w.bitsPerPixel, NULL);
-    }
+IntCreateCompatibleBitmap(
+	PDC Dc,
+	INT Width,
+	INT Height)
+{
+	HBITMAP Bmp;
 
-  return Bmp;
+	Bmp = NULL;
+
+	if ((Width >= 0x10000) || (Height >= 0x10000))
+	{
+		DPRINT1("got bad width %d or height %d, please look for reason\n", Width, Height);
+		return NULL;
+	}
+
+	/* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */
+	if (0 == Width || 0 == Height)
+	{
+		Bmp = NtGdiCreateBitmap (1, 1, 1, 1, NULL);
+	}
+	else
+	{
+		Bmp = NtGdiCreateBitmap(Width, Height, 1, Dc->w.bitsPerPixel, NULL);
+	}
+
+	return Bmp;
 }
 
 HBITMAP STDCALL
-NtGdiCreateCompatibleBitmap(HDC hDC,
-                            INT Width,
-                            INT Height)
+NtGdiCreateCompatibleBitmap(
+	HDC hDC,
+	INT Width,
+	INT Height)
 {
-  HBITMAP Bmp;
-  PDC Dc;
+	HBITMAP Bmp;
+	PDC Dc;
 
-  Dc = DC_LockDc(hDC);
+	Dc = DC_LockDc(hDC);
 
-  DPRINT("NtGdiCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC, Width, Height, dc->w.bitsPerPixel);
+	DPRINT("NtGdiCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC, Width, Height, dc->w.bitsPerPixel);
 
-  if (NULL == Dc)
-    {
-      return NULL;
-    }
+	if (NULL == Dc)
+	{
+		SetLastWin32Error(ERROR_INVALID_HANDLE);
+		return NULL;
+	}
 
-  Bmp = IntCreateCompatibleBitmap(Dc, Width, Height);
+	Bmp = IntCreateCompatibleBitmap(Dc, Width, Height);
 
-  DPRINT ("\t\t%04x\n", Bmp);
-  DC_UnlockDc(hDC);
-  return Bmp;
+	DPRINT ("\t\t%04x\n", Bmp);
+	DC_UnlockDc(hDC);
+	return Bmp;
 }
 
-HBITMAP STDCALL NtGdiCreateBitmapIndirect(CONST BITMAP  *BM)
+HBITMAP STDCALL
+NtGdiCreateBitmapIndirect(CONST BITMAP  *BM)
 {
-  return NtGdiCreateBitmap (BM->bmWidth,
-                           BM->bmHeight,
-                           BM->bmPlanes,
-                           BM->bmBitsPixel,
-                           BM->bmBits);
+	return NtGdiCreateBitmap (BM->bmWidth,
+		BM->bmHeight,
+		BM->bmPlanes,
+		BM->bmBitsPixel,
+		BM->bmBits);
 }
 
-HBITMAP STDCALL NtGdiCreateDiscardableBitmap(HDC  hDC,
-                                     INT  Width,
-                                     INT  Height)
+HBITMAP STDCALL
+NtGdiCreateDiscardableBitmap(
+	HDC  hDC,
+	INT  Width,
+	INT  Height)
 {
-  /* FIXME: this probably should do something else */
-  return  NtGdiCreateCompatibleBitmap(hDC, Width, Height);
+	/* FIXME: this probably should do something else */
+	return  NtGdiCreateCompatibleBitmap(hDC, Width, Height);
 }
 
-BOOL STDCALL NtGdiExtFloodFill(HDC  hDC,
-                      INT  XStart,
-                      INT  YStart,
-                      COLORREF  Color,
-                      UINT  FillType)
+BOOL STDCALL
+NtGdiExtFloodFill(
+	HDC  hDC,
+	INT  XStart,
+	INT  YStart,
+	COLORREF  Color,
+	UINT  FillType)
 {
-  UNIMPLEMENTED;
+	UNIMPLEMENTED;
 }
 
-BOOL STDCALL NtGdiFloodFill(HDC  hDC,
-                    INT  XStart,
-                    INT  YStart,
-                    COLORREF  Fill)
+BOOL STDCALL
+NtGdiFloodFill(
+	HDC  hDC,
+	INT  XStart,
+	INT  YStart,
+	COLORREF  Fill)
 {
-  return NtGdiExtFloodFill(hDC, XStart, YStart, Fill, FLOODFILLBORDER );
+	return NtGdiExtFloodFill(hDC, XStart, YStart, Fill, FLOODFILLBORDER );
 }
 
-BOOL STDCALL NtGdiGetBitmapDimensionEx(HBITMAP  hBitmap,
-                               LPSIZE  Dimension)
+BOOL STDCALL
+NtGdiGetBitmapDimensionEx(
+	HBITMAP  hBitmap,
+	LPSIZE  Dimension)
 {
-  PBITMAPOBJ  bmp;
+	PBITMAPOBJ  bmp;
 
-  bmp = BITMAPOBJ_LockBitmap(hBitmap);
-  if (bmp == NULL)
-  {
-    return FALSE;
-  }
+	bmp = BITMAPOBJ_LockBitmap(hBitmap);
+	if (bmp == NULL)
+	{
+		return FALSE;
+	}
 
-  *Dimension = bmp->dimension;
+	*Dimension = bmp->dimension;
 
-  BITMAPOBJ_UnlockBitmap(hBitmap);
+	BITMAPOBJ_UnlockBitmap(hBitmap);
 
-  return  TRUE;
+	return  TRUE;
 }
 
-COLORREF
-STDCALL
+COLORREF STDCALL
 NtGdiGetPixel(HDC hDC, INT XPos, INT YPos)
 {
-   PDC dc = NULL;
-   COLORREF clrSource, Result = (COLORREF)CLR_INVALID; // default to failure
-   PSURFGDI Surface;
-   PSURFOBJ SurfaceObject;
-   HPALETTE Pal;
-   PPALGDI PalGDI;
-   USHORT PalMode;
-   PXLATEOBJ XlateObj;
-
-   dc = DC_LockDc (hDC);
-   if (dc != NULL)
-   {
-      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);
-
-               XlateObj = (PXLATEOBJ)IntEngCreateXlate ( PAL_RGB, PalMode, NULL, Pal );
-               if ( XlateObj )
-               {
-                  Result = XLATEOBJ_iXlate(XlateObj, clrSource);
-                  EngDeleteXlate(XlateObj);
-               }
-            }
-         }
-      }
-      DC_UnlockDc(hDC);
-   }
+	PDC dc = NULL;
+	COLORREF Result = (COLORREF)CLR_INVALID; // default to failure
+	BOOL bInRect = FALSE;
+	PSURFGDI Surface;
+	PSURFOBJ SurfaceObject;
+	HPALETTE Pal;
+	PPALGDI PalGDI;
+	USHORT PalMode;
+	PXLATEOBJ XlateObj;
+
+	dc = DC_LockDc (hDC);
+
+	if ( !dc )
+	{
+		SetLastWin32Error(ERROR_INVALID_HANDLE);
+		return Result;
+	}
+	if ( IN_RECT(dc->CombinedClip->rclBounds,XPos,YPos) )
+	{
+		bInRect = TRUE;
+		SurfaceObject = (PSURFOBJ)AccessUserObject((ULONG)dc->Surface);
+		ASSERT(SurfaceObject);
+		Surface = (PSURFGDI)AccessInternalObjectFromUserObject(SurfaceObject);
+		if ( Surface )
+		{
+			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);
+
+				XlateObj = (PXLATEOBJ)IntEngCreateXlate ( PAL_RGB, PalMode, NULL, Pal );
+				if ( XlateObj )
+				{
+					// check if this DC has a DIB behind it...
+					if ( SurfaceObject->pvScan0 ) // STYPE_BITMAP == SurfaceObject->iType
+					{
+						ASSERT ( SurfaceObject->lDelta && Surface->DIB_GetPixel );
+						Result = XLATEOBJ_iXlate(XlateObj, Surface->DIB_GetPixel ( SurfaceObject, XPos, YPos ) );
+					}
+					EngDeleteXlate(XlateObj);
+				}
+			}
+		}
+	}
+	DC_UnlockDc(hDC);
+
+	// if Result is still CLR_INVALID, then the "quick" method above didn't work
+	if ( bInRect && Result == CLR_INVALID )
+	{
+		// FIXME: create a 1x1 32BPP DIB, and blit to it
+		HDC hDCTmp = NtGdiCreateCompatableDC(hDC);
+		if ( hDCTmp )
+		{
+			static const BITMAPINFOHEADER bih = { sizeof(BITMAPINFOHEADER), 1, 1, 1, 32, BI_RGB, 0, 0, 0, 0, 0 };
+			BITMAPINFO bi;
+			RtlMoveMemory ( &(bi.bmiHeader), &bih, sizeof(bih) );
+			HBITMAP hBmpTmp = NtGdiCreateDIBitmap ( hDC, &bi.bmiHeader, 0, NULL, &bi, DIB_RGB_COLORS );
+			//HBITMAP hBmpTmp = NtGdiCreateBitmap ( 1, 1, 1, 32, NULL);
+			if ( hBmpTmp )
+			{
+				HBITMAP hBmpOld = (HBITMAP)NtGdiSelectObject ( hDCTmp, hBmpTmp );
+				if ( hBmpOld )
+				{
+					PBITMAPOBJ bmpobj;
+
+					NtGdiBitBlt ( hDCTmp, 0, 0, 1, 1, hDC, XPos, YPos, SRCCOPY );
+					NtGdiSelectObject ( hDCTmp, hBmpOld );
+
+					// our bitmap is no longer selected, so we can access it's stuff...
+					bmpobj = BITMAPOBJ_LockBitmap ( hBmpTmp );
+					if ( bmpobj )
+					{
+						Result = *(COLORREF*)bmpobj->bitmap.bmBits;
+						BITMAPOBJ_UnlockBitmap ( hBmpTmp );
+					}
+				}
+				NtGdiDeleteObject ( hBmpTmp );
+			}
+			NtGdiDeleteDC ( hDCTmp );
+		}
+	}
 
-   return Result;
+	return Result;
 }
 
 /***********************************************************************
  * MaskBlt
  * Ported from WINE by sedwards 11-4-03
- * 
- * Someone thought it would be faster to do it here and then switch back 
- * to GDI32. I dunno. Write a test and let me know. 
+ *
+ * Someone thought it would be faster to do it here and then switch back
+ * to GDI32. I dunno. Write a test and let me know.
[truncated at 1000 lines; 1256 more skipped]
CVSspam 0.2.8