Author: tkreuzer
Date: Sun Jan 9 18:38:41 2011
New Revision: 50343
URL:
http://svn.reactos.org/svn/reactos?rev=50343&view=rev
Log:
[WIN32K]
- In BitmapFormat, allow intermediate bpp values, use ULONG as parameter type, instead of
WORD and DWORD
- In NtGdiCreateBitmap get the real bpp value from the gajBitsPerFormat array
- Add back check of too large nWidth (needed to make sure, cjWidthBytes didn't
overflow)
- Merge all parameter checks
- Check cPlanes and cBitsPixel paramters explicitly
- Use GreCreateBitmapEx
- Remove BITMAP_GetRealBitsPixel
Modified:
trunk/reactos/subsystems/win32/win32k/eng/surface.c
trunk/reactos/subsystems/win32/win32k/include/bitmaps.h
trunk/reactos/subsystems/win32/win32k/include/surface.h
trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c
Modified: trunk/reactos/subsystems/win32/win32k/eng/surface.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/en…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/eng/surface.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/eng/surface.c [iso-8859-1] Sun Jan 9 18:38:41
2011
@@ -37,28 +37,19 @@
};
-ULONG FASTCALL BitmapFormat(WORD Bits, DWORD Compression)
-{
- switch (Compression)
+ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression)
+{
+ switch (iCompression)
{
case BI_RGB:
/* Fall through */
case BI_BITFIELDS:
- switch (Bits)
- {
- case 1:
- return BMF_1BPP;
- case 4:
- return BMF_4BPP;
- case 8:
- return BMF_8BPP;
- case 16:
- return BMF_16BPP;
- case 24:
- return BMF_24BPP;
- case 32:
- return BMF_32BPP;
- }
+ if (cBits <= 1) return BMF_1BPP;
+ if (cBits <= 4) return BMF_4BPP;
+ if (cBits <= 8) return BMF_8BPP;
+ if (cBits <= 16) return BMF_16BPP;
+ if (cBits <= 24) return BMF_24BPP;
+ if (cBits <= 32) return BMF_32BPP;
return 0;
case BI_RLE4:
Modified: trunk/reactos/subsystems/win32/win32k/include/bitmaps.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/bitmaps.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/bitmaps.h [iso-8859-1] Sun Jan 9
18:38:41 2011
@@ -11,7 +11,6 @@
INT APIENTRY BITMAP_GetObject(SURFACE * bmp, INT count, LPVOID buffer);
HBITMAP FASTCALL IntCreateBitmap(IN SIZEL Size, IN LONG Width, IN ULONG Format, IN ULONG
Flags, IN PVOID Bits);
HBITMAP FASTCALL BITMAP_CopyBitmap (HBITMAP hBitmap);
-UINT FASTCALL BITMAP_GetRealBitsPixel(UINT nBitsPixel);
HBITMAP
APIENTRY
Modified: trunk/reactos/subsystems/win32/win32k/include/surface.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/in…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/surface.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/include/surface.h [iso-8859-1] Sun Jan 9
18:38:41 2011
@@ -125,7 +125,7 @@
#define GDIDEV(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev))
#define GDIDEVFUNCS(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev))->DriverFunctions
-ULONG FASTCALL BitmapFormat (WORD Bits, DWORD Compression);
+ULONG FASTCALL BitmapFormat(ULONG cBits, ULONG iCompression);
extern UCHAR gajBitsPerFormat[];
#define BitsPerFormat(Format) gajBitsPerFormat[Format]
Modified: trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/bitmaps.c [iso-8859-1] Sun Jan 9
18:38:41 2011
@@ -161,60 +161,47 @@
IN OPTIONAL LPBYTE pUnsafeBits)
{
HBITMAP hbmp;
- ULONG cjWidthBytes, iFormat;
-
- /* NOTE: Windows also doesn't store nr. of planes separately! */
- cBitsPixel = BITMAP_GetRealBitsPixel(cBitsPixel * cPlanes);
-
- /* Calculate bitmap format */
- iFormat = BitmapFormat(cBitsPixel, BI_RGB);
-
- /* Check parameters */
- if (iFormat == 0 || nWidth <= 0 || nHeight <= 0)
- {
- DPRINT1("Width = %d, Height = %d BitsPixel = %d\n",
- nWidth, nHeight, cBitsPixel);
+ ULONG cRealBpp, cjWidthBytes, iFormat;
+ ULONGLONG cjSize;
+
+ /* Calculate bitmap format and real bits per pixel. */
+ iFormat = BitmapFormat(cBitsPixel * cPlanes, BI_RGB);
+ cRealBpp = gajBitsPerFormat[iFormat];
+
+ /* Calculate width and image size in bytes */
+ cjWidthBytes = WIDTH_BYTES_ALIGN16(nWidth, cRealBpp);
+ cjSize = cjWidthBytes * nHeight;
+
+ /* Check parameters (possible overflow of cjWidthBytes!) */
+ if (iFormat == 0 || nWidth <= 0 || nWidth >= 0x8000000 || nHeight <= 0 ||
+ cBitsPixel > 32 || cPlanes > 32 || cjSize >= 0x100000000ULL)
+ {
+ DPRINT1("Invalid bitmap format! Width=%d, Height=%d, Bpp=%d,
Planes=%d\n",
+ nWidth, nHeight, cBitsPixel, cPlanes);
EngSetLastError(ERROR_INVALID_PARAMETER);
return NULL;
}
- if(WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel)*nHeight >= 0x8000000)
- {
- /* I just can't get enough, I just can't get enough */
- EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
- return NULL;
- }
-
- /* Make sure that cjBits will not overflow */
- cjWidthBytes = WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel);
- if ((ULONGLONG)cjWidthBytes * nHeight >= 0x100000000ULL)
- {
- DPRINT1("Width = %d, Height = %d BitsPixel = %d\n",
- nWidth, nHeight, cBitsPixel);
- EngSetLastError(ERROR_INVALID_PARAMETER);
- return NULL;
- }
-
- /* cBitsPixel = cBitsPixel * cPlanes now! */
- hbmp = GreCreateBitmap(nWidth, nHeight, 1, cBitsPixel, NULL);
-
- if (pUnsafeBits)
- {
- PSURFACE psurf = SURFACE_LockSurface(hbmp);
+ /* Call internal function. */
+ hbmp = GreCreateBitmapEx(nWidth, nHeight, 0, iFormat, 0, 0, NULL, DDB_SURFACE);
+
+ if (pUnsafeBits && hbmp)
+ {
+ PSURFACE psurf = SURFACE_LockSurface(hbmp);
_SEH2_TRY
{
- ProbeForRead(pUnsafeBits, cjWidthBytes * nHeight, 1);
+ ProbeForRead(pUnsafeBits, cjSize, 1);
UnsafeSetBitmapBits(psurf, 0, pUnsafeBits);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- SURFACE_UnlockSurface(psurf);
+ SURFACE_UnlockSurface(psurf);
SURFACE_FreeSurfaceByHandle(hbmp);
_SEH2_YIELD(return NULL;)
}
_SEH2_END
- SURFACE_UnlockSurface(psurf);
+ SURFACE_UnlockSurface(psurf);
}
return hbmp;
@@ -833,25 +820,6 @@
/* Internal Functions */
-
-UINT FASTCALL
-BITMAP_GetRealBitsPixel(UINT nBitsPixel)
-{
- if (nBitsPixel <= 1)
- return 1;
- 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;
-}
HBITMAP FASTCALL
BITMAP_CopyBitmap(HBITMAP hBitmap)