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

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 using gr2lib.core.exceptions;
8 using gr2lib.core.ui.helpers;
9 namespace gr2lib.core.coretypes.implementation
10 {
11 /// <summary>
12 /// Image class
13 /// </summary>
14 public class Image : GrannyRigParentResource,IImage
15 {
16 /// <summary>
17 /// get string representation
18 /// </summary>
19 /// <returns></returns>
20 public override string ToString()
21 {
22 return base.ToString();
23 }
24
25 /// <summary>
26 /// default constructor
27 /// </summary>
28 public Image() : base("Image Data")
29 {
30 this.MIPLevels = new List<MIPLevel>();
31 //this.NativePointer = IntPtr.Zero;
32 }
33
34 internal static Image ReadFromMemory(IntPtr pointer)
35 {
36 try
37 {
38 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 }
44 catch (Exception ex)
45 {
46 StackTrace st = new StackTrace(true);
47 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
48 Granny2ExceptionWriter.WriteToConsole(ex,st);
49 #endif
50 return default(Image);
51 }
52 }
53
54 internal static Image ReadFromNative(native.Image native)
55 {
56 try
57 {
58 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 }
74 catch (Exception ex)
75 {
76 StackTrace st = new StackTrace(true);
77 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
78 Granny2ExceptionWriter.WriteToConsole(ex,st);
79 #endif
80 return default(Image);
81 }
82 }
83
84 #region INativePointer Members
85 private IntPtr _NativePointer;
86 /// <summary>
87 /// When used in a derived class, gets the native pointer for this instance
88 /// </summary>
89 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
90 #endregion
91
92
93 #region IImage Members
94 private List<MIPLevel> _MIPLevels;
95 /// <summary>
96 /// Get the miplevels associated with this instance
97 /// </summary>
98 public List<MIPLevel> MIPLevels { get { return _MIPLevels; } set { _MIPLevels = value; } }
99 #endregion
100 }
101 }

  ViewVC Help
Powered by ViewVC 1.1.22