/[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 89 - (show annotations) (download)
Fri Jul 16 23:44:30 2010 UTC (10 years, 1 month ago) by william
File size: 2954 byte(s)
managed.Pixels[i] = default(Pixel); -> managed.Pixels[i] = New Pixel();

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 namespace gr2lib.core.coretypes.implementation
8 {
9 public class MIPLevel : IMIPLevel
10 {
11 public MIPLevel()
12 {
13 this.Stride = 0;
14 //this.Pixels = new PixelList();
15 this.Pixels = new List<Pixel>();
16 //this.NativePointer = IntPtr.Zero;
17 }
18
19 internal static MIPLevel ReadFromMemory(IntPtr pointer)
20 {
21 try
22 {
23 if (pointer == IntPtr.Zero) return null;
24 native.MIPLevel native = Helpers.ReadFromMemory<native.MIPLevel>(pointer);
25 MIPLevel managed = ReadFromNative(native);
26 managed.NativePointer = pointer;
27 return managed;
28 }
29 catch (Exception ex)
30 {
31 Console.WriteLine(ex.ToString());
32 return default(MIPLevel);
33 }
34 }
35
36 internal static MIPLevel ReadFromNative(native.MIPLevel native)
37 {
38 try
39 {
40 MIPLevel managed = new MIPLevel();
41 managed.Stride = native.Stride;
42 IntPtr[] pixels = Helpers.ReadPtrArrayFromMemory<native.Pixel>(native.Pixels);
43 int length = pixels.Length;
44 //managed.Pixels = new PixelList(length);
45 managed.Pixels = new List<Pixel>(length);
46 foreach (IntPtr ptr in pixels)
47 {
48 Pixel _tmp = new Pixel();
49 _tmp.NativePointer = ptr;
50 managed.Pixels.Add(_tmp);
51 }
52
53 for (int i = 0; i < length; i++)
54 {
55 #if READ_PIXELS_FROM_MEMORY
56 managed.Pixels[i] = Pixel.ReadFromMemory(pixels[i]);
57 #else
58 managed.Pixels[i] = new Pixel();
59 #endif
60 }
61 return managed;
62 }
63 catch (Exception ex)
64 {
65 Console.WriteLine(ex.ToString());
66 return default(MIPLevel);
67 }
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 IMIPLevel Members
77 private int _Stride;
78 //private PixelList _Pixels;
79 private List<Pixel> _Pixels;
80
81 public int Stride { get { return _Stride; } set { _Stride = value; } }
82 //public PixelList Pixels { get { return _Pixels; } set { _Pixels = value; } }
83 public List<Pixel> Pixels { get { return _Pixels; } set { _Pixels = value; } }
84 #endregion
85 }
86 }

  ViewVC Help
Powered by ViewVC 1.1.22