- DIB data is not mandatory in CreateDIBitmap
[WIN32K]
  - Simplify GreCreateDIBitmap
  - Surface data should be 16 bits aligned

svn path=/branches/reactos-yarotows/; revision=47735
This commit is contained in:
Jérôme Gardou 2010-06-10 14:32:05 +00:00
parent cc4ef59c16
commit f57bcb3e25
3 changed files with 43 additions and 69 deletions

View file

@ -461,8 +461,8 @@ CreateDIBitmap( HDC hDC,
LONG width, height, compr, dibsize; LONG width, height, compr, dibsize;
WORD planes, bpp; WORD planes, bpp;
// PDC_ATTR pDc_Attr; // PDC_ATTR pDc_Attr;
UINT InfoSize; UINT InfoSize = 0;
UINT cjBmpScanSize; UINT cjBmpScanSize = 0;
HBITMAP hBmp; HBITMAP hBmp;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
@ -477,17 +477,20 @@ CreateDIBitmap( HDC hDC,
// For Icm support. // For Icm support.
// GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID)&pDc_Attr)) // GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID)&pDc_Attr))
_SEH2_TRY if(Data)
{ {
cjBmpScanSize = DIB_BitmapBitsSize(Data); _SEH2_TRY
CalculateColorTableSize(&Data->bmiHeader, &ColorUse, &InfoSize); {
InfoSize += Data->bmiHeader.biSize; cjBmpScanSize = DIB_BitmapBitsSize(Data);
CalculateColorTableSize(&Data->bmiHeader, &ColorUse, &InfoSize);
InfoSize += Data->bmiHeader.biSize;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Status = _SEH2_GetExceptionCode();
}
_SEH2_END
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Status = _SEH2_GetExceptionCode();
}
_SEH2_END
if(!NT_SUCCESS(Status)) if(!NT_SUCCESS(Status))
{ {

View file

@ -203,12 +203,12 @@ SURFACE_bSetBitmapBits(
if (ulWidth) if (ulWidth)
{ {
/* Align the width (Windows compatibility) */ /* Align the width (Windows compatibility) */
ulWidth = ((((ulWidth << 3) / cBitsPixel) * cBitsPixel + 31) & ~31) >> 3; ulWidth = ((((ulWidth << 3) / cBitsPixel) * cBitsPixel + 15) & ~15) >> 3;
} }
else else
{ {
/* Calculate width from the bitmap width in pixels */ /* Calculate width from the bitmap width in pixels */
ulWidth = ((pso->sizlBitmap.cx * cBitsPixel + 31) & ~31) >> 3; ulWidth = ((pso->sizlBitmap.cx * cBitsPixel + 15) & ~15) >> 3;
} }
/* Calculate the bitmap size in bytes */ /* Calculate the bitmap size in bytes */

View file

@ -1177,68 +1177,39 @@ GreCreateDIBitmapInternal(
PDC Dc; PDC Dc;
HBITMAP Bmp; HBITMAP Bmp;
WORD bpp; WORD bpp;
HDC hdcDest;
if (!hDc) // CreateBitmap if (!hDc) /* 1bpp monochrome bitmap */
{ // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this. { // Should use System Bitmap DC hSystemBM, with CreateCompatibleDC for this.
hDc = IntGdiCreateDC(NULL, NULL, NULL, NULL,FALSE); hdcDest = IntGdiCreateDC(NULL, NULL, NULL, NULL,FALSE);
if (!hDc) if(!hdcDest)
{ {
SetLastWin32Error(ERROR_INVALID_HANDLE);
return NULL; return NULL;
} }
Dc = DC_LockDc(hDc);
if (!Dc)
{
NtGdiDeleteObjectApp(hDc);
SetLastWin32Error(ERROR_INVALID_HANDLE);
return NULL;
}
bpp = 1;
Bmp = IntCreateDIBitmap(Dc, cx, cy, bpp, fInit, pjInit, pbmi, iUsage);
DC_UnlockDc(Dc);
NtGdiDeleteObjectApp(hDc);
} }
else // CreateCompatibleBitmap else
{ {
Dc = DC_LockDc(hDc); hdcDest = hDc;
if (!Dc) }
{
SetLastWin32Error(ERROR_INVALID_HANDLE); Dc = DC_LockDc(hdcDest);
return NULL; if (!Dc)
} {
/* pbmi == null SetLastWin32Error(ERROR_INVALID_HANDLE);
First create an un-initialised bitmap. The depth of the bitmap return NULL;
should match that of the hdc and not that supplied in bmih. }
*/ /* It's OK to set bpp=0 here, as IntCreateDIBitmap will create a compatible Bitmap
if (pbmi) * if bpp != 1 and ignore the real value that was passed */
bpp = pbmi->bmiHeader.bV5BitCount; if (pbmi)
else bpp = pbmi->bmiHeader.bV5BitCount;
{ else
if (Dc->dctype != DC_TYPE_MEMORY) bpp = 0;
bpp = Dc->ppdev->gdiinfo.cBitsPixel; Bmp = IntCreateDIBitmap(Dc, cx, cy, bpp, fInit, pjInit, pbmi, iUsage);
else DC_UnlockDc(Dc);
{
DIBSECTION dibs; if(!hDc)
INT Count; {
SURFACE *psurf = Dc->dclevel.pSurface; NtGdiDeleteObjectApp(hdcDest);
Count = BITMAP_GetObject(psurf, sizeof(dibs), &dibs);
if (!Count)
bpp = 1;
else
{
if (Count == sizeof(BITMAP))
/* A device-dependent bitmap is selected in the DC */
bpp = dibs.dsBm.bmBitsPixel;
else
/* A DIB section is selected in the DC */
bpp = dibs.dsBmih.biBitCount;
}
}
}
Bmp = IntCreateDIBitmap(Dc, cx, cy, bpp, fInit, pjInit, pbmi, iUsage);
DC_UnlockDc(Dc);
} }
return Bmp; return Bmp;
} }