Evan Stade : gdiplus: Added GdipGetImagePixelFormat.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Aug 6 08:03:39 CDT 2007


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

Author: Evan Stade <estade at gmail.com>
Date:   Fri Aug  3 17:30:30 2007 -0700

gdiplus: Added GdipGetImagePixelFormat.

---

 dlls/gdiplus/gdiplus.spec      |    2 +-
 dlls/gdiplus/gdiplus_private.h |    1 +
 dlls/gdiplus/image.c           |   57 ++++++++++++++++++++++++++++++---------
 include/gdiplusflat.h          |    1 +
 include/gdipluspixelformats.h  |   26 ++++++++++++++++++
 5 files changed, 73 insertions(+), 14 deletions(-)

diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 3d79760..e8802ab 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -293,7 +293,7 @@
 @ stub GdipGetImageItemData
 @ stub GdipGetImagePalette
 @ stub GdipGetImagePaletteSize
-@ stub GdipGetImagePixelFormat
+@ stdcall GdipGetImagePixelFormat(ptr ptr)
 @ stdcall GdipGetImageRawFormat(ptr ptr)
 @ stub GdipGetImageThumbnail
 @ stdcall GdipGetImageType(ptr ptr)
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index 02db7aa..cea667f 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -142,6 +142,7 @@ struct GpBitmap{
     GpImage image;
     INT width;
     INT height;
+    PixelFormat format;
 };
 
 struct GpImageAttributes{
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index 6b71014..a52b9ca 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -36,6 +36,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
 
 typedef void ImageItemData;
 
+#define PIXELFORMATBPP(x) ((x) ? ((x) >> 8) & 255 : 24)
+
 static INT ipicture_pixel_height(IPicture *pic)
 {
     HDC hdcref;
@@ -121,7 +123,7 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
     bmih->biWidth           = width;
     bmih->biHeight          = height;
     /* FIXME: use the rest of the data from format */
-    bmih->biBitCount        = format >> 8;
+    bmih->biBitCount        = PIXELFORMATBPP(format);
     bmih->biCompression     = BI_RGB;
 
     memcpy(bmih + 1, scan0, datalen);
@@ -145,6 +147,7 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
     (*bitmap)->image.type = ImageTypeBitmap;
     (*bitmap)->width = width;
     (*bitmap)->height = height;
+    (*bitmap)->format = format;
 
     return Ok;
 }
@@ -152,6 +155,10 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromScan0(INT width, INT height, INT stride,
 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
     GpBitmap **bitmap)
 {
+    BITMAPINFO bmi;
+    BITMAPCOREHEADER* bmch;
+    OLE_HANDLE hbm;
+    HDC hdc;
     GpStatus stat;
 
     stat = GdipLoadImageFromStream(stream, (GpImage**) bitmap);
@@ -164,24 +171,34 @@ GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream* stream,
     (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
     (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
 
+    /* get the pixel format */
+    IPicture_get_Handle((*bitmap)->image.picture, &hbm);
+    IPicture_get_CurDC((*bitmap)->image.picture, &hdc);
+
+    bmch = (BITMAPCOREHEADER*) (&bmi.bmiHeader);
+    bmch->bcSize = sizeof(BITMAPCOREHEADER);
+
+    if(!hdc){
+        HBITMAP old;
+        hdc = GetDC(0);
+        old = SelectObject(hdc, (HBITMAP)hbm);
+        GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
+        SelectObject(hdc, old);
+        ReleaseDC(0, hdc);
+    }
+    else
+        GetDIBits(hdc, (HBITMAP)hbm, 0, 0, NULL, &bmi, DIB_RGB_COLORS);
+
+    (*bitmap)->format = (bmch->bcBitCount << 8) | PixelFormatGDI;
+
     return Ok;
 }
 
+/* FIXME: no icm */
 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream* stream,
     GpBitmap **bitmap)
 {
-    GpStatus stat;
-
-    stat = GdipLoadImageFromStreamICM(stream, (GpImage**) bitmap);
-
-    if(stat != Ok)
-        return stat;
-
-    (*bitmap)->image.type = ImageTypeBitmap;
-    (*bitmap)->width = ipicture_pixel_width((*bitmap)->image.picture);
-    (*bitmap)->height = ipicture_pixel_height((*bitmap)->image.picture);
-
-    return Ok;
+    return GdipCreateBitmapFromStream(stream, bitmap);
 }
 
 GpStatus WINGDIPAPI GdipDisposeImage(GpImage *image)
@@ -263,6 +280,20 @@ GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage *image, REAL *res)
     return NotImplemented;
 }
 
+/* FIXME: test this function for non-bitmap types */
+GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage *image, PixelFormat *format)
+{
+    if(!image || !format)
+        return InvalidParameter;
+
+    if(image->type != ImageTypeBitmap)
+        *format = PixelFormat24bppRGB;
+    else
+        *format = ((GpBitmap*) image)->format;
+
+    return Ok;
+}
+
 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage *image, GUID *format)
 {
     static int calls;
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index 7e94a68..bb8855e 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -172,6 +172,7 @@ GpStatus WINGDIPAPI GdipDisposeImage(GpImage*);
 GpStatus WINGDIPAPI GdipGetImageBounds(GpImage*,GpRectF*,GpUnit*);
 GpStatus WINGDIPAPI GdipGetImageHeight(GpImage*,UINT*);
 GpStatus WINGDIPAPI GdipGetImageHorizontalResolution(GpImage*,REAL*);
+GpStatus WINGDIPAPI GdipGetImagePixelFormat(GpImage*,PixelFormat*);
 GpStatus WINGDIPAPI GdipGetImageRawFormat(GpImage*,GUID*);
 GpStatus WINGDIPAPI GdipGetImageType(GpImage*,ImageType*);
 GpStatus WINGDIPAPI GdipGetImageVerticalResolution(GpImage*,REAL*);
diff --git a/include/gdipluspixelformats.h b/include/gdipluspixelformats.h
index 6f50492..dd67410 100644
--- a/include/gdipluspixelformats.h
+++ b/include/gdipluspixelformats.h
@@ -22,4 +22,30 @@
 typedef DWORD ARGB;
 typedef INT PixelFormat;
 
+#define    PixelFormatIndexed   0x00010000
+#define    PixelFormatGDI       0x00020000
+#define    PixelFormatAlpha     0x00040000
+#define    PixelFormatPAlpha    0x00080000
+#define    PixelFormatExtended  0x00100000
+#define    PixelFormatCanonical 0x00200000
+
+#define    PixelFormatUndefined 0
+#define    PixelFormatDontCare  0
+
+#define    PixelFormat1bppIndexed       (1 | ( 1 << 8) | PixelFormatIndexed | PixelFormatGDI)
+#define    PixelFormat4bppIndexed       (2 | ( 4 << 8) | PixelFormatIndexed | PixelFormatGDI)
+#define    PixelFormat8bppIndexed       (3 | ( 8 << 8) | PixelFormatIndexed | PixelFormatGDI)
+#define    PixelFormat16bppGrayScale    (4 | (16 << 8) | PixelFormatExtended)
+#define    PixelFormat16bppRGB555       (5 | (16 << 8) | PixelFormatGDI)
+#define    PixelFormat16bppRGB565       (6 | (16 << 8) | PixelFormatGDI)
+#define    PixelFormat16bppARGB1555     (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI)
+#define    PixelFormat24bppRGB          (8 | (24 << 8) | PixelFormatGDI)
+#define    PixelFormat32bppRGB          (9 | (32 << 8) | PixelFormatGDI)
+#define    PixelFormat32bppARGB         (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical)
+#define    PixelFormat32bppPARGB        (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI)
+#define    PixelFormat48bppRGB          (12 | (48 << 8) | PixelFormatExtended)
+#define    PixelFormat64bppARGB         (13 | (64 << 8) | PixelFormatAlpha  | PixelFormatCanonical | PixelFormatExtended)
+#define    PixelFormat64bppPARGB        (14 | (64 << 8) | PixelFormatAlpha  | PixelFormatPAlpha | PixelFormatExtended)
+#define    PixelFormatMax               15
+
 #endif




More information about the wine-cvs mailing list