/[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 106 - (show 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 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 namespace gr2lib.core.coretypes.implementation
9 {
10 public class Image : IImage
11 {
12
13
14
15 public Image()
16 {
17 this.MIPLevels = new List<MIPLevel>();
18 //this.NativePointer = IntPtr.Zero;
19 }
20
21 internal static Image ReadFromMemory(IntPtr pointer)
22 {
23 try
24 {
25 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 }
31 catch (Exception ex)
32 {
33 StackTrace st = new StackTrace(true);
34 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
35 Granny2ExceptionWriter.WriteToConsole(ex,st);
36 #endif
37 return default(Image);
38 }
39 }
40
41 internal static Image ReadFromNative(native.Image native)
42 {
43 try
44 {
45 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 }
61 catch (Exception ex)
62 {
63 StackTrace st = new StackTrace(true);
64 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
65 Granny2ExceptionWriter.WriteToConsole(ex,st);
66 #endif
67 return default(Image);
68 }
69 }
70
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 }
81 }

  ViewVC Help
Powered by ViewVC 1.1.22