[PATCH] Support and comformance tests for GdipCreateBitmapFromHBITM=
Sean Huckins
bhuckins at ucla.edu
Fri Mar 21 18:39:22 CDT 2008
AP
---
dlls/gdiplus/gdiplus.spec | 2 +-
dlls/gdiplus/image.c | 46 ++++++++++++++++++++++++
dlls/gdiplus/tests/image.c | 83 +++++++++++++++++++++++++++++++++++++=
+++++++
include/gdiplusflat.h | 1 +
dlls/gdiplus/tests/Makefile.in | 2 +-
5 files changed, 132 insertions(+), 2 deletions(-)
diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 4aac0df..3b3ec41 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -75,7 +75,7 @@
@ stdcall GdipCreateBitmapFromFileICM(wstr ptr)
@ stub GdipCreateBitmapFromGdiDib
@ stdcall GdipCreateBitmapFromGraphics(long long ptr ptr)
-@ stub GdipCreateBitmapFromHBITMAP
+@ stdcall GdipCreateBitmapFromHBITMAP(ptr ptr ptr)
@ stub GdipCreateBitmapFromHICON
@ stub GdipCreateBitmapFromResource
@ stdcall GdipCreateBitmapFromScan0(long long long long ptr ptr)
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index f0cc822..2e5ef56 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -1051,3 +1051,49 @@ GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEnco=
ders, UINT size, ImageCodec
=20
return Ok;
}
+GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP hbm, HPALETTE hpal,=
GpBitmap** bitmap)
+{
+ BITMAP bm;
+ GpStatus retval;
+ PixelFormat format;
+
+ if(!hbm || !bitmap)
+ return InvalidParameter;
+
+ /* TODO: Support for device-dependent bitmaps */
+ if(hpal){
+ FIXME("no support for device-dependent bitmaps\n");
+ return NotImplemented;
+ }
+
+ if (GetObjectA(hbm, sizeof(bm), &bm) !=3D sizeof(bm))
+ return InvalidParameter;
+
+ /* TODO: Figure out the correct format for 16, 32, 64 bpp */
+ switch(bm.bmBitsPixel) {
+ case 1:
+ format =3D PixelFormat1bppIndexed;
+ break;
+ case 4:
+ format =3D PixelFormat4bppIndexed;
+ break;
+ case 8:
+ format =3D PixelFormat8bppIndexed;
+ break;
+ case 24:
+ format =3D PixelFormat24bppRGB;
+ break;
+ case 48:
+ format =3D PixelFormat48bppRGB;
+ break;
+ default:
+ FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
+ return InvalidParameter;
+ break;
+ }
+
+ retval =3D GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidt=
hBytes,
+ format, bm.bmBits, bitmap);
+
+ return retval;
+}
diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c
index 9faa090..dcb86fc 100644
--- a/dlls/gdiplus/tests/image.c
+++ b/dlls/gdiplus/tests/image.c
@@ -22,6 +22,7 @@
#include "gdiplus.h"
#include "wine/test.h"
#include <math.h>
+#include "wingdi.h"
=20
#define expect(expected, got) ok(((UINT)got) =3D=3D ((UINT)expected), "Expe=
cted %.8x, got %.8x\n", (UINT)expected, (UINT)got)
=20
@@ -335,6 +336,87 @@ static void test_LockBits(void)
expect(Ok, stat);
}
=20
+static void test_GdipCreateBitmapFromHBITMAP(void)
+{
+ GpBitmap* gpbm =3D NULL;
+ HBITMAP hbm =3D NULL;
+ HPALETTE hpal =3D NULL;
+ GpStatus stat;
+ BYTE buff[1000];
+ LOGPALETTE* LogPal =3D NULL;
+ REAL width, height;
+ const REAL WIDTH1 =3D 5;
+ const REAL HEIGHT1 =3D 15;
+ const REAL WIDTH2 =3D 10;
+ const REAL HEIGHT2 =3D 20;
+ HDC hdc;
+ BITMAPINFO bmi;
+
+ stat =3D GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
+ expect(InvalidParameter, stat);
+
+ hbm =3D CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
+ stat =3D GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
+ expect(InvalidParameter, stat);
+
+ stat =3D GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
+ expect(Ok, stat);
+ expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
+ ok(fabs(WIDTH1 - width) < .0001, "width wrong\n");
+ ok(fabs(HEIGHT1 - height) < .0001, "height wrong\n");
+ if (stat =3D=3D Ok)
+ GdipDisposeImage((GpImage*)gpbm);
+ GlobalFree(hbm);
+
+ hbm =3D CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
+ stat =3D GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
+ expect(Ok, stat);
+ expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
+ ok(fabs(WIDTH2 - width) < .0001, "width wrong\n");
+ ok(fabs(HEIGHT2 - height) < .0001, "height wrong\n");
+ if (stat =3D=3D Ok)
+ GdipDisposeImage((GpImage*)gpbm);
+ GlobalFree(hbm);
+
+ hdc =3D CreateCompatibleDC(0);
+ ok(hdc !=3D NULL, "CreateCompatibleDC failed\n");
+ bmi.bmiHeader.biSize =3D sizeof(bmi.bmiHeader);
+ bmi.bmiHeader.biHeight =3D HEIGHT1;
+ bmi.bmiHeader.biWidth =3D WIDTH1;
+ bmi.bmiHeader.biBitCount =3D 24;
+ bmi.bmiHeader.biPlanes =3D 1;
+ bmi.bmiHeader.biCompression =3D BI_RGB;
+
+ hbm =3D CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
+ ok(hbm !=3D NULL, "CreateDIBSection failed\n");
+
+ stat =3D GdipCreateBitmapFromHBITMAP(hbm, NULL, &gpbm);
+ expect(Ok, stat);
+ expect(Ok, GdipGetImageDimension((GpImage*) gpbm, &width, &height));
+ ok(fabs(WIDTH1 - width) < .0001, "width wrong\n");
+ ok(fabs(HEIGHT1 - height) < .0001, "height wrong\n");
+ if (stat =3D=3D Ok)
+ GdipDisposeImage((GpImage*)gpbm);
+
+ LogPal =3D GdipAlloc(sizeof(LOGPALETTE));
+ ok(LogPal !=3D NULL, "unable to allocate LOGPALETTE\n");
+ LogPal->palVersion =3D 0x300;
+ hpal =3D CreatePalette((const LOGPALETTE*) LogPal);
+ ok(hpal !=3D NULL, "CreatePalette failed\n");
+ GdipFree(LogPal);
+
+ stat =3D GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
+ todo_wine
+ {
+ expect(Ok, stat);
+ }
+ if (stat =3D=3D Ok)
+ GdipDisposeImage((GpImage*)gpbm);
+
+ GlobalFree(hpal);
+ GlobalFree(hbm);
+}
+
START_TEST(image)
{
struct GdiplusStartupInput gdiplusStartupInput;
@@ -353,6 +435,7 @@ START_TEST(image)
test_SavingImages();
test_encoders();
test_LockBits();
+ test_GdipCreateBitmapFromHBITMAP();
=20
GdiplusShutdown(gdiplusToken);
}
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index fe7bdbb..e92c646 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -261,6 +261,7 @@ GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage*,Imag=
eItemData*);
GpStatus WINGDIPAPI GdipFindNextImageItem(GpImage*,ImageItemData*);
GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size)=
;
GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, Image=
CodecInfo *encoders);
+GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP, HPALETTE, GpBitmap=
**);
GpStatus WINGDIPAPI GdipGetImageItemData(GpImage*,ImageItemData*);
GpStatus WINGDIPAPI GdipGetImageBounds(GpImage*,GpRectF*,GpUnit*);
GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage*,GpGraphics**);
diff --git a/dlls/gdiplus/tests/Makefile.in b/dlls/gdiplus/tests/Makefile.in
index 3102f17..9b768e3 100644
--- a/dlls/gdiplus/tests/Makefile.in
+++ b/dlls/gdiplus/tests/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR =3D ../../..
SRCDIR =3D @srcdir@
VPATH =3D @srcdir@
TESTDLL =3D gdiplus.dll
-IMPORTS =3D gdiplus user32 kernel32
+IMPORTS =3D gdiplus user32 kernel32 gdi32
=20
CTESTS =3D \
=09brush.c \
-- =20
1.5.2.5
--=_70pj61w56qkg--
More information about the wine-patches
mailing list