//
// System.Drawing.Imaging.ImageAttributes.cs
//
-// Author:
-// Dennis Hayes (dennish@raytek.com) (stubbed out)
-// Jordi Mas i Hernàndez (jmas@softcatala.org)
-// Sanjay Gupta (gsanjay@novell.com)
+// Authors:
+// Dennis Hayes (dennish@raytek.com) (stubbed out)
+// Jordi Mas i Hernàndez (jmas@softcatala.org)
+// Sanjay Gupta (gsanjay@novell.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002-4 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
-using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
-namespace System.Drawing.Imaging
-{
- /// <summary>
- /// Summary description for ImageAttributes.
- /// </summary>
+namespace System.Drawing.Imaging {
+
+ [StructLayout(LayoutKind.Sequential)]
public sealed class ImageAttributes : ICloneable, IDisposable {
private IntPtr nativeImageAttr = IntPtr.Zero;
Status status = GDIPlus.GdipSetImageAttributesColorKeys (nativeImageAttr,
type, false, 0, 0);
- GDIPlus.CheckStatus (status);
+ GDIPlus.CheckStatus (status);
}
public void ClearColorMatrix()
ClearColorMatrix (ColorAdjustType.Default);
}
- public void ClearColorMatrix(ColorAdjustType type)
+ public void ClearColorMatrix (ColorAdjustType type)
{
- Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
- type, false, null, null, ColorMatrixFlag.Default);
-
- GDIPlus.CheckStatus (status);
+ Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr, type, false,
+ IntPtr.Zero, IntPtr.Zero, ColorMatrixFlag.Default);
+ GDIPlus.CheckStatus (status);
}
public void ClearGamma()
//Sets the color keys for all GDI+ objects
public void SetColorKey(Color colorLow, Color colorHigh)
{
-
- Status status = GDIPlus.GdipSetImageAttributesColorKeys(nativeImageAttr,
- ColorAdjustType.Default, true, colorLow.ToArgb(), colorHigh.ToArgb());
-
- if (status != Status.Ok)
- throw new Exception ("Error calling GDIPlus.GdipSetImageAttributesColorKeys:" +status);
+ SetColorKey (colorLow, colorHigh, ColorAdjustType.Default);
}
- public void SetColorMatrix(ColorMatrix colorMatrix)
+ public void SetColorMatrix (ColorMatrix colorMatrix)
{
-
- Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr, ColorAdjustType.Default,
- true, colorMatrix, (ColorMatrix)null, ColorMatrixFlag.Default);
-
- if (status != Status.Ok)
- throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
+ IntPtr cm = ColorMatrix.Alloc (colorMatrix);
+ try {
+ Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
+ ColorAdjustType.Default, true, cm, IntPtr.Zero, ColorMatrixFlag.Default);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ ColorMatrix.Free (cm);
+ }
}
- public void SetColorMatrix(ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag)
- {
-
- Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr, ColorAdjustType.Default,
- true, colorMatrix, (ColorMatrix)null, colorMatrixFlag);
- if (status != Status.Ok)
- throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
-
+ [MonoTODO ("colorMatrixFlag is ignored in libgdiplus")]
+ public void SetColorMatrix (ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag)
+ {
+ IntPtr cm = ColorMatrix.Alloc (colorMatrix);
+ try {
+ Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
+ ColorAdjustType.Default, true, cm, IntPtr.Zero, colorMatrixFlag);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ ColorMatrix.Free (cm);
+ }
}
- public void SetColorMatrix(ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag, ColorAdjustType colorAdjustType) {
-
- Status status = GDIPlus.GdipSetImageAttributesColorMatrix(nativeImageAttr,colorAdjustType,
- true, colorMatrix, (ColorMatrix)null, colorMatrixFlag);
-
- if (status != Status.Ok)
- throw new Exception ("Error calling GDIPlus.SetColorMatrix:" +status);
+ [MonoTODO ("colorMatrixFlag is ignored in libgdiplus")]
+ public void SetColorMatrix (ColorMatrix colorMatrix, ColorMatrixFlag colorMatrixFlag, ColorAdjustType colorAdjustType)
+ {
+ IntPtr cm = ColorMatrix.Alloc (colorMatrix);
+ try {
+ Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
+ colorAdjustType, true, cm, IntPtr.Zero, colorMatrixFlag);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ ColorMatrix.Free (cm);
+ }
}
public void Dispose()
int mapsize = Marshal.SizeOf (gdiclr);
int size = mapsize * map.Length;
clrmap = lpPointer = Marshal.AllocHGlobal (size);
-
- for (int i=0; i < map.Length; i++)
- {
- gdiclr.from = map[i].OldColor.ToArgb();
- gdiclr.to = map[i].NewColor.ToArgb();
+ try {
+ for (int i=0; i < map.Length; i++) {
+ gdiclr.from = map[i].OldColor.ToArgb();
+ gdiclr.to = map[i].NewColor.ToArgb();
- Marshal.StructureToPtr (gdiclr, lpPointer, false);
- lpPointer = (IntPtr) (lpPointer.ToInt32() + mapsize);
- }
+ Marshal.StructureToPtr (gdiclr, lpPointer, false);
+ lpPointer = (IntPtr) (lpPointer.ToInt64() + mapsize);
+ }
- Status status = GDIPlus.GdipSetImageAttributesRemapTable (nativeImageAttr,
- ColorAdjustType.Brush, true, (uint) map.Length, clrmap);
-
- Marshal.FreeHGlobal (clrmap);
-
- GDIPlus.CheckStatus (status);
+ Status status = GDIPlus.GdipSetImageAttributesRemapTable (nativeImageAttr,
+ ColorAdjustType.Brush, true, (uint) map.Length, clrmap);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ Marshal.FreeHGlobal (clrmap);
+ }
}
}
- public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix)
- {
- Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
- ColorAdjustType.Default, true, newColorMatrix, grayMatrix, ColorMatrixFlag.Default);
-
- GDIPlus.CheckStatus (status);
+ [MonoTODO ("grayMatrix is ignored in libgdiplus")]
+ public void SetColorMatrices (ColorMatrix newColorMatrix, ColorMatrix grayMatrix)
+ {
+ IntPtr cm = ColorMatrix.Alloc (newColorMatrix);
+ try {
+ IntPtr gm = ColorMatrix.Alloc (grayMatrix);
+ try {
+ Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
+ ColorAdjustType.Default, true, cm, gm, ColorMatrixFlag.Default);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ ColorMatrix.Free (gm);
+ }
+ }
+ finally {
+ ColorMatrix.Free (cm);
+ }
}
- public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag flags)
- {
- Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
- ColorAdjustType.Default, true, newColorMatrix, grayMatrix, flags);
-
- GDIPlus.CheckStatus (status);
- }
+ [MonoTODO ("grayMatrix and colorMatrixFlag are ignored in libgdiplus")]
+ public void SetColorMatrices (ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag flags)
+ {
+ IntPtr cm = ColorMatrix.Alloc (newColorMatrix);
+ try {
+ IntPtr gm = ColorMatrix.Alloc (grayMatrix);
+ try {
+ Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
+ ColorAdjustType.Default, true, cm, gm, flags);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ ColorMatrix.Free (gm);
+ }
+ }
+ finally {
+ ColorMatrix.Free (cm);
+ }
+ }
- public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag mode, ColorAdjustType type)
- {
- Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
- ColorAdjustType.Default, true, newColorMatrix, grayMatrix, mode);
-
- GDIPlus.CheckStatus (status);
+ [MonoTODO ("grayMatrix and colorMatrixFlag are ignored in libgdiplus")]
+ public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag mode, ColorAdjustType type)
+ {
+ IntPtr cm = ColorMatrix.Alloc (newColorMatrix);
+ try {
+ IntPtr gm = ColorMatrix.Alloc (grayMatrix);
+ try {
+ Status status = GDIPlus.GdipSetImageAttributesColorMatrix (nativeImageAttr,
+ ColorAdjustType.Default, true, cm, gm, mode);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ ColorMatrix.Free (gm);
+ }
+ }
+ finally {
+ ColorMatrix.Free (cm);
+ }
}
public void SetGamma(float gamma)
int mapsize = Marshal.SizeOf (gdiclr);
int size = mapsize * map.Length;
clrmap = lpPointer = Marshal.AllocHGlobal (size);
-
- for (int i=0; i < map.Length; i++)
- {
- gdiclr.from = map[i].OldColor.ToArgb();
- gdiclr.to = map[i].NewColor.ToArgb();
+ try {
+ for (int i=0; i < map.Length; i++) {
+ gdiclr.from = map[i].OldColor.ToArgb();
+ gdiclr.to = map[i].NewColor.ToArgb();
- Marshal.StructureToPtr (gdiclr, lpPointer, false);
- lpPointer = (IntPtr) (lpPointer.ToInt32() + mapsize);
- }
-
- Status status = GDIPlus.GdipSetImageAttributesRemapTable (nativeImageAttr,
- type, true, (uint) map.Length, clrmap);
-
- Marshal.FreeHGlobal (clrmap);
-
- GDIPlus.CheckStatus (status);
+ Marshal.StructureToPtr (gdiclr, lpPointer, false);
+ lpPointer = (IntPtr) (lpPointer.ToInt64() + mapsize);
+ }
+ Status status = GDIPlus.GdipSetImageAttributesRemapTable (nativeImageAttr,
+ type, true, (uint) map.Length, clrmap);
+ GDIPlus.CheckStatus (status);
+ }
+ finally {
+ Marshal.FreeHGlobal (clrmap);
+ }
}
public void SetThreshold(float threshold)
GDIPlus.CheckStatus (status);
}
-
}
}