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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 102 - (hide annotations) (download)
Sat Jul 17 13:54:18 2010 UTC (9 years, 6 months ago) by william
File size: 2557 byte(s)
add compiler directive to write exceptions to console or not

1 william 72 using System;
2     using System.Collections.Generic;
3     using System.Text;
4     using gr2lib.core.helpers;
5 william 79 using gr2lib.core.interfaces;
6 william 95 using System.Diagnostics;
7 william 72 namespace gr2lib.core.coretypes.implementation
8     {
9 william 79 public class Image : IImage
10 william 72 {
11 william 79
12 william 72
13    
14 william 73 public Image()
15     {
16     this.MIPLevels = new List<MIPLevel>();
17 william 83 //this.NativePointer = IntPtr.Zero;
18 william 73 }
19    
20 william 72 internal static Image ReadFromMemory(IntPtr pointer)
21     {
22 william 86 try
23     {
24 william 72 if (pointer == IntPtr.Zero) return null;
25     native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
26     Image managed = ReadFromNative(native);
27     managed.NativePointer = pointer;
28     return managed;
29 william 86 }
30 william 102 catch
31 william 86 {
32 william 95 StackTrace st = new StackTrace(true);
33 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
34     Console.WriteLine(st.ToString());
35     #endif
36 william 86 return default(Image);
37     }
38 william 72 }
39    
40     internal static Image ReadFromNative(native.Image native)
41     {
42 william 86 try
43 william 72 {
44 william 86 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 william 72 }
60 william 102 catch
61 william 72 {
62 william 95 StackTrace st = new StackTrace(true);
63 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
64     Console.WriteLine(st.ToString());
65     #endif
66 william 86 return default(Image);
67 william 72 }
68     }
69 william 79
70     #region INativePointer Members
71     private IntPtr _NativePointer;
72     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
73     #endregion
74    
75     #region IImage Members
76     private List<MIPLevel> _MIPLevels;
77     public List<MIPLevel> MIPLevels { get { return _MIPLevels; } set { _MIPLevels = value; } }
78     #endregion
79 william 72 }
80     }

  ViewVC Help
Powered by ViewVC 1.1.22