[WIN32SS][NTGDI] Fix UnsafeSetBitmapBits (#1310)

CORE-15657
This commit is contained in:
Katayama Hirofumi MZ 2019-01-27 15:32:52 +09:00 committed by GitHub
parent 53abbb06b5
commit 0aa21c3366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 19 deletions

View File

@ -3,7 +3,8 @@
* PROJECT: ReactOS kernel
* PURPOSE: Bitmap functions
* FILE: win32ss/gdi/ntgdi/bitmaps.c
* PROGRAMER: Timo Kreuzer <timo.kreuzer@reactos.org>
* PROGRAMERS: Timo Kreuzer <timo.kreuzer@reactos.org>
* Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#include <win32k.h>
@ -42,7 +43,7 @@ GreSetBitmapOwner(
return GreSetObjectOwner(hbmp, ulOwner);
}
BOOL
LONG
NTAPI
UnsafeSetBitmapBits(
_Inout_ PSURFACE psurf,
@ -52,34 +53,46 @@ UnsafeSetBitmapBits(
PUCHAR pjDst;
const UCHAR *pjSrc;
LONG lDeltaDst, lDeltaSrc;
ULONG nWidth, nHeight, cBitsPixel;
ULONG Y, iSrc, iDst, cbSrc, cbDst, nWidth, nHeight, cBitsPixel;
NT_ASSERT(psurf->flags & API_BITMAP);
NT_ASSERT(psurf->SurfObj.iBitmapFormat <= BMF_32BPP);
nWidth = psurf->SurfObj.sizlBitmap.cx;
nHeight = psurf->SurfObj.sizlBitmap.cy;
nHeight = labs(psurf->SurfObj.sizlBitmap.cy);
cBitsPixel = BitsPerFormat(psurf->SurfObj.iBitmapFormat);
/* Get pointers */
pjDst = psurf->SurfObj.pvScan0;
pjSrc = pvBits;
lDeltaDst = psurf->SurfObj.lDelta;
lDeltaSrc = WIDTH_BYTES_ALIGN16(nWidth, cBitsPixel);
NT_ASSERT(lDeltaSrc <= abs(lDeltaDst));
NT_ASSERT(lDeltaSrc <= labs(lDeltaDst));
/* Make sure the buffer is large enough*/
if (cjBits < (lDeltaSrc * nHeight))
return FALSE;
cbDst = labs(lDeltaDst) * nHeight;
cbSrc = lDeltaSrc * nHeight;
cjBits = min(cjBits, cbSrc);
while (nHeight--)
iSrc = iDst = 0;
for (Y = 0; Y < nHeight; Y++)
{
if (iSrc + lDeltaSrc > cjBits || iDst + labs(lDeltaDst) > cbDst)
{
LONG lDelta = min(cjBits - iSrc, cbDst - iDst);
NT_ASSERT(lDelta >= 0);
RtlCopyMemory(pjDst, pjSrc, lDelta);
iSrc += lDelta;
break;
}
/* Copy one line */
memcpy(pjDst, pjSrc, lDeltaSrc);
RtlCopyMemory(pjDst, pjSrc, lDeltaSrc);
pjSrc += lDeltaSrc;
pjDst += lDeltaDst;
iSrc += lDeltaSrc;
iDst += labs(lDeltaDst);
}
return TRUE;
return iSrc;
}
HBITMAP

View File

@ -44,13 +44,6 @@ GreCreateDIBitmapInternal(
IN UINT cjMaxBits,
IN HANDLE hcmXform);
BOOL
NTAPI
UnsafeSetBitmapBits(
_Inout_ PSURFACE psurf,
_In_ ULONG cjBits,
_In_ const VOID *pvBits);
BOOL
NTAPI
GreGetBitmapDimension(