diff options
author | Adam Frisby | 2008-04-30 21:16:36 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-30 21:16:36 +0000 |
commit | f5c312bc3c2567449c7268a54a08a54119f58d53 (patch) | |
tree | 424668a4bbec6873ebc5b8256f3671db102f5e9c /OpenSim/Region/Environment/Modules/Scripting/VectorRender | |
parent | * Adds the AuthbuyerID field to sqlite and makes use of it. (diff) | |
download | opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.zip opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2 opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.xz |
* Refactored Environment/Modules directory - modules now reside in their own directory with any associated module-specific classes.
* Each module directory is currently inside one of the following category folders: Agent (Anything relating to do with Client<->Server communications.), Avatar (Anything to do with the avatar or presence inworld), Framework (Classes modules can use), Grid (Grid traffic, new OGS2 grid comms), Scripting (Scripting functions, etc), World (The enrivonment/scene, IE Sun/Tree modules.)
* This should be moved into a seperate project file.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Scripting/VectorRender')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs | 361 |
1 files changed, 361 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs new file mode 100644 index 0000000..4fba5b9 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs | |||
@@ -0,0 +1,361 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Drawing; | ||
30 | using System.Drawing.Imaging; | ||
31 | using System.Globalization; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using libsecondlife; | ||
35 | using Nini.Config; | ||
36 | using OpenJPEGNet; | ||
37 | using OpenSim.Region.Environment.Interfaces; | ||
38 | using OpenSim.Region.Environment.Scenes; | ||
39 | using Image=System.Drawing.Image; | ||
40 | |||
41 | //using Cairo; | ||
42 | |||
43 | namespace OpenSim.Region.Environment.Modules.Scripting.VectorRender | ||
44 | { | ||
45 | public class VectorRenderModule : IRegionModule, IDynamicTextureRender | ||
46 | { | ||
47 | private Scene m_scene; | ||
48 | private string m_name = "VectorRenderModule"; | ||
49 | private IDynamicTextureManager m_textureManager; | ||
50 | |||
51 | public VectorRenderModule() | ||
52 | { | ||
53 | } | ||
54 | |||
55 | public void Initialise(Scene scene, IConfigSource config) | ||
56 | { | ||
57 | if (m_scene == null) | ||
58 | { | ||
59 | m_scene = scene; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | public void PostInitialise() | ||
64 | { | ||
65 | m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>(); | ||
66 | if (m_textureManager != null) | ||
67 | { | ||
68 | m_textureManager.RegisterRender(GetContentType(), this); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | public void Close() | ||
73 | { | ||
74 | } | ||
75 | |||
76 | public string Name | ||
77 | { | ||
78 | get { return m_name; } | ||
79 | } | ||
80 | |||
81 | public bool IsSharedModule | ||
82 | { | ||
83 | get { return true; } | ||
84 | } | ||
85 | |||
86 | private void Draw(string data, LLUUID id, string extraParams) | ||
87 | { | ||
88 | // TODO: this is a brutal hack. extraParams should actually be parsed reasonably. | ||
89 | int size = 256; | ||
90 | try { | ||
91 | size = Convert.ToInt32(extraParams); | ||
92 | } catch (Exception e) { | ||
93 | |||
94 | //Ckrinke: Add a WriteLine to remove the warning about 'e' defined but not used | ||
95 | Console.WriteLine("Problem with Draw. Please verify parameters." + e.ToString()); | ||
96 | } | ||
97 | |||
98 | if ((size < 128) || (size > 1024)) | ||
99 | size = 256; | ||
100 | |||
101 | Bitmap bitmap = new Bitmap(size, size, PixelFormat.Format32bppArgb); | ||
102 | |||
103 | Graphics graph = Graphics.FromImage(bitmap); | ||
104 | |||
105 | extraParams = extraParams.ToLower(); | ||
106 | int alpha = 255; | ||
107 | if (extraParams == "setalpha") | ||
108 | { | ||
109 | alpha = 0; | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | graph.FillRectangle(new SolidBrush(Color.White), 0, 0, size, size); | ||
114 | } | ||
115 | |||
116 | for (int w = 0; w < bitmap.Width; w++) | ||
117 | { | ||
118 | for (int h = 0; h < bitmap.Height; h++) | ||
119 | { | ||
120 | bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h))); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | |||
125 | |||
126 | GDIDraw(data, graph); | ||
127 | |||
128 | byte[] imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true); | ||
129 | m_textureManager.ReturnData(id, imageJ2000); | ||
130 | |||
131 | } | ||
132 | |||
133 | /* | ||
134 | private void CairoDraw(string data, System.Drawing.Graphics graph) | ||
135 | { | ||
136 | using (Win32Surface draw = new Win32Surface(graph.GetHdc())) | ||
137 | { | ||
138 | Context contex = new Context(draw); | ||
139 | |||
140 | contex.Antialias = Antialias.None; //fastest method but low quality | ||
141 | contex.LineWidth = 7; | ||
142 | char[] lineDelimiter = { ';' }; | ||
143 | char[] partsDelimiter = { ',' }; | ||
144 | string[] lines = data.Split(lineDelimiter); | ||
145 | |||
146 | foreach (string line in lines) | ||
147 | { | ||
148 | string nextLine = line.Trim(); | ||
149 | |||
150 | if (nextLine.StartsWith("MoveTO")) | ||
151 | { | ||
152 | float x = 0; | ||
153 | float y = 0; | ||
154 | GetParams(partsDelimiter, ref nextLine, ref x, ref y); | ||
155 | contex.MoveTo(x, y); | ||
156 | } | ||
157 | else if (nextLine.StartsWith("LineTo")) | ||
158 | { | ||
159 | float x = 0; | ||
160 | float y = 0; | ||
161 | GetParams(partsDelimiter, ref nextLine, ref x, ref y); | ||
162 | contex.LineTo(x, y); | ||
163 | contex.Stroke(); | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | graph.ReleaseHdc(); | ||
168 | } | ||
169 | */ | ||
170 | |||
171 | private void GDIDraw(string data, Graphics graph) | ||
172 | { | ||
173 | Point startPoint = new Point(0, 0); | ||
174 | Point endPoint = new Point(0, 0); | ||
175 | Pen drawPen = new Pen(Color.Black, 7); | ||
176 | Font myFont = new Font("Times New Roman", 14); | ||
177 | SolidBrush myBrush = new SolidBrush(Color.Black); | ||
178 | char[] lineDelimiter = { ';' }; | ||
179 | char[] partsDelimiter = { ',' }; | ||
180 | string[] lines = data.Split(lineDelimiter); | ||
181 | |||
182 | foreach (string line in lines) | ||
183 | { | ||
184 | string nextLine = line.Trim(); | ||
185 | //replace with switch, or even better, do some proper parsing | ||
186 | if (nextLine.StartsWith("MoveTo")) | ||
187 | { | ||
188 | float x = 0; | ||
189 | float y = 0; | ||
190 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); | ||
191 | startPoint.X = (int)x; | ||
192 | startPoint.Y = (int)y; | ||
193 | } | ||
194 | else if (nextLine.StartsWith("LineTo")) | ||
195 | { | ||
196 | float x = 0; | ||
197 | float y = 0; | ||
198 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); | ||
199 | endPoint.X = (int)x; | ||
200 | endPoint.Y = (int)y; | ||
201 | graph.DrawLine(drawPen, startPoint, endPoint); | ||
202 | startPoint.X = endPoint.X; | ||
203 | startPoint.Y = endPoint.Y; | ||
204 | } | ||
205 | else if (nextLine.StartsWith("Text")) | ||
206 | { | ||
207 | nextLine = nextLine.Remove(0, 4); | ||
208 | nextLine = nextLine.Trim(); | ||
209 | graph.DrawString(nextLine, myFont, myBrush, startPoint); | ||
210 | } | ||
211 | else if (nextLine.StartsWith("Image")) | ||
212 | { | ||
213 | float x = 0; | ||
214 | float y = 0; | ||
215 | GetParams(partsDelimiter, ref nextLine, 5, ref x, ref y); | ||
216 | endPoint.X = (int)x; | ||
217 | endPoint.Y = (int)y; | ||
218 | Image image = ImageHttpRequest(nextLine); | ||
219 | graph.DrawImage(image, (float)startPoint.X, (float)startPoint.Y, x, y); | ||
220 | startPoint.X += endPoint.X; | ||
221 | startPoint.Y += endPoint.Y; | ||
222 | } | ||
223 | else if (nextLine.StartsWith("Rectangle")) | ||
224 | { | ||
225 | float x = 0; | ||
226 | float y = 0; | ||
227 | GetParams(partsDelimiter, ref nextLine, 9, ref x, ref y); | ||
228 | endPoint.X = (int)x; | ||
229 | endPoint.Y = (int)y; | ||
230 | graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
231 | startPoint.X += endPoint.X; | ||
232 | startPoint.Y += endPoint.Y; | ||
233 | } | ||
234 | else if (nextLine.StartsWith("FillRectangle")) | ||
235 | { | ||
236 | float x = 0; | ||
237 | float y = 0; | ||
238 | GetParams(partsDelimiter, ref nextLine, 13, ref x, ref y); | ||
239 | endPoint.X = (int)x; | ||
240 | endPoint.Y = (int)y; | ||
241 | graph.FillRectangle(myBrush, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
242 | startPoint.X += endPoint.X; | ||
243 | startPoint.Y += endPoint.Y; | ||
244 | } | ||
245 | else if (nextLine.StartsWith("Ellipse")) | ||
246 | { | ||
247 | float x = 0; | ||
248 | float y = 0; | ||
249 | GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y); | ||
250 | endPoint.X = (int)x; | ||
251 | endPoint.Y = (int)y; | ||
252 | graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
253 | startPoint.X += endPoint.X; | ||
254 | startPoint.Y += endPoint.Y; | ||
255 | } | ||
256 | else if (nextLine.StartsWith("FontSize")) | ||
257 | { | ||
258 | nextLine = nextLine.Remove(0, 8); | ||
259 | nextLine = nextLine.Trim(); | ||
260 | float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
261 | myFont = new Font("Times New Roman", size); | ||
262 | } | ||
263 | else if (nextLine.StartsWith("PenSize")) | ||
264 | { | ||
265 | nextLine = nextLine.Remove(0, 8); | ||
266 | nextLine = nextLine.Trim(); | ||
267 | float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
268 | drawPen.Width = size; | ||
269 | } | ||
270 | else if (nextLine.StartsWith("PenColour")) | ||
271 | { | ||
272 | nextLine = nextLine.Remove(0, 9); | ||
273 | nextLine = nextLine.Trim(); | ||
274 | |||
275 | Color newColour = Color.FromName(nextLine); | ||
276 | |||
277 | myBrush.Color = newColour; | ||
278 | drawPen.Color = newColour; | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y) | ||
284 | { | ||
285 | line = line.Remove(0, startLength); | ||
286 | string[] parts = line.Split(partsDelimiter); | ||
287 | if (parts.Length == 2) | ||
288 | { | ||
289 | string xVal = parts[0].Trim(); | ||
290 | string yVal = parts[1].Trim(); | ||
291 | x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture); | ||
292 | y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture); | ||
293 | } | ||
294 | else if (parts.Length > 2) | ||
295 | { | ||
296 | string xVal = parts[0].Trim(); | ||
297 | string yVal = parts[1].Trim(); | ||
298 | x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture); | ||
299 | y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture); | ||
300 | |||
301 | line = ""; | ||
302 | for (int i = 2; i < parts.Length; i++) | ||
303 | { | ||
304 | line = line + parts[i].Trim(); | ||
305 | line = line + " "; | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | |||
310 | private Bitmap ImageHttpRequest(string url) | ||
311 | { | ||
312 | WebRequest request = HttpWebRequest.Create(url); | ||
313 | //Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used. | ||
314 | //Ckrinke Stream str = null; | ||
315 | HttpWebResponse response = (HttpWebResponse)(request).GetResponse(); | ||
316 | if (response.StatusCode == HttpStatusCode.OK) | ||
317 | { | ||
318 | Bitmap image = new Bitmap(response.GetResponseStream()); | ||
319 | return image; | ||
320 | } | ||
321 | |||
322 | return null; | ||
323 | } | ||
324 | |||
325 | public string GetContentType() | ||
326 | { | ||
327 | return ("vector"); | ||
328 | } | ||
329 | |||
330 | public string GetName() | ||
331 | { | ||
332 | return m_name; | ||
333 | } | ||
334 | |||
335 | public bool SupportsAsynchronous() | ||
336 | { | ||
337 | return true; | ||
338 | } | ||
339 | |||
340 | public byte[] ConvertUrl(string url, string extraParams) | ||
341 | { | ||
342 | return null; | ||
343 | } | ||
344 | |||
345 | public byte[] ConvertStream(Stream data, string extraParams) | ||
346 | { | ||
347 | return null; | ||
348 | } | ||
349 | |||
350 | public bool AsyncConvertUrl(LLUUID id, string url, string extraParams) | ||
351 | { | ||
352 | return false; | ||
353 | } | ||
354 | |||
355 | public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams) | ||
356 | { | ||
357 | Draw(bodyData, id, extraParams); | ||
358 | return true; | ||
359 | } | ||
360 | } | ||
361 | } \ No newline at end of file | ||