/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Image.cs
ViewVC logotype

Diff of /trunk/gr2lib/core/coretypes/implementation/Image.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib/core/coretypes/implementation/Image.cs	2010/07/15 14:31:59	73
+++ trunk/gr2lib/core/coretypes/implementation/Image.cs	2010/07/17 13:54:18	102
@@ -2,45 +2,79 @@
 using System.Collections.Generic;
 using System.Text;
 using gr2lib.core.helpers;
-
+using gr2lib.core.interfaces;
+using System.Diagnostics;
 namespace gr2lib.core.coretypes.implementation
 {
-    public class Image
+    public class Image : IImage
     {
-        public List<MIPLevel> MIPLevels;
+        
 
-        public IntPtr NativePointer;
 
         public Image()
         {
             this.MIPLevels = new List<MIPLevel>();
-            this.NativePointer = IntPtr.Zero;
+            //this.NativePointer = IntPtr.Zero;
         }
 
         internal static Image ReadFromMemory(IntPtr pointer)
         {
+            try 
+            { 
             if (pointer == IntPtr.Zero) return null;
             native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
             Image managed = ReadFromNative(native);
             managed.NativePointer = pointer;
             return managed;
+            }
+            catch
+            {
+                StackTrace st = new StackTrace(true);
+#if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
+                Console.WriteLine(st.ToString());
+#endif
+                return default(Image);
+            }
         }
 
         internal static Image ReadFromNative(native.Image native)
         {
-            Image managed = new Image();
-            IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
-            int length = miplevels.Length;
-            managed.MIPLevels = new List<MIPLevel>(length);
-            foreach (IntPtr ptr in miplevels)
+            try
             {
-                managed.MIPLevels.Add(new MIPLevel());
+                Image managed = new Image();
+                IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
+                int length = miplevels.Length;
+                managed.MIPLevels = new List<MIPLevel>(length);
+                foreach (IntPtr ptr in miplevels)
+                {
+                    MIPLevel _tmp = new MIPLevel();
+                    _tmp.NativePointer = ptr;
+                    managed.MIPLevels.Add(_tmp);
+                }
+                for (int i = 0; i < length; i++)
+                {
+                    managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
+                }
+                return managed;
             }
-            for (int i = 0; i < length; i++)
+            catch
             {
-                managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
+                StackTrace st = new StackTrace(true);
+#if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
+                Console.WriteLine(st.ToString());
+#endif
+                return default(Image);
             }
-            return managed;
         }
+
+        #region INativePointer Members
+        private IntPtr _NativePointer;
+        public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
+        #endregion
+
+        #region IImage Members
+        private List<MIPLevel> _MIPLevels;
+        public List<MIPLevel> MIPLevels { get { return _MIPLevels; } set { _MIPLevels = value; } }
+        #endregion
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22