/[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 186 - (hide annotations) (download)
Sat Jul 24 02:23:18 2010 UTC (10 years ago) by william
File size: 3309 byte(s)
continue to add xml documentation

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 119 using gr2lib.core.ui.helpers;
9 william 72 namespace gr2lib.core.coretypes.implementation
10     {
11 william 186 /// <summary>
12     /// Image class
13     /// </summary>
14 william 119 public class Image : GrannyRigParentResource,IImage
15 william 72 {
16 william 186 /// <summary>
17     /// get string representation
18     /// </summary>
19     /// <returns></returns>
20 william 141 public override string ToString()
21     {
22     return base.ToString();
23     }
24 william 72
25 william 186 /// <summary>
26     /// default constructor
27     /// </summary>
28 william 141 public Image() : base("Image Data")
29 william 73 {
30     this.MIPLevels = new List<MIPLevel>();
31 william 83 //this.NativePointer = IntPtr.Zero;
32 william 73 }
33    
34 william 72 internal static Image ReadFromMemory(IntPtr pointer)
35     {
36 william 86 try
37     {
38 william 72 if (pointer == IntPtr.Zero) return null;
39     native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
40     Image managed = ReadFromNative(native);
41     managed.NativePointer = pointer;
42     return managed;
43 william 86 }
44 william 106 catch (Exception ex)
45 william 86 {
46 william 95 StackTrace st = new StackTrace(true);
47 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
48 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
49 william 102 #endif
50 william 86 return default(Image);
51     }
52 william 72 }
53    
54     internal static Image ReadFromNative(native.Image native)
55     {
56 william 86 try
57 william 72 {
58 william 86 Image managed = new Image();
59     IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
60     int length = miplevels.Length;
61     managed.MIPLevels = new List<MIPLevel>(length);
62     foreach (IntPtr ptr in miplevels)
63     {
64     MIPLevel _tmp = new MIPLevel();
65     _tmp.NativePointer = ptr;
66     managed.MIPLevels.Add(_tmp);
67     }
68     for (int i = 0; i < length; i++)
69     {
70     managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
71     }
72     return managed;
73 william 72 }
74 william 106 catch (Exception ex)
75 william 72 {
76 william 95 StackTrace st = new StackTrace(true);
77 william 102 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
78 william 106 Granny2ExceptionWriter.WriteToConsole(ex,st);
79 william 102 #endif
80 william 86 return default(Image);
81 william 72 }
82     }
83 william 79
84     #region INativePointer Members
85     private IntPtr _NativePointer;
86 william 181 /// <summary>
87     /// When used in a derived class, gets the native pointer for this instance
88     /// </summary>
89 william 79 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
90     #endregion
91    
92 william 181
93 william 79 #region IImage Members
94     private List<MIPLevel> _MIPLevels;
95 william 186 /// <summary>
96     /// Get the miplevels associated with this instance
97     /// </summary>
98 william 79 public List<MIPLevel> MIPLevels { get { return _MIPLevels; } set { _MIPLevels = value; } }
99     #endregion
100 william 72 }
101     }

  ViewVC Help
Powered by ViewVC 1.1.22