* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Drawing / System.Drawing / Bitmap.jvm.cs
index 47b9091cbbf3a3f2f6980cecd0873c02a9994aff..90db022df0d0692792abcf88ad54ad0601203a19 100644 (file)
@@ -29,6 +29,7 @@ namespace System.Drawing
                        base.Initialize( orig, false );
                }
 
+               [MonoTODO]
                private Bitmap (SerializationInfo info, StreamingContext context) {
                        throw new NotImplementedException ();
                }
@@ -51,6 +52,7 @@ namespace System.Drawing
                internal Bitmap (java.awt.Image nativeObject, ImageFormat format)
                        :base (nativeObject, format) {}
 
+               [MonoTODO]
                private Bitmap (java.awt.Image nativeObject, ImageFormat format, PixelFormat pixFormat)
                        :this (nativeObject, format) {
                        if (pixFormat != this.PixelFormat)
@@ -73,9 +75,11 @@ namespace System.Drawing
                public Bitmap (string filename) 
                        :this (filename, false) {}
 
+               [MonoTODO]
                public Bitmap (Stream stream, bool useIcm)
                        :this (stream, useIcm, null) {}
 
+               [MonoTODO]
                public Bitmap (string filename, bool useIcm)
                        :this (filename, useIcm, null) {}
 
@@ -86,11 +90,11 @@ namespace System.Drawing
                }
 
                internal Bitmap (string filename, bool useIcm, ImageFormat format) {
-                       // TBD: useIcm param
-                       java.io.File file = vmw.common.IOUtils.getJavaFile (filename);
-                       if (!file.exists ())
-                                throw new System.IO.FileNotFoundException (filename);
-                       Initialize (new stream.FileImageInputStream (file), format);
+                       using(FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
+                               // TBD: useIcm param
+                               io.InputStream jis = vmw.common.IOUtils.ToInputStream (stream);
+                               Initialize (new stream.MemoryCacheImageInputStream (jis), format);
+                       }
                }
 
                public Bitmap (Type type, string resource) {
@@ -103,6 +107,7 @@ namespace System.Drawing
                        }
                }
 #if INTPTR_SUPPORT
+               [MonoTODO]
                public Bitmap (int width, int height, int stride, PixelFormat format, IntPtr scan0)
                {                                               
                        throw new NotImplementedException();                    
@@ -150,14 +155,6 @@ namespace System.Drawing
                protected override void InternalSave (stream.ImageOutputStream output, Guid clsid) {
 
                        ImageCodec ic = ImageCodec.CreateWriter( clsid );
-
-                       // .net saves in png if cannot find requested encoder. act id 316563
-                       if (ic == null)
-                               ic = ImageCodec.CreateWriter( ImageFormat.Png );
-
-                       if (ic == null)
-                               throw new NotSupportedException("The requested format encoder is not supported");
-
                        using (ic) {
 
                                PlainImage plainImage = CurrentImage;
@@ -257,23 +254,23 @@ namespace System.Drawing
                
                public Bitmap Clone (RectangleF rect, PixelFormat pixFormat)
                {
-                       PlainImage plainImage = CurrentImage.Clone(false);\r
-                       BufferedImage clone = new BufferedImage( (int)rect.Width, (int)rect.Height, ToBufferedImageFormat( pixFormat ) );\r
-                       awt.Graphics2D g = clone.createGraphics();\r
-                       try {\r
-                               g.drawImage( NativeObject, -(int)rect.X, -(int)rect.Y, null );\r
-                       }\r
-                       finally {\r
-                               g.dispose();\r
-                       }\r
-\r
-                       plainImage.NativeImage = clone;\r
-                       return new Bitmap(plainImage);\r
+                       PlainImage plainImage = CurrentImage.Clone(false);
+                       BufferedImage clone = new BufferedImage( (int)rect.Width, (int)rect.Height, ToBufferedImageFormat( pixFormat ) );
+                       awt.Graphics2D g = clone.createGraphics();
+                       try {
+                               g.drawImage( NativeObject, -(int)rect.X, -(int)rect.Y, null );
+                       }
+                       finally {
+                               g.dispose();
+                       }
+
+                       plainImage.NativeImage = clone;
+                       return new Bitmap(plainImage);
                }
                #endregion
 
                #region LockBits
-               // TBD: implement this
+               [MonoTODO]
                public BitmapData LockBits (Rectangle rect, ImageLockMode flags, PixelFormat format) {
                        throw new NotImplementedException();
                }
@@ -282,15 +279,17 @@ namespace System.Drawing
                #region MakeTransparent
                public void MakeTransparent ()
                {
-                       Color clr = GetPixel(0,0);                      
+                       Color clr = Color.FromArgb(0,0,0);                      
                        MakeTransparent (clr);
                }
 
                public void MakeTransparent (Color transparentColor)
                {
-                       byte A = transparentColor.A;
                        image.WritableRaster raster = NativeObject.getRaster();
                        int numBands  = raster.getNumBands();
+                       if (numBands != 4)
+                               return;
+
                        int maxWidth  = raster.getWidth() + raster.getMinX();
                        int maxHeight = raster.getHeight() + raster.getMinY();
                        int[] srcPix  = new int[numBands];
@@ -298,12 +297,11 @@ namespace System.Drawing
                        for (int y = raster.getMinY(); y < maxHeight; y++) {
                                for (int x = raster.getMinX(); x < maxWidth; x++) {
                                        /*srcPix =*/ raster.getPixel(x, y, srcPix);
-                                       for (int z = 0; z < numBands; z++) {
-                                               int argb = srcPix[z];
-                                               if ((uint)argb >> 24 == A) {
-                                                       argb &= 0x00FFFFFF;
-                                                       srcPix[z] = argb;
-                                               }
+                                       if (srcPix[0] == transparentColor.R &&
+                                               srcPix[1] == transparentColor.G &&
+                                               srcPix[2] == transparentColor.B) {
+                                               srcPix[3] = 0;
+                                               raster.setPixel(x, y, srcPix);
                                        }
                                }
                        }
@@ -319,7 +317,7 @@ namespace System.Drawing
                #endregion 
 
                #region UnlockBits
-               // TBD: implement this
+               [MonoTODO]
                public void UnlockBits (BitmapData bitmap_data)
                {
                        throw new NotImplementedException();
@@ -387,26 +385,31 @@ namespace System.Drawing
                #endregion
 
 #if INTPTR_SUPPORT
+               [MonoTODO]
                public static Bitmap FromHicon (IntPtr hicon)
                {       
                        throw new NotImplementedException();
                }
 
+               [MonoTODO]
                public static Bitmap FromResource (IntPtr hinstance, string bitmapName) //TBD: Untested
                {
                        throw new NotImplementedException();
                }
 
+               [MonoTODO]
                public IntPtr GetHbitmap ()
                {
                        throw new NotImplementedException();
                }
 
+               [MonoTODO]
                public IntPtr GetHbitmap (Color background)
                {
                        throw new NotImplementedException();
                }
 
+               [MonoTODO]
                public IntPtr GetHicon ()
                {
                        throw new NotImplementedException();