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

Contents of /trunk/gr2lib/core/coretypes/implementation/MIPLevel.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: 3159 byte(s)
add compiler directive to write exceptions to console or not

1 //#define READ_PIXELS_FROM_MEMORY // when defined will enable reading the Pixels from the data in the pointer, else initialize to default pixel
2 using System;
3 using System.Collections.Generic;
4 using System.Text;
5 using gr2lib.core.helpers;
6 using gr2lib.core.interfaces;
7 using System.Diagnostics;
8 namespace gr2lib.core.coretypes.implementation
9 {
10 public class MIPLevel : IMIPLevel
11 {
12 public MIPLevel()
13 {
14 this.Stride = 0;
15 //this.Pixels = new PixelList();
16 this.Pixels = new List<Pixel>();
17 //this.NativePointer = IntPtr.Zero;
18 }
19
20 internal static MIPLevel ReadFromMemory(IntPtr pointer)
21 {
22 try
23 {
24 if (pointer == IntPtr.Zero) return null;
25 native.MIPLevel native = Helpers.ReadFromMemory<native.MIPLevel>(pointer);
26 MIPLevel 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(MIPLevel);
37 }
38 }
39
40 internal static MIPLevel ReadFromNative(native.MIPLevel native)
41 {
42 try
43 {
44 MIPLevel managed = new MIPLevel();
45 managed.Stride = native.Stride;
46 IntPtr[] pixels = Helpers.ReadPtrArrayFromMemory<native.Pixel>(native.Pixels);
47 int length = pixels.Length;
48 //managed.Pixels = new PixelList(length);
49 managed.Pixels = new List<Pixel>(length);
50 foreach (IntPtr ptr in pixels)
51 {
52 Pixel _tmp = new Pixel();
53 _tmp.NativePointer = ptr;
54 managed.Pixels.Add(_tmp);
55 }
56
57 for (int i = 0; i < length; i++)
58 {
59 #if READ_PIXELS_FROM_MEMORY
60 managed.Pixels[i] = Pixel.ReadFromMemory(pixels[i]);
61 #else
62 managed.Pixels[i] = new Pixel();
63 #endif
64 }
65 return managed;
66 }
67 catch
68 {
69 StackTrace st = new StackTrace(true);
70 #if ENABLE_EXCEPTION_OUTPUT_TO_CONSOLE
71 Console.WriteLine(st.ToString());
72 #endif
73 return default(MIPLevel);
74 }
75
76 }
77
78 #region INativePointer Members
79 private IntPtr _NativePointer;
80 public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
81 #endregion
82
83 #region IMIPLevel Members
84 private int _Stride;
85 //private PixelList _Pixels;
86 private List<Pixel> _Pixels;
87
88 public int Stride { get { return _Stride; } set { _Stride = value; } }
89 //public PixelList Pixels { get { return _Pixels; } set { _Pixels = value; } }
90 public List<Pixel> Pixels { get { return _Pixels; } set { _Pixels = value; } }
91 #endregion
92 }
93 }

  ViewVC Help
Powered by ViewVC 1.1.22