Author: spouliot
Date: 2007-01-12 09:57:36 -0500 (Fri, 12 Jan 2007)
New Revision: 70920
Modified:
trunk/libgdiplus/src/ChangeLog
trunk/libgdiplus/src/bitmap.c
trunk/libgdiplus/src/gdip.h
Log:
2007-01-12 Sebastien Pouliot <[EMAIL PROTECTED]>
* bitmap.c: Fix HBITMAP support in GdipCreateBitmapFromHBITMAP and
GdipCreateHBITMAPFromBitmap functions so an HBITMAP can survive the
deletion of the GpBitmap structure. Implement GdipCreateBitmapFromHICON
and GdipCreateHICONFromBitmap functions. See comments about freeing
the memory associated with HBITMAP and HICON.
* gdip.h: Add new undocumented ImageFlag to match MS results.
Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog 2007-01-12 14:35:05 UTC (rev 70919)
+++ trunk/libgdiplus/src/ChangeLog 2007-01-12 14:57:36 UTC (rev 70920)
@@ -1,3 +1,12 @@
+2007-01-12 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * bitmap.c: Fix HBITMAP support in GdipCreateBitmapFromHBITMAP and
+ GdipCreateHBITMAPFromBitmap functions so an HBITMAP can survive the
+ deletion of the GpBitmap structure. Implement GdipCreateBitmapFromHICON
+ and GdipCreateHICONFromBitmap functions. See comments about freeing
+ the memory associated with HBITMAP and HICON.
+ * gdip.h: Add new undocumented ImageFlag to match MS results.
+
2007-01-11 Sebastien Pouliot <[EMAIL PROTECTED]>
* bitmap.c: Fix GdipCreateBitmapFromScan0 to initialize the flags to 2
Modified: trunk/libgdiplus/src/bitmap.c
===================================================================
--- trunk/libgdiplus/src/bitmap.c 2007-01-12 14:35:05 UTC (rev 70919)
+++ trunk/libgdiplus/src/bitmap.c 2007-01-12 14:57:36 UTC (rev 70920)
@@ -450,8 +450,10 @@
/* Duplicate palette */
if (src[i].palette != NULL) {
- result[i].palette = GdipAlloc(sizeof(ColorPalette) +
sizeof(ARGB) * src[i].palette->Count);
- memcpy(result[i].palette, src[i].palette,
sizeof(ColorPalette) + sizeof(ARGB) * src[i].palette->Count);
+ /* note: the ColorPalette structure already contains a
(single)ARGB member (so we substract it) */
+ int size = sizeof(ColorPalette) + sizeof(ARGB) *
(src[i].palette->Count - 1);
+ result[i].palette = GdipAlloc (size);
+ memcpy (result[i].palette, src[i].palette, size);
} else {
result[i].palette = NULL;
}
@@ -995,30 +997,65 @@
return OutOfMemory;
}
-/* coverity[+alloc : arg-*2] */
GpStatus
-GdipCreateBitmapFromHBITMAP(void *hbm, void *hpal, GpBitmap** bitmap)
+GdipCreateBitmapFromHBITMAP (void *hbm, void *hpal, GpBitmap** bitmap)
{
- return GdipCloneImage((GpImage *)hbm, (GpImage **)bitmap);
+ if (!bitmap || !hbm)
+ return InvalidParameter;
+
+ *bitmap = hbm;
+ return Ok;
}
GpStatus
-GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, void **hbmReturn, unsigned long
background)
+GdipCreateHBITMAPFromBitmap (GpBitmap* bitmap, void **hbmReturn, unsigned long
background)
{
- *hbmReturn = bitmap;
+ /*
+ * Note: the handle must survive disposing the bitmap. This means that
there's no interoperable way to free this memory.
+ * For libgdiplus you must use GdipDisposeImage on the handle, while on
Windows you should call the DeleteObject function.
+ */
+ GpStatus status = GdipCloneImage ((GpImage *)bitmap,
(GpImage**)hbmReturn);
+ if (status != Ok)
+ return status;
+ ((GpImage*)*hbmReturn)->image_format = MEMBMP;
+ ((GpImage*)*hbmReturn)->active_bitmap->image_flags |=
ImageFlagsUndocumented; /* 0x00040000 */
+ ((GpImage*)*hbmReturn)->active_bitmap->image_flags &=
~ImageFlagsHasAlpha; /* 0x00000002 */
return Ok;
}
GpStatus
-GdipCreateBitmapFromHICON(void *hicon, GpBitmap** bitmap)
+GdipCreateBitmapFromHICON (void *hicon, GpBitmap** bitmap)
{
- return(NotImplemented);
+ GpStatus status;
+
+ if (!hicon || !bitmap)
+ return InvalidParameter;
+
+ status = GdipCloneImage ((GpImage *)hicon, (GpImage**)bitmap);
+ if (status == Ok) {
+ ColorPalette *palette = (ColorPalette*)GdipAlloc (sizeof
(ColorPalette) - sizeof (ARGB));
+ if (!palette)
+ return OutOfMemory;
+
+ palette->Flags = 0;
+ palette->Count = 0;
+ status = GdipSetImagePalette ((GpImage*)*bitmap, palette);
+ (*bitmap)->image_format = MEMBMP;
+ (*bitmap)->active_bitmap->image_flags |=
ImageFlagsUndocumented;/* 0x00040000 */
+ (*bitmap)->active_bitmap->image_flags &= ~ImageFlagsHasAlpha;
/* 0x00000002 */
+ GdipFree (palette);
+ }
+ return status;
}
GpStatus
-GdipCreateHICONFromBitmap(GpBitmap* bitmap, void **hbmReturn)
+GdipCreateHICONFromBitmap (GpBitmap* bitmap, void **hbmReturn)
{
- return(NotImplemented);
+ /*
+ * Note: the handle must survive disposing the bitmap. This means that
there's no interoperable way to free this memory.
+ * For libgdiplus you must use GdipDisposeImage on the handle, while on
Windows you should call the DestroyIcon function.
+ */
+ return GdipCloneImage ((GpImage *)bitmap, (GpImage**)hbmReturn);
}
GpStatus
Modified: trunk/libgdiplus/src/gdip.h
===================================================================
--- trunk/libgdiplus/src/gdip.h 2007-01-12 14:35:05 UTC (rev 70919)
+++ trunk/libgdiplus/src/gdip.h 2007-01-12 14:57:36 UTC (rev 70920)
@@ -429,7 +429,8 @@
ImageFlagsHasRealDPI = 4096,
ImageFlagsHasRealPixelSize = 8192,
ImageFlagsReadOnly = 65536,
- ImageFlagsCaching = 131072
+ ImageFlagsCaching = 131072,
+ ImageFlagsUndocumented = 0x00040000
} ImageFlags;
typedef enum
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches