Author: tkreuzer Date: Wed Aug 15 03:22:07 2007 New Revision: 28341
URL: http://svn.reactos.org/svn/reactos?rev=28341&view=rev Log: - Rename NtGdiCreateBitmap to IntGdiCreateBitmap and remove SEH - implement new NtGdiCreateBitmap, calling IntGdiCreateBitmap with SEH - Use only IntGdiCreateBitmap internally - implement BITMAPOBJ_GetRealBitsPixel, finding an appropriate value for unsupported values of BitsPixel - make parameter validation more windows compatible
Modified: trunk/reactos/subsystems/win32/win32k/include/bitmaps.h trunk/reactos/subsystems/win32/win32k/include/intgdi.h trunk/reactos/subsystems/win32/win32k/ntuser/cursoricon.c trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c trunk/reactos/subsystems/win32/win32k/objects/brush.c trunk/reactos/subsystems/win32/win32k/objects/dc.c trunk/reactos/subsystems/win32/win32k/objects/pen.c
Modified: trunk/reactos/subsystems/win32/win32k/include/bitmaps.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/inc... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/include/bitmaps.h (original) +++ trunk/reactos/subsystems/win32/win32k/include/bitmaps.h Wed Aug 15 03:22:07 2007 @@ -39,6 +39,7 @@ void INTERNAL_CALL BITMAPOBJ_CleanupBitsLock(BITMAPOBJ *pBMObj);
INT FASTCALL BITMAPOBJ_GetWidthBytes (INT bmWidth, INT bpp); +INT FASTCALL BITMAPOBJ_GetRealBitsPixel(INT nBitsPixel); HBITMAP FASTCALL BITMAPOBJ_CopyBitmap (HBITMAP hBitmap); INT FASTCALL DIB_GetDIBWidthBytes (INT width, INT depth); int NTAPI DIB_GetDIBImageBytes (INT width, INT height, INT depth);
Modified: trunk/reactos/subsystems/win32/win32k/include/intgdi.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/inc... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/include/intgdi.h (original) +++ trunk/reactos/subsystems/win32/win32k/include/intgdi.h Wed Aug 15 03:22:07 2007 @@ -253,6 +253,14 @@ INT Width, INT Height);
+HBITMAP STDCALL +IntGdiCreateBitmap( + INT Width, + INT Height, + UINT Planes, + UINT BitsPixel, + IN OPTIONAL LPBYTE pBits); + HDC STDCALL IntGdiGetDCState(HDC hDC);
WORD STDCALL IntGdiSetHookFlags(HDC hDC, WORD Flags);
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/cursoricon.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ntu... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/ntuser/cursoricon.c (original) +++ trunk/reactos/subsystems/win32/win32k/ntuser/cursoricon.c Wed Aug 15 03:22:07 2007 @@ -1308,7 +1308,7 @@ } else { - BitmapStretched = NtGdiCreateBitmap(WidthDest, HeightDest, 1, 1, NULL); + BitmapStretched = IntGdiCreateBitmap(WidthDest, HeightDest, 1, 1, NULL); } if (NULL == BitmapStretched) {
Modified: trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/obj... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c (original) +++ trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c Wed Aug 15 03:22:07 2007 @@ -32,12 +32,12 @@ )
HBITMAP STDCALL -NtGdiCreateBitmap( +IntGdiCreateBitmap( INT Width, INT Height, UINT Planes, UINT BitsPixel, - IN OPTIONAL LPBYTE pUnsafeBits) + IN OPTIONAL LPBYTE pBits) { PBITMAPOBJ bmp; HBITMAP hBitmap; @@ -45,32 +45,33 @@ LONG WidthBytes;
/* NOTE: Windows also doesn't store nr. of planes separately! */ - BitsPixel = BitsPixel * Planes; + BitsPixel = BITMAPOBJ_GetRealBitsPixel(BitsPixel * Planes); + + /* Check parameters */ + if (BitsPixel == 0 || Width < 1 || Height < 1) + { + DPRINT1("Width = %d, Height = %d BitsPixel = %d\n", Width, Height, BitsPixel); + SetLastWin32Error(ERROR_INVALID_PARAMETER); + return 0; + } + WidthBytes = BITMAPOBJ_GetWidthBytes(Width, BitsPixel);
- /* Check parameters */ - if (0 == Height || 0 == Width) - { - Size.cx = Size.cy = 1; - } - else - { - Size.cx = abs(Width); - Size.cy = abs(Height); - } + Size.cx = Width; + Size.cy = Height;
/* Create the bitmap object. */ hBitmap = IntCreateBitmap(Size, WidthBytes, BitmapFormat(BitsPixel, BI_RGB), (Height < 0 ? BMF_TOPDOWN : 0) | - (NULL == pUnsafeBits ? 0 : BMF_NOZEROINIT), NULL); + (NULL == pBits ? 0 : BMF_NOZEROINIT), NULL); if (!hBitmap) { - DPRINT("NtGdiCreateBitmap: returned 0\n"); + DPRINT("IntGdiCreateBitmap: returned 0\n"); return 0; }
- DPRINT("NtGdiCreateBitmap:%dx%d, %d BPP colors returning %08x\n", + DPRINT("IntGdiCreateBitmap:%dx%d, %d BPP colors returning %08x\n", Size.cx, Size.cy, BitsPixel, hBitmap);
bmp = BITMAPOBJ_LockBitmap( hBitmap ); @@ -82,20 +83,41 @@
bmp->flFlags = BITMAPOBJ_IS_APIBITMAP;
- if (NULL != pUnsafeBits) + if (NULL != pBits) { - _SEH_TRY + IntSetBitmapBits(bmp, bmp->SurfObj.cjBits, pBits); + } + + BITMAPOBJ_UnlockBitmap( bmp ); + + return hBitmap; +} + + +HBITMAP STDCALL +NtGdiCreateBitmap( + INT Width, + INT Height, + UINT Planes, + UINT BitsPixel, + IN OPTIONAL LPBYTE pUnsafeBits) +{ + HBITMAP hBitmap; + + _SEH_TRY + { + if (pUnsafeBits) { - ProbeForRead(pUnsafeBits, bmp->SurfObj.cjBits, 1); - IntSetBitmapBits(bmp, bmp->SurfObj.cjBits, pUnsafeBits); + UINT cjBits = BITMAPOBJ_GetWidthBytes(Width, BitsPixel) * Height; + ProbeForRead(pUnsafeBits, cjBits, 1); } - _SEH_HANDLE - { - } - _SEH_END + hBitmap = IntGdiCreateBitmap(Width, Height, Planes, BitsPixel, pUnsafeBits); } - - BITMAPOBJ_UnlockBitmap( bmp ); + _SEH_HANDLE + { + hBitmap = 0; + } + _SEH_END
return hBitmap; } @@ -152,11 +174,11 @@ /* 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); + Bmp = IntGdiCreateBitmap (1, 1, 1, 1, NULL); } else { - Bmp = NtGdiCreateBitmap(Width, Height, 1, Dc->w.bitsPerPixel, NULL); + Bmp = IntGdiCreateBitmap(Width, Height, 1, Dc->w.bitsPerPixel, NULL); }
return Bmp; @@ -272,7 +294,7 @@ BITMAPINFO bi; RtlMoveMemory ( &(bi.bmiHeader), &bih, sizeof(bih) ); hBmpTmp = NtGdiCreateDIBitmap ( hDC, &bi.bmiHeader, 0, NULL, &bi, DIB_RGB_COLORS ); - //HBITMAP hBmpTmp = NtGdiCreateBitmap ( 1, 1, 1, 32, NULL); + //HBITMAP hBmpTmp = IntGdiCreateBitmap ( 1, 1, 1, 32, NULL); if ( hBmpTmp ) { HBITMAP hBmpOld = (HBITMAP)NtGdiSelectObject ( hDCTmp, hBmpTmp ); @@ -539,6 +561,29 @@ /* Internal Functions */
INT FASTCALL +BITMAPOBJ_GetRealBitsPixel(INT nBitsPixel) +{ + if (nBitsPixel < 0) + return 0; + if (nBitsPixel <= 1) + return 1; + if (nBitsPixel <= 2) + return 2; + if (nBitsPixel <= 4) + return 4; + if (nBitsPixel <= 8) + return 8; + if (nBitsPixel <= 16) + return 16; + if (nBitsPixel <= 24) + return 24; + if (nBitsPixel <= 32) + return 32; + + return 0; +} + +INT FASTCALL BITMAPOBJ_GetWidthBytes (INT bmWidth, INT bpp) { #if 0
Modified: trunk/reactos/subsystems/win32/win32k/objects/brush.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/obj... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/brush.c (original) +++ trunk/reactos/subsystems/win32/win32k/objects/brush.c Wed Aug 15 03:22:07 2007 @@ -326,7 +326,7 @@ else DataPtr += PaletteEntryCount * sizeof(USHORT);
- hPattern = NtGdiCreateBitmap(BitmapInfo->bmiHeader.biWidth, + hPattern = IntGdiCreateBitmap(BitmapInfo->bmiHeader.biWidth, BitmapInfo->bmiHeader.biHeight, BitmapInfo->bmiHeader.biPlanes, BitmapInfo->bmiHeader.biBitCount, @@ -378,7 +378,7 @@ return 0; }
- hPattern = NtGdiCreateBitmap(8, 8, 1, 1, (LPBYTE)HatchBrushes[Style]); + hPattern = IntGdiCreateBitmap(8, 8, 1, 1, (LPBYTE)HatchBrushes[Style]); if (hPattern == NULL) { SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
Modified: trunk/reactos/subsystems/win32/win32k/objects/dc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/obj... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/dc.c (original) +++ trunk/reactos/subsystems/win32/win32k/objects/dc.c Wed Aug 15 03:22:07 2007 @@ -226,7 +226,7 @@ NewDC->Dc_Attr.szlViewportExt.cy = OrigDC->Dc_Attr.szlViewportExt.cy;
/* Create default bitmap */ - if (!(hBitmap = NtGdiCreateBitmap( 1, 1, 1, NewDC->w.bitsPerPixel, NULL ))) + if (!(hBitmap = IntGdiCreateBitmap( 1, 1, 1, NewDC->w.bitsPerPixel, NULL ))) { DC_UnlockDc( OrigDC ); DC_UnlockDc( NewDC );
Modified: trunk/reactos/subsystems/win32/win32k/objects/pen.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/obj... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/objects/pen.c (original) +++ trunk/reactos/subsystems/win32/win32k/objects/pen.c Wed Aug 15 03:22:07 2007 @@ -99,27 +99,27 @@
case PS_ALTERNATE: PenObject->flAttrs |= GDIBRUSH_IS_BITMAP; - PenObject->hbmPattern = NtGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternAlternate); + PenObject->hbmPattern = IntGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternAlternate); break;
case PS_DOT: PenObject->flAttrs |= GDIBRUSH_IS_BITMAP; - PenObject->hbmPattern = NtGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDot); + PenObject->hbmPattern = IntGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDot); break;
case PS_DASH: PenObject->flAttrs |= GDIBRUSH_IS_BITMAP; - PenObject->hbmPattern = NtGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDash); + PenObject->hbmPattern = IntGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDash); break;
case PS_DASHDOT: PenObject->flAttrs |= GDIBRUSH_IS_BITMAP; - PenObject->hbmPattern = NtGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDashDot); + PenObject->hbmPattern = IntGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDashDot); break;
case PS_DASHDOTDOT: PenObject->flAttrs |= GDIBRUSH_IS_BITMAP; - PenObject->hbmPattern = NtGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDashDotDot); + PenObject->hbmPattern = IntGdiCreateBitmap(24, 1, 1, 1, (LPBYTE)PatternDashDotDot); break;
case PS_INSIDEFRAME: