/[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 106 - (hide annotations) (download)
Sat Jul 17 14:52:37 2010 UTC (10 years, 9 months ago) by william
File size: 2642 byte(s)
implement Granny2ExceptionWriter

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 106 using gr2lib.core.exceptions;
8 william 72 namespace gr2lib.core.coretypes.implementation
9     {
10 william 79 public class Image : IImage
11 william 72 {
12 william 79
13 william 72
14    
15 william 73 public Image()
16     {
17     this.MIPLevels = new List<MIPLevel>();
18 william 83 //this.NativePointer = IntPtr.Zero;
19 william 73 }
20    
21 william 72 internal static Image ReadFromMemory(IntPtr pointer)
22     {
23 william 86 try
24     {
25 william 72 if (pointer == IntPtr.Zero) return null;
26     native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
27     Image managed = ReadFromNative(native);
28     managed.NativePointer = pointer;
29     return managed;
30 william 86 }
31 william 106 catch (Exception ex)
32 william 86 {
33 william 95 StackTrace st = new StackTrace(true);
34 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
35 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
36 william 102 #endif
37 william 86 return default(Image);
38     }
39 william 72 }
40    
41     internal static Image ReadFromNative(native.Image native)
42     {
43 william 86 try
44 william 72 {
45 william 86 Image managed = new Image();
46     IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
47     int length = miplevels.Length;
48     managed.MIPLevels = new List<MIPLevel>(length);
49     foreach (IntPtr ptr in miplevels)
50     {
51     MIPLevel _tmp = new MIPLevel();
52     _tmp.NativePointer = ptr;
53     managed.MIPLevels.Add(_tmp);
54     }
55     for (int i = 0; i < length; i++)
56     {
57     managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
58     }
59     return managed;
60 william 72 }
61 william 106 catch (Exception ex)
62 william 72 {
63 william 95 StackTrace st = new StackTrace(true);
64 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
65 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
66 william 102 #endif
67 william 86 return default(Image);
68 william 72 }
69     }
70 william 79
71     #region INativePointer Members
72     private IntPtr _NativePointer;
73     public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
74     #endregion
75    
76     #region IImage Members
77     private List<MIPLevel> _MIPLevels;
78     public List<MIPLevel> MIPLevels { get { return _MIPLevels; } set { _MIPLevels = value; } }
79     #endregion
80 william 72 }
81     }

  ViewVC Help
Powered by ViewVC 1.1.22