gdiplus: Handle negative stride in GdipCreateBitmapFromScan0.

This commit is contained in:
Vincent Povirk 2009-02-17 14:05:37 -06:00 committed by Alexandre Julliard
parent 4a8e1feeb4
commit 65750fabbb
2 changed files with 18 additions and 13 deletions

View File

@ -496,12 +496,6 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
if(scan0 && !stride)
return InvalidParameter;
/* FIXME: windows allows negative stride (reads backwards from scan0) */
if(stride < 0){
FIXME("negative stride\n");
return InvalidParameter;
}
*bitmap = GdipAlloc(sizeof(GpBitmap));
if(!*bitmap) return OutOfMemory;
@ -527,16 +521,29 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = -height;
/* FIXME: use the rest of the data from format */
bmih->biBitCount = PIXELFORMATBPP(format);
bmih->biCompression = BI_RGB;
bmih->biSizeImage = datalen;
if(scan0)
memcpy(bmih + 1, scan0, datalen);
if (scan0)
{
if (stride > 0)
{
bmih->biHeight = -height;
memcpy(bmih + 1, scan0, datalen);
}
else
{
bmih->biHeight = height;
memcpy(bmih + 1, scan0 + stride * (height - 1), datalen);
}
}
else
{
bmih->biHeight = height;
memset(bmih + 1, 0, datalen);
}
if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
ERR("could not make stream\n");

View File

@ -129,10 +129,8 @@ static void test_Scan0(void)
bm = NULL;
stat = GdipCreateBitmapFromScan0(10, 10, -8, PixelFormat24bppRGB, buff, &bm);
todo_wine{
expect(Ok, stat);
ok(NULL != bm, "Expected bitmap to be initialized\n");
}
expect(Ok, stat);
ok(NULL != bm, "Expected bitmap to be initialized\n");
if (stat == Ok)
GdipDisposeImage((GpImage*)bm);