Author: gedmurphy
Date: Tue Sep 18 19:24:34 2007
New Revision: 29093
URL:
http://svn.reactos.org/svn/reactos?rev=29093&view=rev
Log:
- when converting from a DDB to a DIB, the palette should be the same in the resulting DIB
as the original DDB. This fixes the colour issue we had in the taskbar icons. (there's
still a bit position problem as highlighted in the 1-4 bitmaps)
- Reformat the NtGdiGetDIBitsInternal code to a more readable state.
*note, this function needs a considerable work.
Modified:
trunk/reactos/subsystems/win32/win32k/objects/dibobj.c
Modified: trunk/reactos/subsystems/win32/win32k/objects/dibobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dibobj.c (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dibobj.c Tue Sep 18 19:24:34 2007
@@ -348,225 +348,236 @@
UINT MaxBits,
UINT MaxInfo)
{
- BITMAPOBJ *BitmapObj;
- SURFOBJ *DestSurfObj;
- XLATEOBJ *XlateObj;
- HBITMAP DestBitmap;
- SIZEL DestSize;
- HPALETTE hSourcePalette;
- HPALETTE hDestPalette;
- PPALGDI SourcePalette;
- PPALGDI DestPalette;
- ULONG SourcePaletteType;
- ULONG DestPaletteType;
- PDC Dc;
- POINTL SourcePoint;
- RECTL DestRect;
- ULONG Result = 0;
- ULONG Index;
-
- /* Get handle for the palette in DC. */
- Dc = DC_LockDc(hDC);
- if (Dc == NULL)
- {
- SetLastWin32Error(ERROR_INVALID_HANDLE);
- return 0;
- }
- if (Dc->IsIC)
- {
- DC_UnlockDc(Dc);
- return 0;
- }
- hSourcePalette = Dc->w.hPalette;
- /* FIXME: This is incorrect. hDestPalette should be something other. */
- hDestPalette = Dc->DevInfo->hpalDefault;
- DC_UnlockDc(Dc);
-
- /* Get pointer to the source bitmap object. */
- BitmapObj = BITMAPOBJ_LockBitmap(hBitmap);
- if (BitmapObj == NULL)
- {
- SetLastWin32Error(ERROR_INVALID_HANDLE);
- return 0;
- }
-
- if (Bits == NULL)
- {
- if (Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
- {
- BITMAPCOREHEADER* coreheader = (BITMAPCOREHEADER*) Info;
- coreheader->bcWidth =BitmapObj->SurfObj.sizlBitmap.cx;
- coreheader->bcPlanes = 1;
- coreheader->bcBitCount =
BitsPerFormat(BitmapObj->SurfObj.iBitmapFormat);
-
- coreheader->bcHeight = BitmapObj->SurfObj.sizlBitmap.cy;
- if (BitmapObj->SurfObj.lDelta > 0)
- coreheader->bcHeight = -coreheader->bcHeight;
-
- Result = BitmapObj->SurfObj.sizlBitmap.cy;
- }
-
- if (Info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
- {
- Info->bmiHeader.biWidth = BitmapObj->SurfObj.sizlBitmap.cx;
- Info->bmiHeader.biHeight = BitmapObj->SurfObj.sizlBitmap.cy;
- /* Report negtive height for top-down bitmaps. */
- if (BitmapObj->SurfObj.lDelta > 0)
- Info->bmiHeader.biHeight = -Info->bmiHeader.biHeight;
- Info->bmiHeader.biPlanes = 1;
- Info->bmiHeader.biBitCount =
BitsPerFormat(BitmapObj->SurfObj.iBitmapFormat);
- if (Info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
- {
- switch (BitmapObj->SurfObj.iBitmapFormat)
+ BITMAPOBJ *BitmapObj;
+ SURFOBJ *DestSurfObj;
+ XLATEOBJ *XlateObj;
+ HBITMAP DestBitmap;
+ SIZEL DestSize;
+ HPALETTE hSourcePalette;
+ HPALETTE hDestPalette;
+ PPALGDI SourcePalette;
+ PPALGDI DestPalette;
+ ULONG SourcePaletteType;
+ ULONG DestPaletteType;
+ PDC Dc;
+ POINTL SourcePoint;
+ RECTL DestRect;
+ ULONG Result = 0;
+ ULONG Index;
+
+ /* Get handle for the palette in DC. */
+ Dc = DC_LockDc(hDC);
+ if (Dc == NULL)
+ {
+ SetLastWin32Error(ERROR_INVALID_HANDLE);
+ return 0;
+ }
+ if (Dc->IsIC)
+ {
+ DC_UnlockDc(Dc);
+ return 0;
+ }
+
+ hSourcePalette = Dc->w.hPalette;
+ hDestPalette = Dc->w.hPalette; // unsure of this (Ged)
+ DC_UnlockDc(Dc);
+
+ /* Get pointer to the source bitmap object. */
+ BitmapObj = BITMAPOBJ_LockBitmap(hBitmap);
+ if (BitmapObj == NULL)
+ {
+ SetLastWin32Error(ERROR_INVALID_HANDLE);
+ return 0;
+ }
+
+ if (Bits == NULL)
+ {
+ if (Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
+ {
+ BITMAPCOREHEADER* coreheader = (BITMAPCOREHEADER*) Info;
+ coreheader->bcWidth =BitmapObj->SurfObj.sizlBitmap.cx;
+ coreheader->bcPlanes = 1;
+ coreheader->bcBitCount =
BitsPerFormat(BitmapObj->SurfObj.iBitmapFormat);
+
+ coreheader->bcHeight = BitmapObj->SurfObj.sizlBitmap.cy;
+
+ if (BitmapObj->SurfObj.lDelta > 0)
+ coreheader->bcHeight = -coreheader->bcHeight;
+
+ Result = BitmapObj->SurfObj.sizlBitmap.cy;
+ }
+
+ if (Info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
+ {
+ Info->bmiHeader.biWidth = BitmapObj->SurfObj.sizlBitmap.cx;
+ Info->bmiHeader.biHeight = BitmapObj->SurfObj.sizlBitmap.cy;
+ /* Report negtive height for top-down bitmaps. */
+ if (BitmapObj->SurfObj.lDelta > 0)
+ Info->bmiHeader.biHeight = -Info->bmiHeader.biHeight;
+ Info->bmiHeader.biPlanes = 1;
+ Info->bmiHeader.biBitCount =
BitsPerFormat(BitmapObj->SurfObj.iBitmapFormat);
+ if (Info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
{
- case BMF_1BPP: case BMF_4BPP: case BMF_8BPP:
- case BMF_16BPP: case BMF_24BPP: case BMF_32BPP:
- Info->bmiHeader.biCompression = BI_RGB;
- break;
- case BMF_4RLE:
- Info->bmiHeader.biCompression = BI_RLE4;
- break;
- case BMF_8RLE:
- Info->bmiHeader.biCompression = BI_RLE8;
- break;
- case BMF_JPEG:
- Info->bmiHeader.biCompression = BI_JPEG;
- break;
- case BMF_PNG:
- Info->bmiHeader.biCompression = BI_PNG;
- break;
+ switch (BitmapObj->SurfObj.iBitmapFormat)
+ {
+ case BMF_1BPP:
+ case BMF_4BPP:
+ case BMF_8BPP:
+ case BMF_16BPP:
+ case BMF_24BPP:
+ case BMF_32BPP:
+ Info->bmiHeader.biCompression = BI_RGB;
+ break;
+ case BMF_4RLE:
+ Info->bmiHeader.biCompression = BI_RLE4;
+ break;
+ case BMF_8RLE:
+ Info->bmiHeader.biCompression = BI_RLE8;
+ break;
+ case BMF_JPEG:
+ Info->bmiHeader.biCompression = BI_JPEG;
+ break;
+ case BMF_PNG:
+ Info->bmiHeader.biCompression = BI_PNG;
+ break;
+ }
+
+ Info->bmiHeader.biSizeImage = BitmapObj->SurfObj.cjBits;
+ Info->bmiHeader.biXPelsPerMeter = 0; /* FIXME */
+ Info->bmiHeader.biYPelsPerMeter = 0; /* FIXME */
+ Info->bmiHeader.biClrUsed = 0;
+ Info->bmiHeader.biClrImportant = 1 <<
Info->bmiHeader.biBitCount; /* FIXME */
+ Result = BitmapObj->SurfObj.sizlBitmap.cy;
}
- Info->bmiHeader.biSizeImage = BitmapObj->SurfObj.cjBits;
- Info->bmiHeader.biXPelsPerMeter = 0; /* FIXME */
- Info->bmiHeader.biYPelsPerMeter = 0; /* FIXME */
- Info->bmiHeader.biClrUsed =
- Info->bmiHeader.biClrImportant = 1 << Info->bmiHeader.biBitCount;
/* FIXME */
- Result = BitmapObj->SurfObj.sizlBitmap.cy;
- }
- }
- }
- else
- {
- if (StartScan > BitmapObj->SurfObj.sizlBitmap.cy)
- {
- Result = 0;
- }
- else
- {
- ScanLines = min(ScanLines, BitmapObj->SurfObj.sizlBitmap.cy - StartScan);
- DestSize.cx = BitmapObj->SurfObj.sizlBitmap.cx;
- DestSize.cy = ScanLines;
-
- DestBitmap = NULL;
- if (Info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
- {
- DestBitmap = EngCreateBitmap(DestSize,
- /* DIB_GetDIBWidthBytes(DestSize.cx,
Info->bmiHeader.biBitCount), */
- DestSize.cx * (Info->bmiHeader.biBitCount >> 3), /*
HACK */
- BitmapFormat(Info->bmiHeader.biBitCount,
Info->bmiHeader.biCompression),
- 0 < Info->bmiHeader.biHeight ? 0 :
BMF_TOPDOWN,
- Bits);
- }
-
- if (Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
- {
- BITMAPCOREHEADER* coreheader = (BITMAPCOREHEADER*) Info;
-
- DestBitmap = EngCreateBitmap(DestSize,
- DIB_GetDIBWidthBytes(DestSize.cx, coreheader->bcBitCount),
- BitmapFormat(coreheader->bcBitCount,
BI_RGB),
- 0 < coreheader->bcHeight ? 0 :
BMF_TOPDOWN,
- Bits);
- }
-
- if(DestBitmap == NULL)
- {
- BITMAPOBJ_UnlockBitmap(BitmapObj);
- return 0;
- }
-
- DestSurfObj = EngLockSurface((HSURF)DestBitmap);
-
- SourcePalette = PALETTE_LockPalette(hSourcePalette);
- /* FIXME - SourcePalette can be NULL!!! Don't assert here! */
- ASSERT(SourcePalette);
- SourcePaletteType = SourcePalette->Mode;
- PALETTE_UnlockPalette(SourcePalette);
-
- DestPalette = PALETTE_LockPalette(hDestPalette);
- /* FIXME - DestPalette can be NULL!!!! Don't assert here!!! */
- ASSERT(DestPalette);
- DestPaletteType = DestPalette->Mode;
-
- /* Copy palette. */
- /* FIXME: This is largely incomplete. */
- if (Info->bmiHeader.biBitCount <= 8)
- {
- if (Usage == DIB_RGB_COLORS)
+ }
+ }
+ else
+ {
+ if (StartScan > BitmapObj->SurfObj.sizlBitmap.cy)
+ {
+ Result = 0;
+ }
+ else
+ {
+ ScanLines = min(ScanLines, BitmapObj->SurfObj.sizlBitmap.cy - StartScan);
+ DestSize.cx = BitmapObj->SurfObj.sizlBitmap.cx;
+ DestSize.cy = ScanLines;
+
+ DestBitmap = NULL;
+ if (Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
{
- for (Index = 0;
- Index < (1 << Info->bmiHeader.biBitCount) &&
- Index < DestPalette->NumColors;
- Index++)
- {
- Info->bmiColors[Index].rgbRed =
- DestPalette->IndexedColors[Index].peRed;
- Info->bmiColors[Index].rgbGreen =
- DestPalette->IndexedColors[Index].peGreen;
- Info->bmiColors[Index].rgbBlue =
- DestPalette->IndexedColors[Index].peBlue;
- }
+ BITMAPCOREHEADER* coreheader = (BITMAPCOREHEADER*) Info;
+
+ DestBitmap = EngCreateBitmap(DestSize,
+ DIB_GetDIBWidthBytes(DestSize.cx,
coreheader->bcBitCount),
+ BitmapFormat(coreheader->bcBitCount,
BI_RGB),
+ 0 < coreheader->bcHeight ? 0 :
BMF_TOPDOWN,
+ Bits);
}
- if (Usage == DIB_PAL_COLORS)
+
+ if (Info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
{
- DPRINT1("GetDIBits with DIB_PAL_COLORS isn't implemented
yet.");
+ INT one, two, three;
+
+ one = DIB_GetDIBWidthBytes(DestSize.cx, Info->bmiHeader.biBitCount),
+ two = ((DestSize.cx * Info->bmiHeader.biBitCount + 31) & ~31)
>> 3;
+ three = DestSize.cx * (Info->bmiHeader.biBitCount >> 3);
+
+ DestBitmap = EngCreateBitmap(DestSize,
+ /* DIB_GetDIBWidthBytes(DestSize.cx,
Info->bmiHeader.biBitCount), */
+ DestSize.cx * (Info->bmiHeader.biBitCount
>> 3), /* HACK */
+ BitmapFormat(Info->bmiHeader.biBitCount,
Info->bmiHeader.biCompression),
+ 0 < Info->bmiHeader.biHeight ? 0 :
BMF_TOPDOWN,
+ Bits);
}
- }
-
- PALETTE_UnlockPalette(DestPalette);
-
- XlateObj = IntEngCreateXlate(
- DestPaletteType, SourcePaletteType, hDestPalette, hSourcePalette);
-
- SourcePoint.x = 0;
- SourcePoint.y = BitmapObj->SurfObj.sizlBitmap.cy -
- (StartScan + ScanLines);
-
- /* Determine destination rectangle */
- DestRect.top = 0;
- DestRect.left = 0;
- DestRect.right = DestSize.cx;
- DestRect.bottom = DestSize.cy;
-
- if (EngCopyBits(DestSurfObj, &BitmapObj->SurfObj,
- NULL, XlateObj, &DestRect, &SourcePoint))
- {
- Result = ScanLines;
- }
-
- EngDeleteXlate(XlateObj);
- EngUnlockSurface(DestSurfObj);
- }
- }
-
- BITMAPOBJ_UnlockBitmap(BitmapObj);
-
- return Result;
+
+ if(DestBitmap == NULL)
+ {
+ BITMAPOBJ_UnlockBitmap(BitmapObj);
+ return 0;
+ }
+
+ DestSurfObj = EngLockSurface((HSURF)DestBitmap);
+
+ SourcePalette = PALETTE_LockPalette(hSourcePalette);
+ /* FIXME - SourcePalette can be NULL!!! Don't assert here! */
+ ASSERT(SourcePalette);
+ SourcePaletteType = SourcePalette->Mode;
+ PALETTE_UnlockPalette(SourcePalette);
+
+ DestPalette = PALETTE_LockPalette(hDestPalette);
+ /* FIXME - DestPalette can be NULL!!!! Don't assert here!!! */
+ //ASSERT(DestPalette);
+ DestPaletteType = DestPalette->Mode;
+
+ /* Copy palette. */
+ /* FIXME: This is largely incomplete. */
+ if (Info->bmiHeader.biBitCount <= 8)
+ {
+ if (Usage == DIB_RGB_COLORS)
+ {
+ for (Index = 0;
+ Index < (1 << Info->bmiHeader.biBitCount) &&
Index < DestPalette->NumColors;
+ Index++)
+ {
+ Info->bmiColors[Index].rgbRed =
DestPalette->IndexedColors[Index].peRed;
+ Info->bmiColors[Index].rgbGreen =
DestPalette->IndexedColors[Index].peGreen;
+ Info->bmiColors[Index].rgbBlue =
DestPalette->IndexedColors[Index].peBlue;
+ }
+ }
+
+ if (Usage == DIB_PAL_COLORS)
+ {
+ DPRINT1("GetDIBits with DIB_PAL_COLORS isn't implemented
yet\n");
+ }
+ }
+
+ PALETTE_UnlockPalette(DestPalette);
+
+ XlateObj = IntEngCreateXlate(DestPaletteType, SourcePaletteType,
hDestPalette, hSourcePalette);
+
+ SourcePoint.x = 0;
+ SourcePoint.y = BitmapObj->SurfObj.sizlBitmap.cy - (StartScan +
ScanLines);
+
+ /* Determine destination rectangle */
+ DestRect.top = 0;
+ DestRect.left = 0;
+ DestRect.right = DestSize.cx;
+ DestRect.bottom = DestSize.cy;
+
+ if (EngCopyBits(DestSurfObj,
+ &BitmapObj->SurfObj,
+ NULL,
+ XlateObj,
+ &DestRect,
+ &SourcePoint))
+ {
+ Result = ScanLines;
+ }
+
+ EngDeleteXlate(XlateObj);
+ EngUnlockSurface(DestSurfObj);
+ }
+ }
+
+ BITMAPOBJ_UnlockBitmap(BitmapObj);
+
+ return Result;
}
INT STDCALL NtGdiStretchDIBits(HDC hDC,
- INT XDest,
- INT YDest,
- INT DestWidth,
- INT DestHeight,
- INT XSrc,
- INT YSrc,
- INT SrcWidth,
- INT SrcHeight,
- CONST VOID *Bits,
- CONST BITMAPINFO *BitsInfo,
- UINT Usage,
- DWORD ROP)
+ INT XDest,
+ INT YDest,
+ INT DestWidth,
+ INT DestHeight,
+ INT XSrc,
+ INT YSrc,
+ INT SrcWidth,
+ INT SrcHeight,
+ CONST VOID *Bits,
+ CONST BITMAPINFO *BitsInfo,
+ UINT Usage,
+ DWORD ROP)
{
HBITMAP hBitmap, hOldBitmap;
HDC hdcMem;