Author: tkreuzer
Date: Sun Jan 3 16:16:04 2016
New Revision: 70482
URL:
http://svn.reactos.org/svn/reactos?rev=70482&view=rev
Log:
[WIN32K]
NtGdiCreateDIBitmapInternal: clear CBM_INIT flag, if no bits are given.
IntSetDIBits: Always calculate the bitmap size for uncompressed bitmaps, do not pass
uncompressed bits to GreCreateBitmapEx, since they don't have the required alignment
(the width in bytes for DIB is 16 bit aligned, bitmaps 32).
Remove a broken ASSERT.
Modified:
trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c
trunk/reactos/win32ss/gdi/ntgdi/bitmaps.h
trunk/reactos/win32ss/gdi/ntgdi/dibobj.c
Modified: trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/bitmaps.…
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/bitmaps.c [iso-8859-1] Sun Jan 3 16:16:04 2016
@@ -42,15 +42,15 @@
return GreSetObjectOwner(hbmp, ulOwner);
}
-static
-int
+BOOL
NTAPI
UnsafeSetBitmapBits(
- PSURFACE psurf,
- IN ULONG cjBits,
- IN PVOID pvBits)
-{
- PUCHAR pjDst, pjSrc;
+ _Inout_ PSURFACE psurf,
+ _In_ ULONG cjBits,
+ _In_ const VOID *pvBits)
+{
+ PUCHAR pjDst;
+ const UCHAR *pjSrc;
LONG lDeltaDst, lDeltaSrc;
ULONG nWidth, nHeight, cBitsPixel;
NT_ASSERT(psurf->flags & API_BITMAP);
@@ -69,7 +69,7 @@
/* Make sure the buffer is large enough*/
if (cjBits < (lDeltaSrc * nHeight))
- return 0;
+ return FALSE;
while (nHeight--)
{
@@ -79,7 +79,7 @@
pjDst += lDeltaDst;
}
- return 1;
+ return TRUE;
}
HBITMAP
Modified: trunk/reactos/win32ss/gdi/ntgdi/bitmaps.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/bitmaps.…
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/bitmaps.h [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/bitmaps.h [iso-8859-1] Sun Jan 3 16:16:04 2016
@@ -43,3 +43,10 @@
IN FLONG fl,
IN UINT cjMaxBits,
IN HANDLE hcmXform);
+
+BOOL
+NTAPI
+UnsafeSetBitmapBits(
+ _Inout_ PSURFACE psurf,
+ _In_ ULONG cjBits,
+ _In_ const VOID *pvBits);
Modified: trunk/reactos/win32ss/gdi/ntgdi/dibobj.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/win32ss/gdi/ntgdi/dibobj.c…
==============================================================================
--- trunk/reactos/win32ss/gdi/ntgdi/dibobj.c [iso-8859-1] (original)
+++ trunk/reactos/win32ss/gdi/ntgdi/dibobj.c [iso-8859-1] Sun Jan 3 16:16:04 2016
@@ -260,23 +260,26 @@
EXLATEOBJ exlo;
PPALETTE ppalDIB = 0;
ULONG cjSizeImage;
-
- if (!bmi) return 0;
-
- /* Check if the header provided an image size */
- if (bmi->bmiHeader.biSizeImage != 0)
- {
- /* Use the given size */
- cjSizeImage = bmi->bmiHeader.biSizeImage;
- }
- /* Otherwise check for uncompressed formats */
- else if ((bmi->bmiHeader.biCompression == BI_RGB) ||
+ BOOL bCompressed;
+
+ if (!bmi || !Bits) return 0;
+
+ /* Check for uncompressed formats */
+ if ((bmi->bmiHeader.biCompression == BI_RGB) ||
(bmi->bmiHeader.biCompression == BI_BITFIELDS))
{
/* Calculate the image size */
cjSizeImage = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth,
ScanLines,
bmi->bmiHeader.biBitCount);
+ bCompressed = FALSE;
+ }
+ /* Check if the header provided an image size */
+ else if (bmi->bmiHeader.biSizeImage != 0)
+ {
+ /* Use the given size */
+ cjSizeImage = bmi->bmiHeader.biSizeImage;
+ bCompressed = TRUE;
}
else
{
@@ -293,6 +296,8 @@
return 0;
}
+ /* We cannot use the provided buffer for uncompressed bits, since they
+ might not be aligned correctly! */
SourceBitmap = GreCreateBitmapEx(bmi->bmiHeader.biWidth,
ScanLines,
0,
@@ -300,7 +305,7 @@
bmi->bmiHeader.biCompression),
bmi->bmiHeader.biHeight < 0 ? BMF_TOPDOWN :
0,
cjSizeImage,
- (PVOID)Bits,
+ bCompressed ? (PVOID)Bits : NULL,
0);
if (!SourceBitmap)
{
@@ -316,6 +321,17 @@
{
DPRINT1("Error: Could not lock surfaces\n");
goto cleanup;
+ }
+
+ /* Check for uncompressed bits */
+ if (!bCompressed)
+ {
+ /* Copy the bitmap bits */
+ if (!UnsafeSetBitmapBits(psurfSrc, cjMaxBits, Bits))
+ {
+ DPRINT1("Error: Could not set bitmap bits\n");
+ goto cleanup;
+ }
}
/* Create a palette for the DIB */
@@ -340,8 +356,6 @@
rcDst.right = psurfDst->SurfObj.sizlBitmap.cx;
ptSrc.x = 0;
ptSrc.y = 0;
-
- NT_ASSERT(psurfSrc->SurfObj.cjBits <= cjMaxBits);
result = IntEngCopyBits(&psurfDst->SurfObj,
&psurfSrc->SurfObj,
@@ -1456,6 +1470,11 @@
PBYTE safeBits = NULL;
HBITMAP hbmResult = NULL;
+ if (pjInit == NULL)
+ {
+ fInit &= ~CBM_INIT;
+ }
+
if(pjInit && (fInit & CBM_INIT))
{
if (cjMaxBits == 0) return NULL;