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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using gr2lib.core.helpers;
5 using gr2lib.core.interfaces;
6 using System.Diagnostics;
7 namespace gr2lib.core.coretypes.implementation
8 {
9 public class Image : IImage
10 {
11
12
13
14 public Image()
15 {
16 this.MIPLevels = new List<MIPLevel>();
17 //this.NativePointer = IntPtr.Zero;
18 }
19
20 internal static Image ReadFromMemory(IntPtr pointer)
21 {
22 try
23 {
24 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 }
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)
41 {
42 try
43 {
44 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 catch
61 {
62 StackTrace st = new StackTrace(true);
63 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
64 Console.WriteLine(st.ToString());
65 #endif
66 return default(Image);
67 }
68 }
69
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 }
80 }

  ViewVC Help
Powered by ViewVC 1.1.22