Author: krasnov
Date: 2005-09-07 06:51:13 -0400 (Wed, 07 Sep 2005)
New Revision: 49628
Added:
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfiguration.cs
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationCollection.cs
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationHandler.cs
trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodec.jvm.cs
Modified:
trunk/mcs/class/System.Drawing/ChangeLog
trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ChangeLog
trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodecInfo.jvm.cs
trunk/mcs/class/System.Drawing/System.Drawing.vmwcsproj
trunk/mcs/class/System.Drawing/System.Drawing/Bitmap.jvm.cs
trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
trunk/mcs/class/System.Drawing/System.Drawing/Image.jvm.cs
Log:
System.Drawing.vmwcsproj: ImageCodec.jvm.cs
Added Mainsoft.Drawing.Configuration.jvm folder with
ResolutionConfiguration.cs, ResolutionConfigurationCollection.cs,
ResolutionConfigurationHandler.cs
Bitmap.jvm.cs: fixed bitamp accessors
Image.jvm.cs: fixed image accessors
ImageCodecInfo.jvm.cs: Refactoring
Added ImageCodec.jvm.cs
Modified: trunk/mcs/class/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/ChangeLog 2005-09-07 10:33:21 UTC (rev
49627)
+++ trunk/mcs/class/System.Drawing/ChangeLog 2005-09-07 10:51:13 UTC (rev
49628)
@@ -1,3 +1,10 @@
+2005-09-07 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * System.Drawing.vmwcsproj: ImageCodec.jvm.cs
+ Added Mainsoft.Drawing.Configuration.jvm folder with
+ ResolutionConfiguration.cs, ResolutionConfigurationCollection.cs,
+ ResolutionConfigurationHandler.cs
+
2005-08-28 Vladimir Krasnov <[EMAIL PROTECTED]>
* System.Drawing.vmwcsproj: Added GraphicsContainer.jvm.cs,
GraphicsState.jvm.cs
Added:
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfiguration.cs
===================================================================
---
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfiguration.cs
2005-09-07 10:33:21 UTC (rev 49627)
+++
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfiguration.cs
2005-09-07 10:51:13 UTC (rev 49628)
@@ -0,0 +1,76 @@
+using System;
+using System.Collections;
+
+namespace Mainsoft.Drawing.Configuration
+{
+ /// <summary>
+ /// Summary description for ResolutionConfiguration.
+ /// </summary>
+ public class ResolutionConfiguration : IComparable
+ {
+ string _imageFormat = "";
+
+ string _xResPath = "";
+ string _yResPath = "";
+ string _unitsTypePath = "";
+
+ string _xResDefault = "";
+ string _yResDefault = "";
+ string _unitsTypeDefault = "";
+
+ Hashtable _unitScale;
+
+ public ResolutionConfiguration(
+ string imageFormat,
+ string xresPath, string yresPath, string unitsTypePath,
+ string xresDefault, string yresDefault, string
unitsTypeDefault,
+ Hashtable unitScale)
+ {
+ _imageFormat = imageFormat;
+
+ _xResPath = xresPath;
+ _yResPath = yresPath;
+ _unitsTypePath = unitsTypePath;
+
+ _xResDefault = xresDefault;
+ _yResDefault = yresDefault;
+ _unitsTypeDefault = unitsTypeDefault;
+
+ _unitScale = unitScale;
+ }
+
+ public string XResPath {
+ get { return _xResPath; }
+ }
+ public string XResDefault {
+ get { return _xResDefault; }
+ }
+ public string YResPath {
+ get { return _yResPath; }
+ }
+ public string YResDefault {
+ get { return _yResDefault; }
+ }
+ public string UnitsTypePath {
+ get { return _unitsTypePath; }
+ }
+ public string UnitsTypeDefault {
+ get { return _unitsTypeDefault; }
+ }
+ public string ImageFormat {
+ get { return _imageFormat; }
+ }
+ public Hashtable UnitsScale {
+ get { return _unitScale; }
+ }
+
+ #region IComparable Members
+
+ public int CompareTo(object obj) {
+ return
_imageFormat.CompareTo(((ResolutionConfiguration)obj).ImageFormat);
+ }
+
+ #endregion
+
+ }
+}
Added:
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationCollection.cs
===================================================================
---
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationCollection.cs
2005-09-07 10:33:21 UTC (rev 49627)
+++
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationCollection.cs
2005-09-07 10:51:13 UTC (rev 49628)
@@ -0,0 +1,93 @@
+using System;
+using System.Collections;
+
+namespace Mainsoft.Drawing.Configuration {
+ /// <summary>
+ /// Summary description for MetadataConfigurationCollection.
+ /// </summary>
+ public class ResolutionConfigurationCollection : IEnumerable,
ICollection {
+
+ ArrayList _resolutionConfigurations;
+
+ #region ctors
+
+ internal
ResolutionConfigurationCollection(ResolutionConfigurationCollection parent) {
+ _resolutionConfigurations = new ArrayList();
+
+ if (parent != null)
+ _resolutionConfigurations.AddRange(parent);
+ }
+
+ #endregion
+
+ #region methods
+
+ internal void Add(ResolutionConfiguration value) {
+ _resolutionConfigurations.Add(value);
+ }
+
+ internal void Sort() {
+ _resolutionConfigurations.Sort();
+ }
+
+ #endregion
+
+ #region props
+
+ public ResolutionConfiguration this[int index] {
+ get {
+ return
(ResolutionConfiguration)_resolutionConfigurations[index];
+ }
+ }
+
+ public ResolutionConfiguration this[string ImageFormat] {
+ get {
+ for (int i=0; i <
_resolutionConfigurations.Count; i++)
+ if (
((ResolutionConfiguration)_resolutionConfigurations[i]).ImageFormat ==
ImageFormat )
+ return
(ResolutionConfiguration)_resolutionConfigurations[i];
+ return null;
+ }
+ }
+
+ #endregion
+
+ #region IEnumerable Members
+
+ public IEnumerator GetEnumerator() {
+ // TODO: Add
ResolutionConfigurationCollection.GetEnumerator implementation
+ return _resolutionConfigurations.GetEnumerator();
+ }
+
+ #endregion
+
+ #region ICollection Members
+
+ public bool IsSynchronized {
+ get {
+ // TODO: Add
ResolutionConfigurationCollection.IsSynchronized getter implementation
+ return _resolutionConfigurations.IsSynchronized;
+ }
+ }
+
+ public int Count {
+ get {
+ // TODO: Add
ResolutionConfigurationCollection.Count getter implementation
+ return _resolutionConfigurations.Count;
+ }
+ }
+
+ public void CopyTo(Array array, int index) {
+ // TODO: Add ResolutionConfigurationCollection.CopyTo
implementation
+ _resolutionConfigurations.CopyTo(array, index);
+ }
+
+ public object SyncRoot {
+ get {
+ // TODO: Add
ResolutionConfigurationCollection.SyncRoot getter implementation
+ return _resolutionConfigurations.SyncRoot;
+ }
+ }
+
+ #endregion
+ }
+}
Added:
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationHandler.cs
===================================================================
---
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationHandler.cs
2005-09-07 10:33:21 UTC (rev 49627)
+++
trunk/mcs/class/System.Drawing/Mainsoft.Drawing.Configuration.jvm/ResolutionConfigurationHandler.cs
2005-09-07 10:51:13 UTC (rev 49628)
@@ -0,0 +1,140 @@
+using System;
+using System.Collections;
+using System.Configuration;
+using System.Xml;
+
+
+namespace Mainsoft.Drawing.Configuration
+{
+ /// <summary>
+ /// Summary description for MetadataConfigurationHandler.
+ /// </summary>
+ public class ResolutionConfigurationHandler :
IConfigurationSectionHandler
+ {
+ public ResolutionConfigurationHandler()
+ {
+ //
+ // TODO: Add constructor logic here
+ //
+ }
+
+ public virtual object Create (object parent, object
configContext, XmlNode section) {
+
+ if (section.Attributes != null &&
section.Attributes.Count != 0)
+ HandlersUtil.ThrowException ("Unrecognized
attribute", section);
+
+ ResolutionConfigurationCollection col =
+ new ResolutionConfigurationCollection(parent as
ResolutionConfigurationCollection);
+
+ XmlNodeList imageFormats = section.ChildNodes;
+ foreach (XmlNode child in imageFormats) {
+
+ XmlNodeType ntype = child.NodeType;
+ if (ntype == XmlNodeType.Whitespace || ntype ==
XmlNodeType.Comment)
+ continue;
+
+ if (ntype != XmlNodeType.Element)
+ HandlersUtil.ThrowException ("Only
elements allowed", child);
+
+ string imageFormatName =
HandlersUtil.ExtractAttributeValue ("name", child, false, false);
+
+ string xResPath =
HandlersUtil.ExtractNodeValue(child["xresolution"]);
+ string yResPath =
HandlersUtil.ExtractNodeValue(child["yresolution"]);
+ string unitsType =
HandlersUtil.ExtractNodeValue(child["unitstype"], false, true);
+
+ string xResDefault =
HandlersUtil.ExtractAttributeValue ("default", child["xresolution"]);
+ string yResDefault =
HandlersUtil.ExtractAttributeValue ("default", child["yresolution"]);
+ string unitsTypeDefault =
HandlersUtil.ExtractAttributeValue ("default", child["unitstype"], true);
+
+ Hashtable unitScale = new Hashtable(3);
+
+ XmlNodeList unitScaleNodes =
child.SelectNodes("unitscale");
+ foreach (XmlNode unitScaleNode in
unitScaleNodes) {
+ unitScale.Add(
+
HandlersUtil.ExtractAttributeValue ("value", unitScaleNode),
+
HandlersUtil.ExtractNodeValue(unitScaleNode) );
+ }
+
+ ResolutionConfiguration resConf = new
ResolutionConfiguration(
+ imageFormatName,
+ xResPath, yResPath, unitsType,
+ xResDefault, yResDefault,
unitsTypeDefault,
+ unitScale);
+
+ col.Add(resConf);
+ }
+
+ col.Sort();
+ return col;
+ }
+ }
+
+ internal sealed class HandlersUtil {
+ private HandlersUtil () {
+ }
+
+ static internal string ExtractNodeValue(XmlNode node, bool
optional, bool allowEmpty) {
+ if (node == null) {
+ if (optional)
+ return null;
+ ThrowException ("Required node not found",
node);
+ }
+
+ string nodeValue = node.InnerText;
+
+ if (!allowEmpty && nodeValue == String.Empty) {
+ string opt = optional ? "Optional" : "Required";
+ ThrowException (opt + " node is empty", node);
+ }
+
+ return nodeValue;
+ }
+
+ static internal string ExtractNodeValue(XmlNode node, bool
optional) {
+ return ExtractNodeValue(node, false, false);
+ }
+
+ static internal string ExtractNodeValue(XmlNode node) {
+ return ExtractNodeValue(node, false);
+ }
+
+ static internal string ExtractAttributeValue (string attKey,
XmlNode node) {
+ return ExtractAttributeValue (attKey, node, false);
+ }
+
+ static internal string ExtractAttributeValue (string attKey,
XmlNode node, bool optional) {
+ return ExtractAttributeValue (attKey, node, optional,
false);
+ }
+
+ static internal string ExtractAttributeValue (string attKey,
XmlNode node, bool optional,
+ bool allowEmpty) {
+ if (node.Attributes == null) {
+ if (optional)
+ return null;
+
+ ThrowException ("Required attribute not found:
" + attKey, node);
+ }
+
+ XmlNode att = node.Attributes.RemoveNamedItem (attKey);
+ if (att == null) {
+ if (optional)
+ return null;
+ ThrowException ("Required attribute not found:
" + attKey, node);
+ }
+
+ string value = att.Value;
+ if (!allowEmpty && value == String.Empty) {
+ string opt = optional ? "Optional" : "Required";
+ ThrowException (opt + " attribute is empty: " +
attKey, node);
+ }
+
+ return value;
+ }
+
+ static internal void ThrowException (string msg, XmlNode node) {
+ if (node != null && node.Name != String.Empty)
+ msg = msg + " (node name: " + node.Name + ") ";
+ throw new ConfigurationException (msg, node);
+ }
+ }
+}
Modified: trunk/mcs/class/System.Drawing/System.Drawing/Bitmap.jvm.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Bitmap.jvm.cs 2005-09-07
10:33:21 UTC (rev 49627)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Bitmap.jvm.cs 2005-09-07
10:51:13 UTC (rev 49628)
@@ -2,6 +2,7 @@
using System.IO;
using System.Drawing.Imaging;
using System.Runtime.Serialization;
+using Mainsoft.Drawing.Services;
using io = java.io;
using imageio = javax.imageio;
@@ -24,8 +25,10 @@
throw new NotImplementedException ();
}
- public Bitmap (int width, int height, Graphics g) {
- throw new NotImplementedException();
+ public Bitmap (int width, int height, Graphics g)
+ :this (width, height, PixelFormat.Format32bppArgb) {
+ this._horizontalResolution = g.DpiX;
+ this._verticalResolution = g.DpiY;
}
public Bitmap (Image orig, Size newSize)
@@ -84,16 +87,15 @@
//FIXME: useIcm param
java.io.File file = vmw.common.IOUtils.getJavaFile
(filename);
if (!file.exists ())
- //TBD: check what exception throws NET
- throw new System.IO.IOException ("File not
found: "+filename);
+ throw new System.IO.FileNotFoundException
(filename);
Initialize (new stream.FileImageInputStream (file),
format);
}
public Bitmap (Type type, string resource) {
using (Stream s =
type.Assembly.GetManifestResourceStream (resource)) {
if (s == null)
- //TBD: check what type is thrown in MS
- throw new Exception("Resource name was
not found: `" + resource + "'");
+ throw new ArgumentException("Resource
'" + resource + "' could not be found in class '" + type.ToString() + "'");
+
io.InputStream jis =
vmw.common.IOUtils.ToInputStream (s);
try {
Initialize (new
stream.MemoryCacheImageInputStream (jis), null);
@@ -104,101 +106,58 @@
}
}
}
-
- //FIXME: should go to imageio helpers class
- static ImageFormat MimeTypesToImageFormat (string [] mimeTypes)
- {
- foreach (ImageCodecInfo codec in
ImageCodecInfo.Decoders.Values)
- for (int i=0; i<mimeTypes.Length; i++)
- if (codec.MimeType == mimeTypes [i])
- return new ImageFormat
(codec.FormatID);
- return null;
+#if INTPTR_SUPPORT
+ public Bitmap (int width, int height, int stride, PixelFormat
format, IntPtr scan0)
+ {
+ throw new NotImplementedException();
}
+#endif
+ #endregion
+ #region Internal Initialization
+
private void Initialize (stream.ImageInputStream input,
ImageFormat format) {
- java.util.Iterator iter = null;
- if (format != null)
- iter =
imageio.ImageIO.getImageReadersByMIMEType (
- ImageCodecInfo.ImageFormatToMimeType
(format));
- else
- iter = imageio.ImageIO.getImageReaders (input);
+ ImageCodec ic = null;
- if (!iter.hasNext ())
- throw new ArgumentException ("Format not
found"); //TBD: make same text as MS
-
- imageio.ImageReader r = (imageio.ImageReader) iter.next
();
-
- r.setInput (input);
-
if (format == null)
- format = MimeTypesToImageFormat
(r.getOriginatingProvider ().getMIMETypes ());
+ ic = ImageCodec.CreateReader(input);
+ else
+ ic = ImageCodec.CreateReader(format);
- Initialize (r, format);
- }
-
- private void Initialize (imageio.ImageReader r, ImageFormat
format) {
java.awt.Image [] nativeObjects;
java.awt.Image [] thumbnails = null;
try {
- nativeObjects = new BufferedImage
[r.getNumImages (false)];
- for (int i = 0; i < nativeObjects.Length; i++) {
- if (r.hasThumbnails(i)) {
- if (thumbnails == null)
- thumbnails = new
BufferedImage[nativeObjects.Length];
-
- thumbnails[i] =
r.readThumbnail(i, 0);
- }
- nativeObjects [i] = r.read (i);
- }
-
+ ic.NativeStream = input;
+ nativeObjects = ic.ReadImage();
+ thumbnails = ic.ReadThumbnails(0);
+ ic.ParseMetadata();
}
catch (Exception e) {
- //TDB: make exception same as in MS
- throw new ArgumentException ("Error reading",
e);
+ string h = e.Message;
+ throw new OutOfMemoryException ("Out of
memory");
}
- base.Initialize (nativeObjects, thumbnails, format,
FrameDimension.Page.Guid);
- }
-#if INTPTR_SUPPORT
- public Bitmap (int width, int height, int stride, PixelFormat
format, IntPtr scan0)
- {
- throw new NotImplementedException();
+ base.Initialize (
+ nativeObjects, thumbnails, format,
FrameDimension.Page.Guid,
+ ic.ImageHorizontalResolution,
ic.ImageVerticalResolution );
}
-#endif
+
#endregion
#region InternalSave
protected override void InternalSave (stream.ImageOutputStream
output, Guid clsid) {
- string mime=ImageCodecInfo.FindEncoder (clsid).MimeType;
- imageio.ImageWriter writer = null;;
- try {
- writer = (imageio.ImageWriter)
imageio.ImageIO.getImageWritersByMIMEType (mime).next ();
- writer.setOutput (output);
- if (NativeObjectsCount == 1)
- writer.write (NativeObject);
- else if (writer.canWriteSequence ())
- SaveSequence (writer);
- else
- throw new NotImplementedException ();
+
+ ImageCodec ic = ImageCodec.CreateWriter( clsid );
+ if (ic != null) {
+ ic.NativeStream = output;
+ ic.WriteImage( NativeObject );
}
- catch (Exception e) {
- //FIXME: check dotnet exceptions in save, and
throw same types
- throw new Exception ("java threw an exception",
e);
+ else {
+ // FIXME: correct this exception
+ throw new Exception("Format not supported");
}
}
- void SaveSequence (imageio.ImageWriter writer) {
- //FIXME: does not supports metadata and thumbnails for
now
- writer.prepareWriteSequence (null);
-
- for (int i = 0; i < NativeObjectsCount; i++) {
- imageio.IIOImage iio = new imageio.IIOImage
((BufferedImage)this[i], null, null);
- writer.writeToSequence (iio, null);
- }
-
- writer.endWriteSequence ();
- }
-
#endregion
#region private statics: ToBufferedImageFormat,
CreateScaledImage
@@ -313,7 +272,8 @@
#region SetResolution [TODO]
public void SetResolution (float xDpi, float yDpi)
{
- throw new NotImplementedException();
+ _horizontalResolution = xDpi;
+ _verticalResolution = yDpi;
}
#endregion
Modified: trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2005-09-07
10:33:21 UTC (rev 49627)
+++ trunk/mcs/class/System.Drawing/System.Drawing/ChangeLog 2005-09-07
10:51:13 UTC (rev 49628)
@@ -1,3 +1,8 @@
+2005-09-07 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * Bitmap.jvm.cs: fixed bitamp accessors
+ * Image.jvm.cs: fixed image accessors
+
2005-09-07 Konstantin Triger <[EMAIL PROTECTED]>
* AdvancedStroke.jvm.cs: fix matrix translate
* Graphics.jvm.cs: fix matrix concatenation order
Modified: trunk/mcs/class/System.Drawing/System.Drawing/Image.jvm.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing/Image.jvm.cs 2005-09-07
10:33:21 UTC (rev 49627)
+++ trunk/mcs/class/System.Drawing/System.Drawing/Image.jvm.cs 2005-09-07
10:51:13 UTC (rev 49628)
@@ -13,8 +13,11 @@
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.ComponentModel;
+using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
+using Mainsoft.Drawing.Services;
+
using BufferedImage = java.awt.image.BufferedImage;
using java.io;
using javax.imageio;
@@ -33,6 +36,8 @@
int _currentObject;
Guid _dimension;
ImageFormat _format;
+ protected float _verticalResolution = 0;
+ protected float _horizontalResolution = 0;
#endregion
#region Constructor
@@ -71,11 +76,16 @@
}
protected void Initialize (java.awt.Image [] nativeObjects,
java.awt.Image [] thumbnails, ImageFormat format, Guid dimension) {
+ Initialize(nativeObjects, thumbnails, format, dimension, 0, 0);
+ }
+ protected void Initialize (java.awt.Image [] nativeObjects,
java.awt.Image [] thumbnails, ImageFormat format, Guid dimension, float xRes,
float yRes) {
_format = format;
_nativeObjects = nativeObjects;
_thumbnails = thumbnails;
_currentObject = 0;
_dimension = dimension;
+ _horizontalResolution = xRes;
+ _verticalResolution = yRes;
}
#endregion
@@ -86,6 +96,9 @@
get {
return _nativeObjects [_currentObject];
}
+ set {
+ _nativeObjects [_currentObject] = value;
+ }
}
protected java.awt.Image this [int i] {
@@ -247,8 +260,55 @@
#region RotateFlip [TODO]
public void RotateFlip (RotateFlipType rotateFlipType)
- {
- throw new NotImplementedException ();
+ {
+ awt.geom.AffineTransform tx;
+
+ //FIXME: check if it's not a metafile
+ switch (rotateFlipType) {
+ case RotateFlipType.RotateNoneFlipNone :
+ return;
+
+ case RotateFlipType.Rotate90FlipNone :
+ tx =
awt.geom.AffineTransform.getRotateInstance(Math.PI / 2);
+ tx.translate( 0, -NativeObject.getHeight(null)
);
+ break;
+
+ case RotateFlipType.Rotate180FlipNone :
+ tx =
awt.geom.AffineTransform.getScaleInstance(-1, -1);
+ tx.translate( -NativeObject.getWidth(null),
-NativeObject.getHeight(null) );
+ break;
+
+ case RotateFlipType.Rotate270FlipNone :
+ tx =
awt.geom.AffineTransform.getRotateInstance(-Math.PI / 2);
+ tx.translate( -NativeObject.getWidth(null), 0 );
+ break;
+
+ case RotateFlipType.RotateNoneFlipX :
+ tx =
awt.geom.AffineTransform.getScaleInstance(-1, 1);
+ tx.translate( -NativeObject.getWidth(null), 0 );
+ break;
+
+ case RotateFlipType.Rotate90FlipX :
+ tx =
awt.geom.AffineTransform.getRotateInstance(Math.PI / 2);
+ tx.scale(1, -1);
+ break;
+
+ case RotateFlipType.Rotate180FlipX :
+ tx =
awt.geom.AffineTransform.getScaleInstance(1, -1);
+ tx.translate( 0, -NativeObject.getHeight(null)
);
+ break;
+
+ case RotateFlipType.Rotate270FlipX :
+ tx =
awt.geom.AffineTransform.getRotateInstance(Math.PI / 2);
+ tx.scale(-1, 1);
+ tx.translate( -NativeObject.getWidth(null),
-NativeObject.getHeight(null) );
+ break;
+
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ image.AffineTransformOp op = new image.AffineTransformOp(tx,
image.AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
+ NativeObject = op.filter((BufferedImage)NativeObject, null);
}
#endregion
@@ -279,14 +339,14 @@
public void Save (Stream stream, ImageFormat format)
{
- Save (stream, ImageCodecInfo.FindEncoder (
- ImageCodecInfo.ImageFormatToClsid (format)), null);
+ Save (stream, ImageCodec.FindEncoder (
+ ImageCodec.ImageFormatToClsid (format)), null);
}
public void Save(string filename, ImageFormat format)
{
- Save (filename, ImageCodecInfo.FindEncoder (
- ImageCodecInfo.ImageFormatToClsid (format)), null);
+ Save (filename, ImageCodec.FindEncoder (
+ ImageCodec.ImageFormatToClsid (format)), null);
}
#endregion
@@ -347,11 +407,13 @@
}
#endregion
- #region HorisontalDimention [TODO]
+ #region HorizontalResolution [TODO]
public float HorizontalResolution
{
get {
- throw new NotImplementedException ();
+ if (_horizontalResolution == 0)
+ return Graphics.DefaultScreenResolution;
+ return _horizontalResolution;
}
}
#endregion
@@ -359,21 +421,33 @@
#region ColorPalette [TODO]
public ColorPalette Palette
{
- get {
-
- throw new NotImplementedException ();
+ get {
+ //FIXME: check if it's not a metafile
+
+ image.ColorModel colorModel =
((BufferedImage)NativeObject).getColorModel();
+ if (colorModel is image.IndexColorModel) {
+
+ Color [] colors = new Color[
((image.IndexColorModel)colorModel).getMapSize() ];
+ for (int i=0; i<colors.Length; i++) {
+ colors[i] = Color.FromArgb(
((image.IndexColorModel)colorModel).getRGB(i) );
+ }
+ ColorPalette palette = new ColorPalette(0,
colors);
+ return palette;
+ }
+ return new ColorPalette();
}
set {
+ // FIXME: add set
throw new NotImplementedException ();
}
}
#endregion
- #region PhysicalDimension [TODO]
+ #region PhysicalDimension
public SizeF PhysicalDimension
{
get {
- throw new NotImplementedException ();
+ return new Size(Width, Height);
}
}
#endregion
@@ -428,7 +502,9 @@
public float VerticalResolution
{
get {
- throw new NotImplementedException();
+ if (_verticalResolution == 0)
+ return Graphics.DefaultScreenResolution;
+ return _verticalResolution;
}
}
#endregion
Modified: trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ChangeLog
2005-09-07 10:33:21 UTC (rev 49627)
+++ trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ChangeLog
2005-09-07 10:51:13 UTC (rev 49628)
@@ -1,3 +1,8 @@
+2005-09-07 Vladimir Krasnov <[EMAIL PROTECTED]>
+
+ * ImageCodecInfo.jvm.cs: Refactoring
+ * Added ImageCodec.jvm.cs
+
2005-08-28 Vladimir Krasnov <[EMAIL PROTECTED]>
* ImageCodecInfo.jvm.cs: Fixed Iterate
Added: trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodec.jvm.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodec.jvm.cs
2005-09-07 10:33:21 UTC (rev 49627)
+++ trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodec.jvm.cs
2005-09-07 10:51:13 UTC (rev 49628)
@@ -0,0 +1,546 @@
+using System;
+using System.Configuration;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Drawing.Imaging;
+using System.Xml;
+using Mainsoft.Drawing.Configuration;
+
+using imageio = javax.imageio;
+using stream = javax.imageio.stream;
+using image = java.awt.image;
+using spi = javax.imageio.spi;
+using dom = org.w3c.dom;
+
+namespace Mainsoft.Drawing.Services {
+ /// <summary>
+ /// Summary description for ImageCodec.
+ /// </summary>
+ public class ImageCodec {
+ #region Members
+
+ imageio.ImageReader _nativeReader = null;
+ imageio.ImageWriter _nativeWriter = null;
+ stream.ImageInputStream _nativeStream = null;
+
+ float _imageHorizontalResolution = 0;
+ float _imageVerticalResolution = 0;
+
+ XmlDocument _metadataDocument = null;
+ ImageFormat _imageFormat = null;
+
+ #endregion
+
+ #region Constructros
+
+ protected ImageCodec() {
+ }
+
+ static ImageCodec() {
+ }
+
+ #endregion
+
+ #region Internal properties
+
+ internal imageio.ImageReader NativeReader {
+ get { return _nativeReader; }
+ set {
+ _nativeReader = value;
+ _imageFormat = MimeTypesToImageFormat(
value.getOriginatingProvider().getMIMETypes() );
+ }
+ }
+ internal imageio.ImageWriter NativeWriter {
+ get { return _nativeWriter; }
+ set {
+ _nativeWriter = value;
+ _imageFormat = MimeTypesToImageFormat(
value.getOriginatingProvider().getMIMETypes() );
+ }
+ }
+
+ internal stream.ImageInputStream NativeStream {
+ get { return _nativeStream; }
+ set {
+ if (value == null)
+ throw new
ArgumentNullException("stream");
+
+ _nativeStream = value;
+
+ if (NativeReader != null)
+ NativeReader.setInput( value );
+
+ if (NativeWriter != null)
+ NativeWriter.setOutput( value );
+ }
+ }
+
+ #endregion
+
+ #region ImageCodec factory methods
+
+ public static ImageCodec CreateReader(stream.ImageInputStream
inputStream) {
+ java.util.Iterator iter =
imageio.ImageIO.getImageReaders( inputStream );
+ return CreateReader(iter);
+ }
+
+ public static ImageCodec CreateReader(ImageFormat imageFormat) {
+ return CreateReader( ImageFormatToClsid( imageFormat )
);
+ }
+
+ public static ImageCodec CreateReader(Guid clsid) {
+ ImageCodecInfo codecInfo = (ImageCodecInfo)
Decoders[clsid];
+ java.util.Iterator iter =
imageio.ImageIO.getImageReadersByMIMEType( codecInfo.MimeType );
+ return CreateReader(iter);
+ }
+
+ private static ImageCodec CreateReader(java.util.Iterator iter)
{
+ if ( !iter.hasNext() )
+ throw new OutOfMemoryException ("Out of
memory");
+
+ ImageCodec imageCodec = new ImageCodec();
+ imageCodec.NativeReader = (imageio.ImageReader)
iter.next();
+ return imageCodec;
+ }
+
+ public static ImageCodec CreateWriter(ImageFormat imageFormat) {
+ return CreateWriter( ImageFormatToClsid( imageFormat )
);
+ }
+
+ public static ImageCodec CreateWriter(Guid clsid) {
+ ImageCodecInfo codecInfo = (ImageCodecInfo)
Encoders[clsid];
+ java.util.Iterator iter =
imageio.ImageIO.getImageWritersByMIMEType( codecInfo.MimeType );
+ return CreateWriter(iter);
+ }
+
+ public static ImageCodec CreateWriter(java.util.Iterator iter) {
+ if ( !iter.hasNext() )
+ throw new OutOfMemoryException ("Out of
memory");
+
+ ImageCodec imageCodec = new ImageCodec();
+ imageCodec.NativeWriter = (imageio.ImageWriter)
iter.next();
+ return imageCodec;
+ }
+
+ #endregion
+
+ #region Codec enumerations
+
+ internal static Hashtable Decoders {
+ get {
+ const string MYNAME =
"System.Drawing.Imaging.ImageCodecInfo.decoders";
+ Hashtable o = (Hashtable)
AppDomain.CurrentDomain.GetData (MYNAME);
+ if (o != null)
+ return o;
+ o = new ReaderSpiIterator().Iterate();
+ AppDomain.CurrentDomain.SetData(MYNAME, o);
+ return o;
+ }
+ }
+
+ internal static Hashtable Encoders {
+ get {
+ const string MYNAME =
"System.Drawing.Imaging.ImageCodecInfo.encoders";
+ Hashtable o = (Hashtable)
AppDomain.CurrentDomain.GetData (MYNAME);
+ if (o != null)
+ return o;
+ o = new WriterSpiIterator().Iterate();
+ AppDomain.CurrentDomain.SetData(MYNAME, o);
+ return o;
+ }
+ }
+
+ internal static ImageCodecInfo FindEncoder (Guid clsid) {
+ return (ImageCodecInfo) Encoders[clsid];
+ }
+
+ internal static ImageCodecInfo FindDecoder (Guid clsid) {
+ return (ImageCodecInfo) Decoders[clsid];
+ }
+
+ #endregion
+
+ #region SpiIterators
+
+ abstract class BaseSpiIterator {
+ protected abstract java.util.Iterator GetIterator
(string mimeType);
+ protected abstract spi.ImageReaderWriterSpi GetNext
(java.util.Iterator iter);
+
+ #region ProcessOneCodec
+ ImageCodecInfo ProcessOneCodec (Guid clsid, Guid
formatID, string mimeType) {
+ ImageCodecInfo ici = new ImageCodecInfo ();
+ ici.Clsid = clsid;
+ ici.FormatID = formatID;
+ ici.MimeType = mimeType;
+ java.util.Iterator iter = GetIterator
(mimeType);
+ while (iter.hasNext ()) {
+ spi.ImageReaderWriterSpi rw = GetNext
(iter);
+ try {
+ ici.CodecName =
rw.getDescription (java.util.Locale.getDefault ());
+ ici.DllName = null;
+ foreach (string suffix in
rw.getFileSuffixes ()) {
+ if
(ici.FilenameExtension != null)
+
ici.FilenameExtension += ";";
+ ici.FilenameExtension
+= "*."+suffix;
+ }
+ ici.Flags =
ImageCodecFlags.Builtin|ImageCodecFlags.SupportBitmap;
+ if (rw is spi.ImageReaderSpi) {
+ ici.Flags |=
ImageCodecFlags.Decoder;
+ if ((rw as
spi.ImageReaderSpi).getImageWriterSpiNames().Length != 0)
+ ici.Flags |=
ImageCodecFlags.Encoder;
+ }
+ if (rw is spi.ImageWriterSpi) {
+ ici.Flags |=
ImageCodecFlags.Encoder;
+ if ((rw as
spi.ImageWriterSpi).getImageReaderSpiNames().Length != 0)
+ ici.Flags |=
ImageCodecFlags.Decoder;
+ }
+ ici.FormatDescription =
string.Join(";",
+ rw.getFormatNames());
+ ici.Version =
(int)Convert.ToDouble(rw.getVersion ());
+ break;
+ }
+ catch {
+ }
+ }
+ return ici;
+ }
+ #endregion
+
+ public Hashtable Iterate () {
+ // TBD: Insert Exception handling here
+ NameValueCollection nvc = (NameValueCollection)
System.Configuration.ConfigurationSettings
+ .GetConfig ("system.drawing/codecs");
+ Hashtable codecs = new Hashtable (10);
+
+ for (int i=0; i<nvc.Count; i++) {
+ Guid clsid = new Guid (nvc.GetKey (i));
+ ImageFormat format = ClsidToImageFormat
(clsid);
+ ImageCodecInfo codec = ProcessOneCodec
(clsid, format.Guid, nvc[i]);
+ if (codec.FilenameExtension != null)
+ codecs [clsid] = codec;
+ }
+ return codecs;
+ }
+ }
+
+ class ReaderSpiIterator: BaseSpiIterator {
+ protected override java.util.Iterator
GetIterator(string mimeType) {
+ return
imageio.ImageIO.getImageReadersByMIMEType (mimeType);
+ }
+ protected override
javax.imageio.spi.ImageReaderWriterSpi GetNext(java.util.Iterator iter) {
+ imageio.ImageReader r = (imageio.ImageReader)
iter.next ();
+ return r.getOriginatingProvider ();
+ }
+ }
+
+ class WriterSpiIterator: BaseSpiIterator {
+ protected override java.util.Iterator
GetIterator(string mimeType) {
+ return
imageio.ImageIO.getImageWritersByMIMEType (mimeType);
+ }
+ protected override
javax.imageio.spi.ImageReaderWriterSpi GetNext(java.util.Iterator iter) {
+ imageio.ImageWriter w = (imageio.ImageWriter)
iter.next ();
+ return w.getOriginatingProvider ();
+ }
+ }
+ #endregion
+
+ #region Clsid and FormatID
+ static Guid BmpClsid = new Guid
("557cf400-1a04-11d3-9a73-0000f81ef32e");
+ static Guid JpegClsid = new Guid
("557cf401-1a04-11d3-9a73-0000f81ef32e");
+ static Guid GifClsid = new Guid
("557cf402-1a04-11d3-9a73-0000f81ef32e");
+ static Guid EmfClsid = new Guid
("557cf403-1a04-11d3-9a73-0000f81ef32e");
+ static Guid WmfClsid = new Guid
("557cf404-1a04-11d3-9a73-0000f81ef32e");
+ static Guid TiffClsid = new Guid
("557cf405-1a04-11d3-9a73-0000f81ef32e");
+ static Guid PngClsid = new Guid
("557cf406-1a04-11d3-9a73-0000f81ef32e");
+ static Guid IconClsid = new Guid
("557cf407-1a04-11d3-9a73-0000f81ef32e");
+
+ internal static ImageFormat MimeTypesToImageFormat (string []
mimeTypes) {
+ foreach (ImageCodecInfo codec in Decoders.Values)
+ for (int i=0; i<mimeTypes.Length; i++)
+ if (codec.MimeType == mimeTypes [i])
+ return new ImageFormat
(codec.FormatID);
+ return null;
+ }
+
+ internal static ImageFormat ClsidToImageFormat (Guid clsid) {
+ if (clsid.Equals (BmpClsid))
+ return ImageFormat.Bmp;
+ else if (clsid.Equals (JpegClsid))
+ return ImageFormat.Jpeg;
+ else if (clsid.Equals (GifClsid))
+ return ImageFormat.Gif;
+ else if (clsid.Equals (EmfClsid))
+ return ImageFormat.Emf;
+ else if (clsid.Equals (WmfClsid))
+ return ImageFormat.Wmf;
+ else if (clsid.Equals (TiffClsid))
+ return ImageFormat.Tiff;
+ else if (clsid.Equals (PngClsid))
+ return ImageFormat.Png;
+ else if (clsid.Equals (IconClsid))
+ return ImageFormat.Icon;
+ else
+ return null;
+ }
+
+ internal static Guid ImageFormatToClsid (ImageFormat format) {
+ if (format == null)
+ return Guid.Empty;
+
+ if (format.Guid.Equals (ImageFormat.Bmp.Guid))
+ return BmpClsid;
+ else if (format.Guid.Equals (ImageFormat.Jpeg.Guid))
+ return JpegClsid;
+ else if (format.Guid.Equals (ImageFormat.Gif))
+ return GifClsid;
+ else if (format.Guid.Equals (ImageFormat.Emf.Guid))
+ return EmfClsid;
+ else if (format.Guid.Equals (ImageFormat.Wmf.Guid))
+ return WmfClsid;
+ else if (format.Guid.Equals (ImageFormat.Tiff.Guid))
+ return TiffClsid;
+ else if (format.Guid.Equals (ImageFormat.Png.Guid))
+ return PngClsid;
+ else if (format.Guid.Equals (ImageFormat.Icon.Guid))
+ return IconClsid;
+ else
+ return Guid.Empty;
+ }
+ #endregion
+
+ #region Image read/write methods
+
+ public image.BufferedImage [] ReadImage() {
+ int imgNumber = 0;
+ ArrayList nativeObjects = new ArrayList();
+
+ while (true) {
+ try {
+ nativeObjects.Add(
ReadImage(imgNumber++) );
+ }
+ catch (java.lang.IndexOutOfBoundsException) {
+ break;
+ }
+ catch (java.io.IOException ex) {
+ throw new
System.IO.IOException(ex.Message, ex);
+ }
+ }
+ return (image.BufferedImage[])
nativeObjects.ToArray(typeof(image.BufferedImage));
+ }
+
+ public image.BufferedImage ReadImage(int frame) {
+ if (NativeStream == null)
+ throw new Exception("Input stream not
specified");
+
+ return NativeReader.read (frame);
+ }
+
+ public image.BufferedImage [] ReadThumbnails(int frame) {
+ // FIXME: seems to be incorrect on multiframe with
multi thumbnail
+ if (NativeReader.hasThumbnails(frame)) {
+
+ int tmbNumber =
NativeReader.getNumThumbnails(frame);
+ if (tmbNumber > 0) {
+ image.BufferedImage [] thumbnails = new
image.BufferedImage[ tmbNumber ];
+
+ for (int i = 0; i < tmbNumber; i++) {
+ thumbnails[i] =
NativeReader.readThumbnail(frame, i);
+ }
+ return thumbnails;
+ }
+ }
+ return null;
+ }
+
+ public void ReadImageMetadata(int index) {
+ if (NativeStream == null)
+ throw new Exception("Input stream not
specified");
+
+ imageio.metadata.IIOMetadata md =
NativeReader.getImageMetadata( index );
+
+ string [] formatNames = md.getMetadataFormatNames();
+ dom.Element rootNode = (dom.Element)
md.getAsTree(formatNames[0]);
+
+ MetadataDocument = new XmlDocument();
+ XmlConvert(rootNode, MetadataDocument);
+ }
+
+ public void WriteImage(image.BufferedImage bitmap) {
+ if (NativeStream == null)
+ throw new Exception("Output stream not
specified");
+
+ NativeWriter.write(bitmap);
+ }
+
+ public void WriteImage(image.BufferedImage [] bitmap) {
+ //FIXME: does not supports metadata and thumbnails for
now
+ if (bitmap.Length == 1) {
+ WriteImage(bitmap[0]);
+ }
+ else {
+ if (NativeWriter.canWriteSequence ()) {
+ NativeWriter.prepareWriteSequence
(null);
+
+ for (int i = 0; i < bitmap.Length; i++)
{
+ imageio.IIOImage iio = new
imageio.IIOImage ((image.BufferedImage)bitmap[i], null, null);
+ NativeWriter.writeToSequence
(iio, null);
+ }
+ NativeWriter.endWriteSequence ();
+ }
+ else
+ throw new ArgumentException();
+ }
+ }
+
+ #endregion
+
+ #region Extra properties
+
+ public float ImageHorizontalResolution {
+ get {return _imageHorizontalResolution;}
+ }
+ public float ImageVerticalResolution {
+ get {return _imageVerticalResolution;}
+ }
+
+ public ImageFormat ImageFormat {
+ get { return _imageFormat; }
+ }
+
+ public XmlDocument MetadataDocument {
+ get { return _metadataDocument; }
+ set {
+ if (value == null)
+ throw new ArgumentNullException();
+
+ _metadataDocument = value;
+ }
+ }
+
+ #endregion
+
+ #region Metadata parse
+
+ public void ParseMetadata() {
+ if (MetadataDocument == null)
+ ReadImageMetadata(0);
+
+ SetResolution();
+ }
+
+ protected void SetResolution() {
+ ResolutionConfigurationCollection rcc =
+ (ResolutionConfigurationCollection)
+
ConfigurationSettings.GetConfig("system.drawing/codecsmetadata");
+
+ if (rcc == null)
+ throw new ConfigurationException("Configuration
section codecsmetadata not found");
+
+ ResolutionConfiguration rc = rcc[
ImageFormat.ToString() ];
+
+ // Horizontal resolution
+ string xResPath = rc.XResPath;
+ string xRes;
+
+ if (xResPath == string.Empty)
+ xRes = rc.XResDefault;
+ else
+ xRes = GetValueFromMetadata(xResPath);
+
+ if ((xRes == null) || (xRes == string.Empty))
+ xRes = rc.XResDefault;
+
+ // Vertical resolution
+ string yResPath = rc.YResPath;
+ string yRes;
+
+ if (yResPath == string.Empty)
+ yRes = rc.YResDefault;
+ else
+ yRes = GetValueFromMetadata(yResPath);
+
+ if ((yRes == null) || (yRes == string.Empty))
+ yRes = rc.YResDefault;
+
+ // Resolution units
+ string resUnitsPath = rc.UnitsTypePath;
+ string resUnitsType;
+
+ if (resUnitsPath == string.Empty)
+ resUnitsType = rc.UnitsTypeDefault;
+ else
+ resUnitsType =
GetValueFromMetadata(resUnitsPath);
+
+ // Unit scale
+ string unitScale =
rc.UnitsScale[resUnitsType].ToString();
+
+ // Adjust resolution to its units
+ _imageHorizontalResolution = ParseFloatValue(xRes) *
ParseFloatValue(unitScale);
+ _imageVerticalResolution = ParseFloatValue(yRes) *
ParseFloatValue(unitScale);
+ }
+
+
+ protected string GetValueFromMetadata(string path) {
+ return
MetadataDocument.SelectSingleNode(path).InnerText;
+ }
+
+ private void XmlConvert(dom.Node jNode, XmlNode nNode) {
+ XmlDocument document = nNode.OwnerDocument;
+ if (document == null)
+ document = (XmlDocument)nNode;
+
+ XmlNode n = null;
+ switch (jNode.getNodeType()) {
+ case 1 :
+ n =
document.CreateNode(XmlNodeType.Element, jNode.getNodeName(),
jNode.getNamespaceURI());
+ break;
+
+ case 4 :
+ n =
document.CreateNode(XmlNodeType.CDATA, jNode.getNodeName(),
jNode.getNamespaceURI());
+ break;
+
+ default:
+ return;
+ }
+ //set value
+ n.InnerText = jNode.getNodeValue();
+ nNode.AppendChild( n );
+
+ //copy attributes
+ org.w3c.dom.NamedNodeMap nm = jNode.getAttributes();
+ for (int i=0; i<nm.getLength(); i++) {
+ XmlAttribute a = document.CreateAttribute(
nm.item(i).getNodeName() );
+ a.Value = nm.item(i).getNodeValue();
+ n.Attributes.Append( a );
+ }
+
+ //copy childs
+ org.w3c.dom.NodeList nl = jNode.getChildNodes();
+ for (int i=0; i<nl.getLength(); i++) {
+ XmlConvert(nl.item(i), n);
+ }
+ }
+
+ protected virtual float ParseFloatValue(string strValue) {
+ try {
+ if ((strValue != null) && (strValue != "")) {
+ int dividerPos = strValue.IndexOf("/");
+
+ if (dividerPos < 0) {
+ return float.Parse(strValue);
+ }
+ else {
+ return
float.Parse(strValue.Substring( 0, dividerPos )) /
+
float.Parse(strValue.Substring( dividerPos + 1 ));
+ }
+ }
+ return float.NaN;
+ }
+ catch (Exception) {
+ return float.NaN;
+ }
+ }
+
+ #endregion
+
+ }
+}
Modified:
trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodecInfo.jvm.cs
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodecInfo.jvm.cs
2005-09-07 10:33:21 UTC (rev 49627)
+++ trunk/mcs/class/System.Drawing/System.Drawing.Imaging/ImageCodecInfo.jvm.cs
2005-09-07 10:51:13 UTC (rev 49628)
@@ -41,6 +41,8 @@
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
+using Mainsoft.Drawing.Services;
+
using imageio = javax.imageio;
using spi = javax.imageio.spi;
@@ -61,197 +63,9 @@
private byte[][] signaturePatterns;
private int version;
- #region SpiIterators
- abstract class BaseSpiIterator {
- protected abstract java.util.Iterator GetIterator
(string mimeType);
- protected abstract spi.ImageReaderWriterSpi GetNext
(java.util.Iterator iter);
-
- #region ProcessOneCodec
- ImageCodecInfo ProcessOneCodec (Guid clsid, Guid
formatID, string mimeType) {
- ImageCodecInfo ici = new ImageCodecInfo ();
- ici.Clsid = clsid;
- ici.FormatID = formatID;
- ici.MimeType = mimeType;
- java.util.Iterator iter = GetIterator
(mimeType);
- while (iter.hasNext ()) {
- spi.ImageReaderWriterSpi rw = GetNext
(iter);
- try {
- ici.CodecName =
rw.getDescription (java.util.Locale.getDefault ());
- ici.DllName = null;
- foreach (string suffix in
rw.getFileSuffixes ()) {
- if
(ici.FilenameExtension != null)
-
ici.FilenameExtension += ";";
- ici.FilenameExtension
+= "*."+suffix;
- }
- ici.Flags =
ImageCodecFlags.Builtin|ImageCodecFlags.SupportBitmap;
- if (rw is spi.ImageReaderSpi) {
- ici.Flags |=
ImageCodecFlags.Decoder;
- if ((rw as
spi.ImageReaderSpi).getImageWriterSpiNames().Length != 0)
- ici.Flags |=
ImageCodecFlags.Encoder;
- }
- if (rw is spi.ImageWriterSpi) {
- ici.Flags |=
ImageCodecFlags.Encoder;
- if ((rw as
spi.ImageWriterSpi).getImageReaderSpiNames().Length != 0)
- ici.Flags |=
ImageCodecFlags.Decoder;
- }
- ici.FormatDescription =
string.Join(";",
- rw.getFormatNames());
- ici.Version =
(int)Convert.ToDouble(rw.getVersion ());
- break;
- }
- catch {
- }
- }
- return ici;
- }
- #endregion
-
- public Hashtable Iterate () {
- // TBD: Insert Exception handling here
- NameValueCollection nvc = (NameValueCollection)
System.Configuration.ConfigurationSettings
- .GetConfig ("system.drawing/codecs");
- Hashtable codecs = new Hashtable (10);
-
- for (int i=0; i<nvc.Count; i++) {
- Guid clsid = new Guid (nvc.GetKey (i));
- ImageFormat format = ClsidToImageFormat
(clsid);
- string [] codecMimeTypes =
nvc[i].Split(',');
- for (int j = 0; j <
codecMimeTypes.Length; j++)
- {
- ImageCodecInfo codec =
ProcessOneCodec (clsid, format.Guid, codecMimeTypes[j].Trim());
- if (codec.FilenameExtension !=
null)
- codecs [clsid] = codec;
- }
- }
- return codecs;
- }
- }
-
- class ReaderSpiIterator: BaseSpiIterator {
- protected override java.util.Iterator
GetIterator(string mimeType) {
- return
imageio.ImageIO.getImageReadersByMIMEType (mimeType);
- }
- protected override
javax.imageio.spi.ImageReaderWriterSpi GetNext(java.util.Iterator iter) {
- imageio.ImageReader r = (imageio.ImageReader)
iter.next ();
- return r.getOriginatingProvider ();
- }
- }
-
- class WriterSpiIterator: BaseSpiIterator {
- protected override java.util.Iterator
GetIterator(string mimeType) {
- return
imageio.ImageIO.getImageWritersByMIMEType (mimeType);
- }
- protected override
javax.imageio.spi.ImageReaderWriterSpi GetNext(java.util.Iterator iter) {
- imageio.ImageWriter w = (imageio.ImageWriter)
iter.next ();
- return w.getOriginatingProvider ();
- }
- }
- #endregion
-
- #region Clsid and FormatID
- static Guid BmpClsid = new Guid
("557cf400-1a04-11d3-9a73-0000f81ef32e");
- static Guid JpegClsid = new Guid
("557cf401-1a04-11d3-9a73-0000f81ef32e");
- static Guid GifClsid = new Guid
("557cf402-1a04-11d3-9a73-0000f81ef32e");
- static Guid EmfClsid = new Guid
("557cf403-1a04-11d3-9a73-0000f81ef32e");
- static Guid WmfClsid = new Guid
("557cf404-1a04-11d3-9a73-0000f81ef32e");
- static Guid TiffClsid = new Guid
("557cf405-1a04-11d3-9a73-0000f81ef32e");
- static Guid PngClsid = new Guid
("557cf406-1a04-11d3-9a73-0000f81ef32e");
- static Guid IconClsid = new Guid
("557cf407-1a04-11d3-9a73-0000f81ef32e");
-
- internal static ImageFormat ClsidToImageFormat (Guid clsid)
- {
- if (clsid.Equals (BmpClsid))
- return ImageFormat.Bmp;
- else if (clsid.Equals (JpegClsid))
- return ImageFormat.Jpeg;
- else if (clsid.Equals (GifClsid))
- return ImageFormat.Gif;
- else if (clsid.Equals (EmfClsid))
- return ImageFormat.Emf;
- else if (clsid.Equals (WmfClsid))
- return ImageFormat.Wmf;
- else if (clsid.Equals (TiffClsid))
- return ImageFormat.Tiff;
- else if (clsid.Equals (PngClsid))
- return ImageFormat.Png;
- else if (clsid.Equals (IconClsid))
- return ImageFormat.Icon;
- else
- return null;
- }
-
- internal static Guid ImageFormatToClsid (ImageFormat format)
- {
- if (format == null)
- return Guid.Empty;
-
- if (format.Guid.Equals (ImageFormat.Bmp.Guid))
- return BmpClsid;
- else if (format.Guid.Equals (ImageFormat.Jpeg.Guid))
- return JpegClsid;
- else if (format.Guid.Equals (ImageFormat.Gif))
- return GifClsid;
- else if (format.Guid.Equals (ImageFormat.Emf.Guid))
- return EmfClsid;
- else if (format.Guid.Equals (ImageFormat.Wmf.Guid))
- return WmfClsid;
- else if (format.Guid.Equals (ImageFormat.Tiff.Guid))
- return TiffClsid;
- else if (format.Guid.Equals (ImageFormat.Png.Guid))
- return PngClsid;
- else if (format.Guid.Equals (ImageFormat.Icon.Guid))
- return IconClsid;
- else
- return Guid.Empty;
- }
- #endregion
-
- #region Internals
- internal static Hashtable Decoders {
- get {
- const string MYNAME =
"System.Drawing.Imaging.ImageCodecInfo.decoders";
- Hashtable o = (Hashtable)
AppDomain.CurrentDomain.GetData (MYNAME);
- if (o != null)
- return o;
- o = new ReaderSpiIterator ().Iterate ();
- AppDomain.CurrentDomain.SetData (MYNAME, o);
- return o;
- }
- }
-
- internal static Hashtable Encoders {
- get {
- const string MYNAME =
"System.Drawing.Imaging.ImageCodecInfo.encoders";
- Hashtable o = (Hashtable)
AppDomain.CurrentDomain.GetData (MYNAME);
- if (o != null)
- return o;
- o = new WriterSpiIterator ().Iterate ();
- AppDomain.CurrentDomain.SetData (MYNAME, o);
- return o;
- }
- }
-
- internal static ImageCodecInfo FindEncoder (Guid clsid) {
- return (ImageCodecInfo) Encoders [clsid];
- }
-
- internal static ImageCodecInfo FindDecoder (Guid clsid) {
- return (ImageCodecInfo) Decoders [clsid];
- }
-
- internal static string ImageFormatToMimeType (ImageFormat
format) {
- //FIXME: this code assumes that any encoder has
corresponding decoder
- Guid clsid = ImageFormatToClsid (format);
- ImageCodecInfo codec = FindDecoder (clsid);
- if (codec == null)
- return null;
- return codec.MimeType;
- }
- #endregion
-
public static ImageCodecInfo[] GetImageDecoders ()
{
- Hashtable oldInfo = Decoders;
+ Hashtable oldInfo = ImageCodec.Decoders;
ImageCodecInfo [] newInfo = new ImageCodecInfo
[oldInfo.Count];
int i=0;
foreach (ImageCodecInfo codec in oldInfo.Values) {
@@ -272,12 +86,12 @@
return newInfo;
}
- private ImageCodecInfo () {
+ internal ImageCodecInfo () {
}
public static ImageCodecInfo[] GetImageEncoders ()
{
- Hashtable oldInfo = Encoders;
+ Hashtable oldInfo = ImageCodec.Encoders;
ImageCodecInfo [] newInfo = new ImageCodecInfo
[oldInfo.Count];
int i=0;
foreach (ImageCodecInfo codec in oldInfo.Values) {
Modified: trunk/mcs/class/System.Drawing/System.Drawing.vmwcsproj
===================================================================
--- trunk/mcs/class/System.Drawing/System.Drawing.vmwcsproj 2005-09-07
10:33:21 UTC (rev 49627)
+++ trunk/mcs/class/System.Drawing/System.Drawing.vmwcsproj 2005-09-07
10:51:13 UTC (rev 49628)
@@ -9,6 +9,7 @@
<Reference Name="System" AssemblyName="System"
HintPath="..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"/>
<Reference Name="rt" AssemblyName="rt"
HintPath="..\lib\j2sdk1.4.1\rt.dll" Private="False"/>
<Reference Name="J2SE.Helpers"
AssemblyName="J2SE.Helpers" HintPath="..\lib\J2SE.Helpers.dll" Private="False"/>
+ <Reference Name="System.Xml"
AssemblyName="System.Xml"
HintPath="..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Xml.dll"
Private="False"/>
</References>
</Build>
<Files>
@@ -17,6 +18,9 @@
<File RelPath="MonoTODOAttribute.cs"
Link="..\..\build\common\MonoTODOAttribute.cs" SubType="Code"
BuildAction="Compile"/>
<File RelPath="Assembly\AssemblyInfo.cs"
SubType="Code" BuildAction="Compile"/>
<File RelPath="Assembly\Consts.cs.in"
Link="..\..\build\common\Consts.cs.in" SubType="Code" BuildAction="Compile"/>
+ <File
RelPath="Mainsoft.Drawing.Configuration.jvm\ResolutionConfiguration.cs"
SubType="Code" BuildAction="Compile"/>
+ <File
RelPath="Mainsoft.Drawing.Configuration.jvm\ResolutionConfigurationCollection.cs"
SubType="Code" BuildAction="Compile"/>
+ <File
RelPath="Mainsoft.Drawing.Configuration.jvm\ResolutionConfigurationHandler.cs"
SubType="Code" BuildAction="Compile"/>
<File
RelPath="System.Drawing\AdvancedStroke.jvm.cs" SubType="Code"
BuildAction="Compile"/>
<File
RelPath="System.Drawing\BasicShape.jvm.cs" SubType="Code"
BuildAction="Compile"/>
<File RelPath="System.Drawing\Bitmap.jvm.cs"
SubType="Code" BuildAction="Compile"/>
@@ -125,6 +129,7 @@
<File
RelPath="System.Drawing.Imaging\EncoderValue.cs" SubType="Code"
BuildAction="Compile"/>
<File
RelPath="System.Drawing.Imaging\FrameDimension.cs" SubType="Code"
BuildAction="Compile"/>
<File
RelPath="System.Drawing.Imaging\ImageAttributes.jvm.cs" SubType="Code"
BuildAction="Compile"/>
+ <File
RelPath="System.Drawing.Imaging\ImageCodec.jvm.cs" SubType="Code"
BuildAction="Compile"/>
<File
RelPath="System.Drawing.Imaging\ImageCodecFlags.cs" SubType="Code"
BuildAction="Compile"/>
<File
RelPath="System.Drawing.Imaging\ImageCodecInfo.jvm.cs" SubType="Code"
BuildAction="Compile"/>
<File
RelPath="System.Drawing.Imaging\ImageFlags.cs" SubType="Code"
BuildAction="Compile"/>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches