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

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

  ViewVC Help
Powered by ViewVC 1.1.22