/[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 106 - (show annotations) (download)
Sat Jul 17 14:52:37 2010 UTC (10 years, 9 months ago) by william
File size: 3244 byte(s)
implement Granny2ExceptionWriter

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

  ViewVC Help
Powered by ViewVC 1.1.22