/[gr2lib]/trunk/gr2lib/core/ui/typeeditors/PixelBytesEditor.cs
ViewVC logotype

Contents of /trunk/gr2lib/core/ui/typeeditors/PixelBytesEditor.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 145 - (show annotations) (download)
Mon Jul 19 09:39:21 2010 UTC (10 years ago) by william
File size: 7856 byte(s)
coreapi.GrannyCopyTextureImage -> Finially got a return value of true from the copy function.
Will have to check and see what exactly was copied

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using gr2lib.core.ui.rigeditor.interfaces;
10 using gr2lib.core.coretypes.implementation;
11 using System.IO;
12 using gr2lib.core.typedefs;
13 using System.Runtime.InteropServices;
14
15 namespace gr2lib.core.ui.typeeditors
16 {
17 public partial class PixelBytesEditor : UserControl, IValueType<List<Pixel>>
18 {
19 private List<Pixel> _Value;
20 public List<Pixel> Value { get { return _Value; } set { _Value = value; } }
21
22 public PixelBytesEditor()
23 {
24 InitializeComponent();
25 this.Value = default(List<Pixel>);
26 }
27 public PixelBytesEditor(List<Pixel> PixelBytes)
28 {
29 InitializeComponent();
30 this.Value = PixelBytes;
31 }
32 public PixelBytesEditor(object PixelBytes)
33 {
34 InitializeComponent();
35 this.Value = (List<Pixel>)Convert.ChangeType(PixelBytes, typeof(List<Pixel>));
36 }
37
38
39
40 private void PixelBytesEditor_Load(object sender, EventArgs e)
41 {
42 btnImport.FlatStyle = FlatStyle.Standard;
43 btnExport.FlatStyle = FlatStyle.Standard;
44 btnViewImage.FlatStyle = FlatStyle.Standard;
45 btnDebugPixels.FlatStyle = FlatStyle.Standard;
46 }
47
48 #region IMPORT PIXELS SUPPORT
49 private void btnImport_Click(object sender, EventArgs e)
50 {
51 //throw new NotImplementedException("Import Has Not Been Implemented");
52 DialogResult result = PixelImporter.ShowDialog();
53 if (result != DialogResult.OK) return;
54
55 // read bytes from file
56 FileStream fs = new FileStream(PixelImporter.FileName, FileMode.Open);
57 List<Pixel> _pixels = new List<Pixel>();
58 BinaryReader r = new BinaryReader(fs);
59 r.BaseStream.Seek(0, SeekOrigin.Begin);
60 byte[] bytes = r.ReadBytes((int)r.BaseStream.Length);
61 r.Close();
62
63 foreach (byte b in bytes)
64 {
65 Pixel p = new Pixel();
66 p.UInt8 = b;
67 _pixels.Add(p);
68 }
69
70 if (_pixels.Count != Value.Count)
71 {
72 MessageBox.Show("Import Size = " + _pixels.Count + " (" + string.Format("0x{0}", _pixels.Count.ToString("X8")) + ")" + "\nTarget Size = " + Value.Count + " (" + string.Format("0x{0}", Value.Count.ToString("X8")) + ")", "Pixel Data Import Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
73 return;
74 }
75 else
76 {
77 MessageBox.Show("Successfully imported: " + _pixels.Count + " (" + string.Format("0x{0}", _pixels.Count.ToString("X8")) + ")" + " pixel bytes", "Pixel Data Import Successfull!", MessageBoxButtons.OK, MessageBoxIcon.Information);
78 Value = _pixels;
79 }
80
81 }
82 #endregion
83
84 #region EXPORT PIXELS SUPPORT
85 private void btnExport_Click(object sender, EventArgs e)
86 {
87 //throw new NotImplementedException("Export Has Not Been Implemented");
88 DialogResult result = PixelExporter.ShowDialog();
89 if (result != DialogResult.OK) return;
90
91 try
92 {
93 FileStream fs = new FileStream(PixelExporter.FileName, FileMode.Create);
94 BinaryWriter w = new BinaryWriter(fs);
95 foreach (byte b in Value.ToArray())
96 {
97 w.Write(b);
98 }
99 w.Flush();
100 w.Close();
101 MessageBox.Show("Successfully exported: " + Value.Count + " (" + string.Format("0x{0}", Value.Count.ToString("X8")) + ")" + " pixel bytes", "Pixel Data Export Successfull!", MessageBoxButtons.OK, MessageBoxIcon.Information);
102 }
103 catch (Exception ex)
104 {
105 MessageBox.Show("Failed to export pixel data!\n\nMessage: " + ex.Message, "Pixel Data Export Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
106 return;
107 }
108 }
109 #endregion
110
111 #region VIEW RAW PIXELS SUPPORT
112 private void btnViewRaw_Click(object sender, EventArgs e)
113 {
114 // throw new NotImplementedException("View Raw Has Not Been Implemented");
115 List<byte> _bytes = new List<byte>();
116 foreach (Pixel p in this.Value) { _bytes.Add(p.UInt8); }
117 HexEditor _editor = new HexEditor(_bytes);
118 _editor.ShowDialog();
119
120 this.Value.Clear();
121 this.Value = new List<Pixel>();
122 foreach (byte b in _editor.Value)
123 {
124 Pixel p = new Pixel();
125 p.UInt8 = b;
126 this.Value.Add(p);
127 }
128 }
129 #endregion
130
131 #region VIEW IMAGE SUPPORT
132 private void btnViewImage_Click(object sender, EventArgs e)
133 {
134 // throw new NotImplementedException("View Image Has Not Been Implemented");
135 MessageBox.Show("View Image Has Not Been Implemented", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
136 }
137 #endregion
138
139 #region IMAGE SAVE SUPPORT
140 private void btnSaveImage_Click(object sender, EventArgs e)
141 {
142 // throw new NotImplementedException("Image Save Has Not Been Implemented");
143 MessageBox.Show("Image Save Has Not Been Implemented", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
144 }
145 #endregion
146
147 #region IMAGE IMPORT SUPPORT
148 private void btnImportImage_Click(object sender, EventArgs e)
149 {
150 // throw new NotImplementedException("Image Import Has Not Been Implemented");
151 MessageBox.Show("Image Import Has Not Been Implemented", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
152 }
153 #endregion
154
155
156 #region DEBUG PIXELS SUPPORT
157 private void btnDebugPixels_Click(object sender, EventArgs e)
158 {
159 //throw new NotImplementedException("Debug Has Not Been Implemented");
160 //MessageBox.Show("Debug Has Not Been Implemented", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
161 List<byte> _bytes = new List<byte>();
162 foreach (Pixel p in this.Value) { _bytes.Add(new byte()); }
163
164 byte[] __bytes = _bytes.ToArray();
165
166 Texture ReferenceTexture = Value[0].ReferenceTexture;
167
168
169 bool TextureCopied = false;
170
171 byte[] buffer = new byte[__bytes.Length];
172 unsafe
173 {
174 fixed (byte* p = buffer)
175 {
176 IntPtr byte_ptr = (IntPtr)p;
177 TextureCopied = coreapi.GrannyCopyTextureImage(ReferenceTexture.NativePointer,
178 0,
179 0,
180 granny_pixel_layout_types.GrannyRGBA8888PixelFormat.NativePointer,
181 ReferenceTexture.Width,
182 ReferenceTexture.Height,
183 0,
184 byte_ptr);
185 MessageBox.Show("coreapi.GrannyCopyTextureImage returned: " + TextureCopied.ToString());
186 }
187 }
188
189
190 }
191 #endregion
192
193
194
195
196
197
198 }
199 }

  ViewVC Help
Powered by ViewVC 1.1.22