Commit a41fa500 authored by Evan Stade's avatar Evan Stade Committed by Alexandre Julliard

gdiplus: Fixed conformance of GdipCreateBitmapFromScan0.

parent cae277f1
......@@ -257,17 +257,34 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
BITMAPFILEHEADER *bmfh;
BITMAPINFOHEADER *bmih;
BYTE *buff;
INT datalen = stride * height, size;
INT datalen, size;
IStream *stream;
TRACE("%d %d %d %d %p %p\n", width, height, stride, format, scan0, bitmap);
if(!scan0 || !bitmap)
if(!bitmap || width <= 0 || height <= 0 || (scan0 && (stride % 4))){
*bitmap = NULL;
return InvalidParameter;
}
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;
if(stride == 0){
stride = width * (PIXELFORMATBPP(format) / 8);
stride = (stride + 3) & ~3;
}
datalen = abs(stride * height);
size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + datalen;
buff = GdipAlloc(size);
if(!buff){
......@@ -284,12 +301,16 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = height;
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);
else
memset(bmih + 1, 0, datalen);
if(CreateStreamOnHGlobal(buff, TRUE, &stream) != S_OK){
ERR("could not make stream\n");
......
......@@ -32,28 +32,26 @@ static void test_Scan0()
bm = NULL;
stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
todo_wine{
expect(Ok, stat);
ok(NULL != bm, "Expected bitmap to be initialized\n");
}
GdipDisposeImage((GpImage*)bm);
bm = (GpBitmap*)0xdeadbeef;
stat = GdipCreateBitmapFromScan0(10, -10, 10, PixelFormat24bppRGB, NULL, &bm);
expect(InvalidParameter, stat);
todo_wine
expect(NULL, bm);
bm = (GpBitmap*)0xdeadbeef;
stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
expect(InvalidParameter, stat);
todo_wine
expect(NULL, bm);
bm = (GpBitmap*)0xdeadbeef;
stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
expect(InvalidParameter, stat);
todo_wine
expect(NULL, bm);
bm = NULL;
......@@ -64,17 +62,13 @@ static void test_Scan0()
bm = (GpBitmap*) 0xdeadbeef;
stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, buff, &bm);
todo_wine{
expect(InvalidParameter, stat);
expect(NULL, bm);
}
bm = (GpBitmap*)0xdeadbeef;
stat = GdipCreateBitmapFromScan0(10, 10, 0, PixelFormat24bppRGB, buff, &bm);
todo_wine{
expect(InvalidParameter, stat);
expect(0xdeadbeef, bm);
}
}
START_TEST(image)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment