Vincent Povirk : gdiplus: Implement GdipCreateHBITMAPFromBitmap.

Alexandre Julliard julliard at winehq.org
Fri Aug 28 10:18:40 CDT 2009


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

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Thu Aug 27 16:58:11 2009 -0500

gdiplus: Implement GdipCreateHBITMAPFromBitmap.

---

 dlls/gdiplus/image.c       |   64 +++++++++++++++++++++++++++++++++++++++++--
 dlls/gdiplus/tests/image.c |    6 ++--
 2 files changed, 64 insertions(+), 6 deletions(-)

diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index 7fb76b0..e65182f 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -447,11 +447,69 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromResource(HINSTANCE hInstance,
 GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap,
     HBITMAP* hbmReturn, ARGB background)
 {
-    FIXME("stub\n");
+    GpStatus stat;
+    HBITMAP result, oldbitmap;
+    UINT width, height;
+    HDC hdc;
+    GpGraphics *graphics;
+    BITMAPINFOHEADER bih;
+    void *bits;
+    TRACE("(%p,%p,%x)\n", bitmap, hbmReturn, background);
+
+    if (!bitmap || !hbmReturn) return InvalidParameter;
+
+    GdipGetImageWidth((GpImage*)bitmap, &width);
+    GdipGetImageHeight((GpImage*)bitmap, &height);
+
+    bih.biSize = sizeof(bih);
+    bih.biWidth = width;
+    bih.biHeight = height;
+    bih.biPlanes = 1;
+    bih.biBitCount = 32;
+    bih.biCompression = BI_RGB;
+    bih.biSizeImage = 0;
+    bih.biXPelsPerMeter = 0;
+    bih.biYPelsPerMeter = 0;
+    bih.biClrUsed = 0;
+    bih.biClrImportant = 0;
+
+    hdc = CreateCompatibleDC(NULL);
+    if (!hdc) return GenericError;
+
+    result = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS, &bits,
+        NULL, 0);
+
+    if (result)
+    {
+        oldbitmap = SelectObject(hdc, result);
+
+        stat = GdipCreateFromHDC(hdc, &graphics);
+        if (stat == Ok)
+        {
+            stat = GdipGraphicsClear(graphics, background);
 
-    if (hbmReturn) *hbmReturn = NULL;
+            if (stat == Ok)
+                stat = GdipDrawImage(graphics, (GpImage*)bitmap, 0, 0);
 
-    return NotImplemented;
+            GdipDeleteGraphics(graphics);
+        }
+
+        SelectObject(hdc, oldbitmap);
+    }
+    else
+        stat = GenericError;
+
+    DeleteDC(hdc);
+
+    if (stat != Ok && result)
+    {
+        DeleteObject(result);
+        result = NULL;
+    }
+
+    *hbmReturn = result;
+
+    return stat;
 }
 
 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics* ref,
diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c
index d566c36..e624e53 100644
--- a/dlls/gdiplus/tests/image.c
+++ b/dlls/gdiplus/tests/image.c
@@ -760,14 +760,14 @@ static void test_createhbitmap(void)
 
     /* test NULL values */
     stat = GdipCreateHBITMAPFromBitmap(NULL, &hbitmap, 0);
-    todo_wine expect(InvalidParameter, stat);
+    expect(InvalidParameter, stat);
 
     stat = GdipCreateHBITMAPFromBitmap(bitmap, NULL, 0);
-    todo_wine expect(InvalidParameter, stat);
+    expect(InvalidParameter, stat);
 
     /* create HBITMAP */
     stat = GdipCreateHBITMAPFromBitmap(bitmap, &hbitmap, 0);
-    todo_wine expect(Ok, stat);
+    expect(Ok, stat);
 
     if (stat == Ok)
     {




More information about the wine-cvs mailing list