gdiplus: Fixed conformance of GdipCreateBitmapFromScan0.

This commit is contained in:
Evan Stade 2007-08-08 19:42:24 -07:00 committed by Alexandre Julliard
parent cae277f13e
commit a41fa500f4
2 changed files with 37 additions and 22 deletions

View file

@ -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;
memcpy(bmih + 1, scan0, 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");

View file

@ -32,29 +32,27 @@ 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");
}
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);
expect(NULL, bm);
bm = (GpBitmap*)0xdeadbeef;
stat = GdipCreateBitmapFromScan0(-10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
expect(InvalidParameter, stat);
todo_wine
expect(NULL, bm);
expect(NULL, bm);
bm = (GpBitmap*)0xdeadbeef;
stat = GdipCreateBitmapFromScan0(10, 0, 10, PixelFormat24bppRGB, NULL, &bm);
expect(InvalidParameter, stat);
todo_wine
expect(NULL, bm);
expect(NULL, bm);
bm = NULL;
stat = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, buff, &bm);
@ -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);
}
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);
}
expect(InvalidParameter, stat);
expect(0xdeadbeef, bm);
}
START_TEST(image)