/[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

revision 79 by william, Thu Jul 15 21:50:56 2010 UTC revision 95 by william, Sat Jul 17 05:10:22 2010 UTC
# Line 3  using System.Collections.Generic; Line 3  using System.Collections.Generic;
3  using System.Text;  using System.Text;
4  using gr2lib.core.helpers;  using gr2lib.core.helpers;
5  using gr2lib.core.interfaces;  using gr2lib.core.interfaces;
6    using System.Diagnostics;
7  namespace gr2lib.core.coretypes.implementation  namespace gr2lib.core.coretypes.implementation
8  {  {
9      public class Image : IImage      public class Image : IImage
# Line 13  namespace gr2lib.core.coretypes.implemen Line 14  namespace gr2lib.core.coretypes.implemen
14          public Image()          public Image()
15          {          {
16              this.MIPLevels = new List<MIPLevel>();              this.MIPLevels = new List<MIPLevel>();
17              this.NativePointer = IntPtr.Zero;              //this.NativePointer = IntPtr.Zero;
18          }          }
19    
20          internal static Image ReadFromMemory(IntPtr pointer)          internal static Image ReadFromMemory(IntPtr pointer)
21          {          {
22                try
23                {
24              if (pointer == IntPtr.Zero) return null;              if (pointer == IntPtr.Zero) return null;
25              native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);              native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
26              Image managed = ReadFromNative(native);              Image managed = ReadFromNative(native);
27              managed.NativePointer = pointer;              managed.NativePointer = pointer;
28              return managed;              return managed;
29                }
30                catch (Exception ex)
31                {
32                    StackTrace st = new StackTrace(true);
33                    Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
34                    return default(Image);
35                }
36          }          }
37    
38          internal static Image ReadFromNative(native.Image native)          internal static Image ReadFromNative(native.Image native)
39          {          {
40              Image managed = new Image();              try
             IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);  
             int length = miplevels.Length;  
             managed.MIPLevels = new List<MIPLevel>(length);  
             foreach (IntPtr ptr in miplevels)  
41              {              {
42                  managed.MIPLevels.Add(new MIPLevel());                  Image managed = new Image();
43                    IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
44                    int length = miplevels.Length;
45                    managed.MIPLevels = new List<MIPLevel>(length);
46                    foreach (IntPtr ptr in miplevels)
47                    {
48                        MIPLevel _tmp = new MIPLevel();
49                        _tmp.NativePointer = ptr;
50                        managed.MIPLevels.Add(_tmp);
51                    }
52                    for (int i = 0; i < length; i++)
53                    {
54                        managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
55                    }
56                    return managed;
57              }              }
58              for (int i = 0; i < length; i++)              catch (Exception ex)
59              {              {
60                  managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);                  StackTrace st = new StackTrace(true);
61                    Console.WriteLine(st.ToString() + "\n\n" + "Stack Trace: \n" + ex.ToString());
62                    return default(Image);
63              }              }
             return managed;  
64          }          }
65    
66          #region INativePointer Members          #region INativePointer Members

Legend:
Removed from v.79  
changed lines
  Added in v.95

  ViewVC Help
Powered by ViewVC 1.1.22