Author: pbartok
Date: 2005-05-26 12:03:34 -0400 (Thu, 26 May 2005)
New Revision: 45059
Modified:
trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
trunk/mcs/class/System.Drawing/System.Drawing/Image.cs
Log:
2005-05-25 Jonathan Gilbert <[EMAIL PROTECTED]>
* Image.cs: Added retrieveGDIPalette () and storeGDIPalette ()
and modified the Palette property to call them. This non-
persistent behaviour was discovered by trial and error with
Microsoft's implementation. In fact, the Palette property
does not behave like a property at all! It is the only way an
instance of System.Drawing.Imaging.ColorPalette can be created,
and it reflects a backing store that is only updated when the
property 'set' method is called. Also updated Clone () since
the palette is no longer cached at image load time.
* Image.cs: Added IsIndexedPixelFormat () in the same vein as
Image::IsAlphaPixelFormat and Image::IsCanonicalPixelFormat.
As such a function is not listed in MSDN nor given in
Microsoft's implementation, I have made it a private function
within the class that uses it.
Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2005-05-26
15:52:42 UTC (rev 45058)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2005-05-26
16:03:34 UTC (rev 45059)
@@ -1,3 +1,20 @@
+2005-05-25 Jonathan Gilbert <[EMAIL PROTECTED]>
+
+ * Image.cs: Added retrieveGDIPalette () and storeGDIPalette ()
+ and modified the Palette property to call them. This non-
+ persistent behaviour was discovered by trial and error with
+ Microsoft's implementation. In fact, the Palette property
+ does not behave like a property at all! It is the only way an
+ instance of System.Drawing.Imaging.ColorPalette can be created,
+ and it reflects a backing store that is only updated when the
+ property 'set' method is called. Also updated Clone () since
+ the palette is no longer cached at image load time.
+ * Image.cs: Added IsIndexedPixelFormat () in the same vein as
+ Image::IsAlphaPixelFormat and Image::IsCanonicalPixelFormat.
+ As such a function is not listed in MSDN nor given in
+ Microsoft's implementation, I have made it a private function
+ within the class that uses it.
+
2005-05-24 Kornél Pál <[EMAIL PROTECTED]>
* Graphics.cs: Revised DrawString methods
Modified: trunk/mcs/class/System.Drawing/System.Drawing/Image.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Image.cs 2005-05-26
15:52:42 UTC (rev 45058)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Image.cs 2005-05-26
16:03:34 UTC (rev 45059)
@@ -75,6 +75,12 @@
}
}
}
+
+ private static bool IsIndexedPixelFormat(PixelFormat pixfmt)
+ {
+ return ((pixfmt & PixelFormat.Indexed) != 0);
+ }
+
void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
{
@@ -526,43 +532,57 @@
[Browsable (false)]
public ColorPalette Palette {
get {
- int size = 0;
- IntPtr palbuff;
-
- Status status = GDIPlus.GdipGetImagePaletteSize
(nativeObject, out size);
- GDIPlus.CheckStatus (status);
-
- palbuff = Marshal.AllocHGlobal (size);
-
- try {
- status = GDIPlus.GdipGetImagePalette
(nativeObject, palbuff, size);
- GDIPlus.CheckStatus (status);
-
- ColorPalette colpal = new ColorPalette ();
- colpal.setFromGDIPalette (palbuff);
-
- return colpal;
- }
-
- finally {
- Marshal.FreeHGlobal (palbuff);
- }
-
+ return retrieveGDIPalette();
}
set {
- IntPtr palbuff = value.getGDIPalette ();
-
- try {
- Status status = GDIPlus.GdipSetImagePalette
(nativeObject, palbuff);
- GDIPlus.CheckStatus (status);
- }
-
- finally {
- Marshal.FreeHGlobal (palbuff);
- }
-
+ storeGDIPalette(value);
}
}
+
+ internal ColorPalette retrieveGDIPalette()
+ {
+ ColorPalette ret = new ColorPalette();
+ if (!IsIndexedPixelFormat (PixelFormat)) {
+ return ret;
+ }
+ Status st;
+ int bytes;
+
+ st = GDIPlus.GdipGetImagePaletteSize (nativeObject, out bytes);
+ GDIPlus.CheckStatus (st);
+ IntPtr palette_data = Marshal.AllocHGlobal (bytes);
+ try {
+ st = GDIPlus.GdipGetImagePalette (nativeObject,
palette_data, bytes);
+ GDIPlus.CheckStatus (st);
+ ret.setFromGDIPalette (palette_data);
+ return ret;
+ }
+
+ finally {
+ Marshal.FreeHGlobal (palette_data);
+ }
+ }
+
+ internal void storeGDIPalette(ColorPalette palette)
+ {
+ if (palette == null) {
+ throw new ArgumentNullException("palette");
+ }
+ IntPtr palette_data = palette.getGDIPalette();
+ if (palette_data == IntPtr.Zero) {
+ return;
+ }
+
+ try {
+ Status st = GDIPlus.GdipSetImagePalette (nativeObject,
palette_data);
+ GDIPlus.CheckStatus (st);
+ }
+
+ finally {
+ Marshal.FreeHGlobal(palette_data);
+ }
+ }
+
public SizeF PhysicalDimension {
get {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches