/[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 102 by william, Sat Jul 17 13:54:18 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
31                {
32                    StackTrace st = new StackTrace(true);
33    #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
34                    Console.WriteLine(st.ToString());
35    #endif
36                    return default(Image);
37                }
38          }          }
39    
40          internal static Image ReadFromNative(native.Image native)          internal static Image ReadFromNative(native.Image native)
41          {          {
42              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)  
43              {              {
44                  managed.MIPLevels.Add(new MIPLevel());                  Image managed = new Image();
45                    IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
46                    int length = miplevels.Length;
47                    managed.MIPLevels = new List<MIPLevel>(length);
48                    foreach (IntPtr ptr in miplevels)
49                    {
50                        MIPLevel _tmp = new MIPLevel();
51                        _tmp.NativePointer = ptr;
52                        managed.MIPLevels.Add(_tmp);
53                    }
54                    for (int i = 0; i < length; i++)
55                    {
56                        managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
57                    }
58                    return managed;
59              }              }
60              for (int i = 0; i < length; i++)              catch
61              {              {
62                  managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);                  StackTrace st = new StackTrace(true);
63    #if  ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
64                    Console.WriteLine(st.ToString());
65    #endif
66                    return default(Image);
67              }              }
             return managed;  
68          }          }
69    
70          #region INativePointer Members          #region INativePointer Members

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

  ViewVC Help
Powered by ViewVC 1.1.22