1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Collections; |
4 |
using System.Text; |
5 |
using gr2lib.core.helpers; |
6 |
using System.IO; |
7 |
using System.Drawing; |
8 |
using System.ComponentModel; |
9 |
using System.Runtime.InteropServices; |
10 |
using System.Drawing.Imaging; |
11 |
using gr2lib.core.interfaces; |
12 |
|
13 |
namespace gr2lib.core.coretypes.implementation |
14 |
{ |
15 |
/// <summary> |
16 |
/// Pixel class |
17 |
/// </summary> |
18 |
public class Pixel : IPixel |
19 |
{ |
20 |
#region Implicit operators |
21 |
/// <summary> |
22 |
/// Convert Byte to Pixel |
23 |
/// </summary> |
24 |
/// <param name="b">the byte to convert</param> |
25 |
/// <returns>pixel</returns> |
26 |
public static implicit operator Pixel(byte b) |
27 |
{ |
28 |
Pixel p = new Pixel(); |
29 |
p.UInt8 = b; |
30 |
return p; |
31 |
} |
32 |
/// <summary> |
33 |
/// Convert Pixel to byte |
34 |
/// </summary> |
35 |
/// <param name="p">the pixel to convert</param> |
36 |
/// <returns>byte</returns> |
37 |
public static implicit operator byte(Pixel p) |
38 |
{ |
39 |
return p.UInt8; |
40 |
} |
41 |
#endregion |
42 |
|
43 |
|
44 |
internal Texture ReferenceTexture; |
45 |
|
46 |
/// <summary> |
47 |
/// default constructor |
48 |
/// </summary> |
49 |
public Pixel() |
50 |
{ |
51 |
this.UInt8 = 0; |
52 |
this.ReferenceTexture = new Texture(); |
53 |
//this.NativePointer = IntPtr.Zero; |
54 |
} |
55 |
internal static Pixel ReadFromMemory(IntPtr pointer) |
56 |
{ |
57 |
try |
58 |
{ |
59 |
if (pointer == IntPtr.Zero) return null; |
60 |
native.Pixel native = Helpers.ReadFromMemory<native.Pixel>(pointer); |
61 |
Pixel managed = ReadFromNative(native); |
62 |
managed.NativePointer = pointer; |
63 |
return managed; |
64 |
} |
65 |
catch(Exception ex) |
66 |
{ |
67 |
Console.WriteLine(ex.ToString()); |
68 |
return default(Pixel); |
69 |
} |
70 |
} |
71 |
|
72 |
internal static Pixel ReadFromNative(native.Pixel native) |
73 |
{ |
74 |
try |
75 |
{ |
76 |
Pixel managed = new Pixel(); |
77 |
managed.UInt8 = native.UInt8; |
78 |
return managed; |
79 |
} |
80 |
catch (Exception ex) |
81 |
{ |
82 |
Console.WriteLine(ex.ToString()); |
83 |
return default(Pixel); |
84 |
} |
85 |
|
86 |
} |
87 |
|
88 |
#region INativePointer Members |
89 |
private IntPtr _NativePointer; |
90 |
/// <summary> |
91 |
/// When used in a derived class, gets the native pointer for this instance |
92 |
/// </summary> |
93 |
public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } } |
94 |
#endregion |
95 |
|
96 |
#region IPixel Members |
97 |
private byte _UInt8; |
98 |
/// <summary> |
99 |
/// Represents a single byte of a pixel |
100 |
/// </summary> |
101 |
public byte UInt8 { get { return _UInt8; } set { _UInt8 = value; } } |
102 |
#endregion |
103 |
} |
104 |
} |