Sean Huckins : gdiplus: Implementation of GdipCreateBitmapFromHBITMAP.

Alexandre Julliard julliard at winehq.org
Mon Mar 24 07:54:58 CDT 2008


Module: wine
Branch: master
Commit: 3266420a1e39ddd7f7b1fd3db5b6f6e416936846
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3266420a1e39ddd7f7b1fd3db5b6f6e416936846

Author: Sean Huckins <bhuckins at ucla.edu>
Date:   Fri Mar 21 16:39:22 2008 -0700

gdiplus: Implementation of GdipCreateBitmapFromHBITMAP.

---

 dlls/gdiplus/gdiplus.spec      |    2 +-
 dlls/gdiplus/image.c           |   46 ++++++++++++++++++++++
 dlls/gdiplus/tests/Makefile.in |    2 +-
 dlls/gdiplus/tests/image.c     |   83 ++++++++++++++++++++++++++++++++++++++++
 include/gdiplusflat.h          |    1 +
 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 numEncoders, UINT size, ImageCodec
 
     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) != sizeof(bm))
+            return InvalidParameter;
+
+    /* TODO: Figure out the correct format for 16, 32, 64 bpp */
+    switch(bm.bmBitsPixel) {
+        case 1:
+            format = PixelFormat1bppIndexed;
+            break;
+        case 4:
+            format = PixelFormat4bppIndexed;
+            break;
+        case 8:
+            format = PixelFormat8bppIndexed;
+            break;
+        case 24:
+            format = PixelFormat24bppRGB;
+            break;
+        case 48:
+            format = PixelFormat48bppRGB;
+            break;
+        default:
+            FIXME("don't know how to handle %d bpp\n", bm.bmBitsPixel);
+            return InvalidParameter;
+            break;
+    }
+
+    retval = GdipCreateBitmapFromScan0(bm.bmWidth, bm.bmHeight, bm.bmWidthBytes,
+        format, bm.bmBits, bitmap);
+
+    return retval;
+}
diff --git a/dlls/gdiplus/tests/Makefile.in b/dlls/gdiplus/tests/Makefile.in
index 3102f17..28b2959 100644
--- a/dlls/gdiplus/tests/Makefile.in
+++ b/dlls/gdiplus/tests/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = gdiplus.dll
-IMPORTS   = gdiplus user32 kernel32
+IMPORTS   = gdiplus user32 gdi32 kernel32
 
 CTESTS = \
 	brush.c \
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"
 
 #define expect(expected, got) ok(((UINT)got) == ((UINT)expected), "Expected %.8x, got %.8x\n", (UINT)expected, (UINT)got)
 
@@ -335,6 +336,87 @@ static void test_LockBits(void)
     expect(Ok, stat);
 }
 
+static void test_GdipCreateBitmapFromHBITMAP(void)
+{
+    GpBitmap* gpbm = NULL;
+    HBITMAP hbm = NULL;
+    HPALETTE hpal = NULL;
+    GpStatus stat;
+    BYTE buff[1000];
+    LOGPALETTE* LogPal = NULL;
+    REAL width, height;
+    const REAL WIDTH1 = 5;
+    const REAL HEIGHT1 = 15;
+    const REAL WIDTH2 = 10;
+    const REAL HEIGHT2 = 20;
+    HDC hdc;
+    BITMAPINFO bmi;
+
+    stat = GdipCreateBitmapFromHBITMAP(NULL, NULL, NULL);
+    expect(InvalidParameter, stat);
+
+    hbm = CreateBitmap(WIDTH1, HEIGHT1, 1, 1, NULL);
+    stat = GdipCreateBitmapFromHBITMAP(hbm, NULL, NULL);
+    expect(InvalidParameter, stat);
+
+    stat = 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 == Ok)
+        GdipDisposeImage((GpImage*)gpbm);
+    GlobalFree(hbm);
+
+    hbm = CreateBitmap(WIDTH2, HEIGHT2, 1, 1, &buff);
+    stat = 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 == Ok)
+        GdipDisposeImage((GpImage*)gpbm);
+    GlobalFree(hbm);
+
+    hdc = CreateCompatibleDC(0);
+    ok(hdc != NULL, "CreateCompatibleDC failed\n");
+    bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
+    bmi.bmiHeader.biHeight = HEIGHT1;
+    bmi.bmiHeader.biWidth = WIDTH1;
+    bmi.bmiHeader.biBitCount = 24;
+    bmi.bmiHeader.biPlanes = 1;
+    bmi.bmiHeader.biCompression = BI_RGB;
+
+    hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
+    ok(hbm != NULL, "CreateDIBSection failed\n");
+
+    stat = 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 == Ok)
+        GdipDisposeImage((GpImage*)gpbm);
+
+    LogPal = GdipAlloc(sizeof(LOGPALETTE));
+    ok(LogPal != NULL, "unable to allocate LOGPALETTE\n");
+    LogPal->palVersion = 0x300;
+    hpal = CreatePalette((const LOGPALETTE*) LogPal);
+    ok(hpal != NULL, "CreatePalette failed\n");
+    GdipFree(LogPal);
+
+    stat = GdipCreateBitmapFromHBITMAP(hbm, hpal, &gpbm);
+    todo_wine
+    {
+        expect(Ok, stat);
+    }
+    if (stat == 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();
 
     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*,ImageItemData*);
 GpStatus WINGDIPAPI GdipFindNextImageItem(GpImage*,ImageItemData*);
 GpStatus WINGDIPAPI GdipGetImageEncodersSize(UINT *numEncoders, UINT *size);
 GpStatus WINGDIPAPI GdipGetImageEncoders(UINT numEncoders, UINT size, ImageCodecInfo *encoders);
+GpStatus WINGDIPAPI GdipCreateBitmapFromHBITMAP(HBITMAP, HPALETTE, GpBitmap**);
 GpStatus WINGDIPAPI GdipGetImageItemData(GpImage*,ImageItemData*);
 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage*,GpRectF*,GpUnit*);
 GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage*,GpGraphics**);




More information about the wine-cvs mailing list