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

Annotation of /trunk/gr2lib/core/coretypes/implementation/Pixel.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 186 - (hide annotations) (download)
Sat Jul 24 02:23:18 2010 UTC (11 years, 5 months ago) by william
File size: 3037 byte(s)
continue to add xml documentation

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

  ViewVC Help
Powered by ViewVC 1.1.22