From 84d260ec60605c0eb1a938b33cc3e8c282740372 Mon Sep 17 00:00:00 2001 From: Jon Yang Date: Wed, 27 Feb 2008 01:36:44 -0800 Subject: [PATCH] gdiplus: Implemented and tested GdipGetImageDimension(). --- dlls/gdiplus/gdiplus.spec | 2 +- dlls/gdiplus/image.c | 31 +++++++++++++++++++++++++++++++ dlls/gdiplus/tests/image.c | 33 +++++++++++++++++++++++++++++++++ include/gdiplusflat.h | 1 + 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec index 55fabe4e3f1..a2d3183e118 100644 --- a/dlls/gdiplus/gdiplus.spec +++ b/dlls/gdiplus/gdiplus.spec @@ -283,7 +283,7 @@ @ stdcall GdipGetImageBounds(ptr ptr ptr) @ stub GdipGetImageDecoders @ stub GdipGetImageDecodersSize -@ stub GdipGetImageDimension +@ stdcall GdipGetImageDimension(ptr ptr ptr) @ stub GdipGetImageEncoders @ stub GdipGetImageEncodersSize @ stub GdipGetImageFlags diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index b08c5e50b4b..0fe7dfe645f 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -463,6 +463,37 @@ GpStatus WINGDIPAPI GdipGetImageBounds(GpImage *image, GpRectF *srcRect, return Ok; } +GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width, + REAL *height) +{ + if(!image || !height || !width) + return InvalidParameter; + + if(image->type == ImageTypeMetafile){ + HDC hdc = GetDC(0); + + *height = convert_unit(hdc, ((GpMetafile*)image)->unit) * + ((GpMetafile*)image)->bounds.Height; + + *width = convert_unit(hdc, ((GpMetafile*)image)->unit) * + ((GpMetafile*)image)->bounds.Width; + + ReleaseDC(0, hdc); + } + + else if(image->type == ImageTypeBitmap){ + *height = ((GpBitmap*)image)->height; + *width = ((GpBitmap*)image)->width; + } + else{ + *height = ipicture_pixel_height(image->picture); + *width = ipicture_pixel_width(image->picture); + } + + TRACE("returning (%f, %f)\n", *height, *width); + return Ok; +} + GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image, GpGraphics **graphics) { diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c index 03649622564..d0959e52508 100644 --- a/dlls/gdiplus/tests/image.c +++ b/dlls/gdiplus/tests/image.c @@ -21,6 +21,7 @@ #include "windows.h" #include "gdiplus.h" #include "wine/test.h" +#include #define expect(expected, got) ok(((UINT)got) == ((UINT)expected), "Expected %.8x, got %.8x\n", (UINT)expected, (UINT)got) @@ -73,6 +74,37 @@ static void test_Scan0(void) expect(0xdeadbeef, bm); } +static void test_GetImageDimension(void) +{ + GpBitmap *bm; + GpStatus stat; + const REAL WIDTH = 10.0, HEIGHT = 20.0; + REAL w,h; + + bm = (GpBitmap*)0xdeadbeef; + stat = GdipCreateBitmapFromScan0(WIDTH, HEIGHT, 0, PixelFormat24bppRGB,NULL, &bm); + expect(Ok,stat); + ok((GpBitmap*)0xdeadbeef != bm, "Expected bitmap to not be 0xdeadbeef\n"); + ok(NULL != bm, "Expected bitmap to not be NULL\n"); + + stat = GdipGetImageDimension(NULL,&w,&h); + expect(InvalidParameter, stat); + + stat = GdipGetImageDimension((GpImage*)bm,NULL,&h); + expect(InvalidParameter, stat); + + stat = GdipGetImageDimension((GpImage*)bm,&w,NULL); + expect(InvalidParameter, stat); + + w = -1; + h = -1; + stat = GdipGetImageDimension((GpImage*)bm,&w,&h); + expect(Ok, stat); + ok(fabs(WIDTH - w) < 0.0001, "Width wrong"); + ok(fabs(HEIGHT - h) < 0.0001, "Height wrong"); + GdipDisposeImage((GpImage*)bm); +} + START_TEST(image) { struct GdiplusStartupInput gdiplusStartupInput; @@ -86,6 +118,7 @@ START_TEST(image) GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); test_Scan0(); + test_GetImageDimension(); GdiplusShutdown(gdiplusToken); } diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h index caf35326670..1f635ba348a 100644 --- a/include/gdiplusflat.h +++ b/include/gdiplusflat.h @@ -114,6 +114,7 @@ GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics*,GpBrush*,REAL,REAL,REAL,REAL); GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics*,GpBrush*,INT,INT,INT,INT); GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics*,CompositingMode*); GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics*,CompositingQuality*); +GpStatus WINGDIPAPI GdipGetImageDimension(GpImage*,REAL*,REAL*); GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics*,InterpolationMode*); GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics*,REAL*); GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics*,GpUnit*);