[GDI+: 6/7] implemented GdiPlus images

Evan Stade estade at gmail.com
Wed Jun 13 18:41:47 CDT 2007


Hi,

Changelog:
*implemented GdipLoadImageFromFile
*added type defines for GpImage

 dlls/gdiplus/Makefile.in       |    1
 dlls/gdiplus/gdiplus.spec      |    2 -
 dlls/gdiplus/gdiplus_private.h |    5 ++
 dlls/gdiplus/image.c           |  115 ++++++++++++++++++++++++++++++++++++++++
 include/gdiplusflat.h          |    2 +
 include/gdiplusgpstubs.h       |    2 +
 6 files changed, 126 insertions(+), 1 deletions(-)

-Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/Makefile.in b/dlls/gdiplus/Makefile.in
index b2bd0c4..5a2f0ab 100644
--- a/dlls/gdiplus/Makefile.in
+++ b/dlls/gdiplus/Makefile.in
@@ -10,6 +10,7 @@ C_SRCS = \
 	brush.c \
 	gdiplus.c \
 	graphics.c \
+	image.c \
 	pen.c
 
 @MAKE_DLL_RULES@
diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 775bde3..bb78e1d 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -416,7 +416,7 @@
 @ stub GdipIsVisibleRegionPointI
 @ stub GdipIsVisibleRegionRect
 @ stub GdipIsVisibleRegionRectI
-@ stub GdipLoadImageFromFile
+@ stdcall GdipLoadImageFromFile(wstr ptr)
 @ stub GdipLoadImageFromFileICM
 @ stub GdipLoadImageFromStream
 @ stub GdipLoadImageFromStreamICM
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index 6cb2e43..f19bb53 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -49,4 +49,9 @@ struct GpSolidFill{
     GpBrush brush;
 };
 
+struct GpImage{
+    HBITMAP bmp;
+    BITMAPINFO bmi;
+};
+
 #endif
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
new file mode 100644
index 0000000..0595e4c
--- /dev/null
+++ b/dlls/gdiplus/image.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2007 Google (Evan Stade)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "gdiplus.h"
+#include "gdiplus_private.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
+
+/* GdipLoadImage* helper function */
+static GpStatus LoadImageFromBuffer(GpImage* gp_image, BYTE* buff, INT len)
+{
+    BITMAPFILEHEADER bmfh;
+    BITMAPINFO bmi;
+    VOID * loc;
+
+    bmfh.bfType = 0;
+
+    memcpy(&bmfh.bfType, buff, sizeof(BITMAPFILEHEADER));
+    memcpy(&(bmi.bmiHeader), buff + sizeof(BITMAPFILEHEADER),
+        sizeof(BITMAPINFOHEADER));
+
+    TRACE("BITMAPFILEHEADER: %x %x %x %x %x\n", bmfh.bfType, bmfh.bfSize, 
+        bmfh.bfReserved1, bmfh.bfReserved2, bmfh.bfOffBits);
+    TRACE("BITMAPINFOHEADER: %x %x %x %x %x %x %x %x %x %x %x\n", 
+        bmi.bmiHeader.biSize, bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, 
+        bmi.bmiHeader.biPlanes, bmi.bmiHeader.biBitCount,
+        bmi.bmiHeader.biCompression, bmi.bmiHeader.biSizeImage, 
+        bmi.bmiHeader.biXPelsPerMeter,  bmi.bmiHeader.biYPelsPerMeter, 
+        bmi.bmiHeader.biClrUsed, bmi.bmiHeader.biClrImportant);
+
+    if(bmi.bmiHeader.biCompression != 0)
+        FIXME("Non-standard .bmp could fail\n");
+
+    bmi.bmiHeader.biSizeImage = bmfh.bfSize - bmfh.bfOffBits;
+
+    if(len != bmfh.bfSize)
+        return UnknownImageFormat;
+
+    gp_image->bmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, &loc, 
+                                            NULL, 0);
+
+    memcpy(loc, buff + bmfh.bfOffBits, bmi.bmiHeader.biSizeImage);
+    memcpy(&(gp_image->bmi), &bmi, sizeof(BITMAPINFOHEADER));
+
+    return Ok;
+}
+
+GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR* filename, 
+    GpImage **gp_image)
+{
+    HANDLE file = NULL;
+    LARGE_INTEGER size;
+    BYTE* buff;
+    DWORD bytesread;
+    GpStatus stat;
+
+    if(!gp_image)    return InvalidParameter;
+
+    *gp_image = (GpImage*) GdipAlloc(sizeof(GpImage));
+    if(!*gp_image)   return OutOfMemory;
+
+    file = CreateFileW(filename, FILE_READ_DATA, FILE_SHARE_READ, NULL, 
+        OPEN_EXISTING, 0, NULL);
+
+    if(!GetFileSizeEx(file, &size)){
+        stat = FileNotFound;
+        goto err;
+    }
+
+    buff = HeapAlloc(GetProcessHeap(), 0, size.QuadPart);
+
+    if(!ReadFile(file, buff, size.QuadPart, &bytesread, NULL)){
+        stat = FileNotFound;
+        goto err;
+    }
+
+    CloseHandle(file);
+    file = NULL;
+
+    if(bytesread < sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)){
+        stat = UnknownImageFormat;
+        goto err;
+    }
+
+    return LoadImageFromBuffer(*gp_image, buff, bytesread);
+
+err:
+    if(*gp_image)
+        GdipFree(*gp_image);
+    if(file)
+        CloseHandle(file);
+
+    return stat;
+}
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index e5c46b3..bddfa44 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -46,6 +46,8 @@ GpStatus WINGDIPAPI GdipCreateSolidFill(
 GpStatus WINGDIPAPI GdipGetBrushType(GpBrush*,GpBrushType*);
 GpStatus WINGDIPAPI GdipDeleteBrush(GpBrush*);
 
+GpStatus WINGDIPAPI GdipLoadImageFromFile(GDIPCONST WCHAR*,GpImage**);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/gdiplusgpstubs.h b/include/gdiplusgpstubs.h
index 727ca06..58c51ba 100644
--- a/include/gdiplusgpstubs.h
+++ b/include/gdiplusgpstubs.h
@@ -25,6 +25,7 @@ class GpGraphics {};
 class GpGraphics {};
 class GpBrush {};
 class GpSolidFill {};
+class GpImage {};
 
 #else /* end of c++ declarations */
 
@@ -32,6 +33,7 @@ typedef struct GpGraphics GpGraphics;
 typedef struct GpPen GpPen;
 typedef struct GpBrush GpBrush;
 typedef struct GpSolidFill GpSolidFill;
+typedef struct GpImage GpImage;
 
 #endif /* end of c declarations */
 
-- 
1.4.1


More information about the wine-patches mailing list