Commit 3266420a authored by Sean Huckins's avatar Sean Huckins Committed by Alexandre Julliard

gdiplus: Implementation of GdipCreateBitmapFromHBITMAP.

parent e7498257
......@@ -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)
......
......@@ -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;
}
......@@ -3,7 +3,7 @@ TOPOBJDIR = ../../..
SRCDIR = @srcdir@
VPATH = @srcdir@
TESTDLL = gdiplus.dll
IMPORTS = gdiplus user32 kernel32
IMPORTS = gdiplus user32 gdi32 kernel32
CTESTS = \
brush.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);
}
......@@ -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**);
......
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