[PATCH 6/6] GDI+: Implemented GdipSaveImageToFile.
Nathan Beckmann
nathan.beckmann at gmail.com
Sun Feb 24 09:57:19 CST 2008
Tested by converting a JPG image to a BMP using
ConvertImage.exe. (Currently, BMP is only format supported for bitmap
encoding.)
Simple tests included.
---
dlls/gdiplus/gdiplus.spec | 2 +-
dlls/gdiplus/image.c | 32 ++++++++++++++++++++++++++++++++
dlls/gdiplus/tests/image.c | 24 ++++++++++++++++++++++++
3 files changed, 57 insertions(+), 1 deletions(-)
diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 5a7c714..5f31cd4 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -494,7 +494,7 @@
@ stub GdipSaveAdd
@ stub GdipSaveAddImage
@ stdcall GdipSaveGraphics(ptr ptr)
-@ stub GdipSaveImageToFile
+@ stdcall GdipSaveImageToFile(ptr ptr ptr ptr)
@ stdcall GdipSaveImageToStream(ptr ptr ptr ptr)
@ stub GdipScaleLineTransform
@ stdcall GdipScaleMatrix(ptr long long long)
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index 0ec1587..8744f45 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -805,6 +805,38 @@ GpStatus WINGDIPAPI GdipRemovePropertyItem(GpImage *image, PROPID propId)
return NotImplemented;
}
+GpStatus WINGDIPAPI GdipSaveImageToFile(GpImage *image, GDIPCONST WCHAR* filename,
+ GDIPCONST CLSID *clsidEncoder,
+ GDIPCONST EncoderParameters *encoderParams)
+{
+ IPictureDisp *disp = NULL;
+ GpStatus stat;
+
+ if (!image || !filename|| !clsidEncoder)
+ return InvalidParameter;
+
+ if (!(image->picture))
+ return InvalidParameter;
+
+ /* This is a hack. I just use the file name to let
+ OleSavePictureFile discover which type to encode.
+
+ The CLSID will probably be valid from when they queried the
+ encoders, but we rely exclusively on the saved file name. See
+ encoder querying functions.
+ */
+
+ stat = hresult_to_status(IPictureDisp_QueryInterface(image->picture, &IID_IPictureDisp, (PVOID)&disp));
+
+ if (stat != Ok) {
+ return GenericError;
+ }
+
+ OleSavePictureFile((IDispatch*)disp, (BSTR)filename);
+ IPictureDisp_Release((IDispatch*)disp);
+ return Ok;
+}
+
GpStatus WINGDIPAPI GdipSaveImageToStream(GpImage *image, IStream* stream,
GDIPCONST CLSID* clsid, GDIPCONST EncoderParameters* params)
{
diff --git a/dlls/gdiplus/tests/image.c b/dlls/gdiplus/tests/image.c
index 0161530..af8ba78 100644
--- a/dlls/gdiplus/tests/image.c
+++ b/dlls/gdiplus/tests/image.c
@@ -122,6 +122,29 @@ void test_LoadingImages()
expect(InvalidParameter, stat);
}
+void test_SavingImages()
+{
+ GpStatus stat;
+ GpBitmap *bm;
+ static const WCHAR filename[] = { 'a','.','b','m','p',0 };
+
+ stat = GdipSaveImageToFile(0, 0, 0, 0);
+ expect(InvalidParameter, stat);
+
+ bm = NULL;
+ stat = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bm);
+ expect(Ok, stat);
+ if (bm) {
+ stat = GdipSaveImageToFile((GpImage*)bm, 0, 0, 0);
+ expect(InvalidParameter, stat);
+
+ stat = GdipSaveImageToFile((GpImage*)bm, filename, 0, 0);
+ expect(InvalidParameter, stat);
+
+ GdipDisposeImage((GpImage*)bm);
+ }
+}
+
void test_encoders()
{
GpStatus stat;
@@ -189,6 +212,7 @@ START_TEST(image)
test_Scan0();
test_GetImageDimension();
test_LoadingImages();
+ test_SavingImages();
test_encoders();
GdiplusShutdown(gdiplusToken);
--
1.5.4.2
More information about the wine-patches
mailing list