diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Scripting/VectorRender')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs | 515 |
1 files changed, 0 insertions, 515 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs deleted file mode 100644 index 60806a7..0000000 --- a/OpenSim/Region/Environment/Modules/Scripting/VectorRender/VectorRenderModule.cs +++ /dev/null | |||
@@ -1,515 +0,0 @@ | |||
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 OpenMetaverse; | ||
35 | using OpenMetaverse.Imaging; | ||
36 | using Nini.Config; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | |||
40 | //using Cairo; | ||
41 | |||
42 | namespace OpenSim.Region.Environment.Modules.Scripting.VectorRender | ||
43 | { | ||
44 | public class VectorRenderModule : IRegionModule, IDynamicTextureRender | ||
45 | { | ||
46 | private string m_name = "VectorRenderModule"; | ||
47 | private Scene m_scene; | ||
48 | private IDynamicTextureManager m_textureManager; | ||
49 | |||
50 | public VectorRenderModule() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | #region IDynamicTextureRender Members | ||
55 | |||
56 | public string GetContentType() | ||
57 | { | ||
58 | return ("vector"); | ||
59 | } | ||
60 | |||
61 | public string GetName() | ||
62 | { | ||
63 | return m_name; | ||
64 | } | ||
65 | |||
66 | public bool SupportsAsynchronous() | ||
67 | { | ||
68 | return true; | ||
69 | } | ||
70 | |||
71 | public byte[] ConvertUrl(string url, string extraParams) | ||
72 | { | ||
73 | return null; | ||
74 | } | ||
75 | |||
76 | public byte[] ConvertStream(Stream data, string extraParams) | ||
77 | { | ||
78 | return null; | ||
79 | } | ||
80 | |||
81 | public bool AsyncConvertUrl(UUID id, string url, string extraParams) | ||
82 | { | ||
83 | return false; | ||
84 | } | ||
85 | |||
86 | public bool AsyncConvertData(UUID id, string bodyData, string extraParams) | ||
87 | { | ||
88 | Draw(bodyData, id, extraParams); | ||
89 | return true; | ||
90 | } | ||
91 | |||
92 | #endregion | ||
93 | |||
94 | #region IRegionModule Members | ||
95 | |||
96 | public void Initialise(Scene scene, IConfigSource config) | ||
97 | { | ||
98 | if (m_scene == null) | ||
99 | { | ||
100 | m_scene = scene; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | public void PostInitialise() | ||
105 | { | ||
106 | m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>(); | ||
107 | if (m_textureManager != null) | ||
108 | { | ||
109 | m_textureManager.RegisterRender(GetContentType(), this); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | public void Close() | ||
114 | { | ||
115 | } | ||
116 | |||
117 | public string Name | ||
118 | { | ||
119 | get { return m_name; } | ||
120 | } | ||
121 | |||
122 | public bool IsSharedModule | ||
123 | { | ||
124 | get { return true; } | ||
125 | } | ||
126 | |||
127 | #endregion | ||
128 | |||
129 | private void Draw(string data, UUID id, string extraParams) | ||
130 | { | ||
131 | // We need to cater for old scripts that didnt use extraParams neatly, they use either an integer size which represents both width and height, or setalpha | ||
132 | // we will now support multiple comma seperated params in the form width:256,height:512,alpha:255 | ||
133 | int width = 256; | ||
134 | int height = 256; | ||
135 | int alpha = 255; // 0 is transparent | ||
136 | |||
137 | char[] paramDelimiter = { ',' }; | ||
138 | char[] nvpDelimiter = { ':' }; | ||
139 | |||
140 | extraParams = extraParams.Trim(); | ||
141 | extraParams = extraParams.ToLower(); | ||
142 | |||
143 | string[] nvps = extraParams.Split(paramDelimiter); | ||
144 | |||
145 | int temp = -1; | ||
146 | foreach (string pair in nvps) | ||
147 | { | ||
148 | string[] nvp = pair.Split(nvpDelimiter); | ||
149 | string name = ""; | ||
150 | string value = ""; | ||
151 | |||
152 | if (nvp[0] != null) | ||
153 | { | ||
154 | name = nvp[0].Trim(); | ||
155 | } | ||
156 | |||
157 | if (nvp.Length == 2) | ||
158 | { | ||
159 | value = nvp[1].Trim(); | ||
160 | } | ||
161 | |||
162 | switch (name) | ||
163 | { | ||
164 | case "width": | ||
165 | temp = parseIntParam(value); | ||
166 | if (temp != -1) | ||
167 | { | ||
168 | if (temp < 1) | ||
169 | { | ||
170 | width = 1; | ||
171 | } | ||
172 | else if (temp > 2048) | ||
173 | { | ||
174 | width = 2048; | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | width = temp; | ||
179 | } | ||
180 | } | ||
181 | break; | ||
182 | case "height": | ||
183 | temp = parseIntParam(value); | ||
184 | if (temp != -1) | ||
185 | { | ||
186 | if (temp < 1) | ||
187 | { | ||
188 | height = 1; | ||
189 | } | ||
190 | else if (temp > 2048) | ||
191 | { | ||
192 | height = 2048; | ||
193 | } | ||
194 | else | ||
195 | { | ||
196 | height = temp; | ||
197 | } | ||
198 | } | ||
199 | break; | ||
200 | case "alpha": | ||
201 | temp = parseIntParam(value); | ||
202 | if (temp != -1) | ||
203 | { | ||
204 | if (temp < 0) | ||
205 | { | ||
206 | alpha = 0; | ||
207 | } | ||
208 | else if (temp > 255) | ||
209 | { | ||
210 | alpha = 255; | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | alpha = temp; | ||
215 | } | ||
216 | } | ||
217 | break; | ||
218 | case "": | ||
219 | // blank string has been passed do nothing just use defaults | ||
220 | break; | ||
221 | default: // this is all for backwards compat, all a bit ugly hopfully can be removed in future | ||
222 | // could be either set alpha or just an int | ||
223 | if (name == "setalpha") | ||
224 | { | ||
225 | alpha = 0; // set the texture to have transparent background (maintains backwards compat) | ||
226 | } | ||
227 | else | ||
228 | { | ||
229 | // this function used to accept an int on its own that represented both | ||
230 | // width and height, this is to maintain backwards compat, could be removed | ||
231 | // but would break existing scripts | ||
232 | temp = parseIntParam(name); | ||
233 | if (temp != -1) | ||
234 | { | ||
235 | if (temp > 1024) | ||
236 | temp = 1024; | ||
237 | |||
238 | if (temp < 128) | ||
239 | temp = 128; | ||
240 | |||
241 | width = temp; | ||
242 | height = temp; | ||
243 | } | ||
244 | } | ||
245 | break; | ||
246 | } | ||
247 | |||
248 | } | ||
249 | |||
250 | Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); | ||
251 | |||
252 | Graphics graph = Graphics.FromImage(bitmap); | ||
253 | |||
254 | // this is really just to save people filling the | ||
255 | // background white in their scripts, only do when fully opaque | ||
256 | if (alpha == 255) | ||
257 | { | ||
258 | graph.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height); | ||
259 | } | ||
260 | |||
261 | for (int w = 0; w < bitmap.Width; w++) | ||
262 | { | ||
263 | for (int h = 0; h < bitmap.Height; h++) | ||
264 | { | ||
265 | bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h))); | ||
266 | } | ||
267 | } | ||
268 | |||
269 | |||
270 | GDIDraw(data, graph); | ||
271 | |||
272 | byte[] imageJ2000 = new byte[0]; | ||
273 | |||
274 | try | ||
275 | { | ||
276 | imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true); | ||
277 | } | ||
278 | catch (Exception) | ||
279 | { | ||
280 | Console.WriteLine( | ||
281 | "[VECTORRENDERMODULE]: OpenJpeg Encode Failed. Empty byte data returned!"); | ||
282 | } | ||
283 | m_textureManager.ReturnData(id, imageJ2000); | ||
284 | } | ||
285 | |||
286 | private int parseIntParam(string strInt) | ||
287 | { | ||
288 | int parsed; | ||
289 | try | ||
290 | { | ||
291 | parsed = Convert.ToInt32(strInt); | ||
292 | } | ||
293 | catch (Exception) | ||
294 | { | ||
295 | //Ckrinke: Add a WriteLine to remove the warning about 'e' defined but not used | ||
296 | // Console.WriteLine("Problem with Draw. Please verify parameters." + e.ToString()); | ||
297 | parsed = -1; | ||
298 | } | ||
299 | |||
300 | return parsed; | ||
301 | |||
302 | } | ||
303 | |||
304 | |||
305 | /* | ||
306 | private void CairoDraw(string data, System.Drawing.Graphics graph) | ||
307 | { | ||
308 | using (Win32Surface draw = new Win32Surface(graph.GetHdc())) | ||
309 | { | ||
310 | Context contex = new Context(draw); | ||
311 | |||
312 | contex.Antialias = Antialias.None; //fastest method but low quality | ||
313 | contex.LineWidth = 7; | ||
314 | char[] lineDelimiter = { ';' }; | ||
315 | char[] partsDelimiter = { ',' }; | ||
316 | string[] lines = data.Split(lineDelimiter); | ||
317 | |||
318 | foreach (string line in lines) | ||
319 | { | ||
320 | string nextLine = line.Trim(); | ||
321 | |||
322 | if (nextLine.StartsWith("MoveTO")) | ||
323 | { | ||
324 | float x = 0; | ||
325 | float y = 0; | ||
326 | GetParams(partsDelimiter, ref nextLine, ref x, ref y); | ||
327 | contex.MoveTo(x, y); | ||
328 | } | ||
329 | else if (nextLine.StartsWith("LineTo")) | ||
330 | { | ||
331 | float x = 0; | ||
332 | float y = 0; | ||
333 | GetParams(partsDelimiter, ref nextLine, ref x, ref y); | ||
334 | contex.LineTo(x, y); | ||
335 | contex.Stroke(); | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | graph.ReleaseHdc(); | ||
340 | } | ||
341 | */ | ||
342 | |||
343 | private void GDIDraw(string data, Graphics graph) | ||
344 | { | ||
345 | Point startPoint = new Point(0, 0); | ||
346 | Point endPoint = new Point(0, 0); | ||
347 | Pen drawPen = new Pen(Color.Black, 7); | ||
348 | string fontName = "Arial"; | ||
349 | float fontSize = 14; | ||
350 | Font myFont = new Font(fontName, fontSize); | ||
351 | SolidBrush myBrush = new SolidBrush(Color.Black); | ||
352 | char[] lineDelimiter = {';'}; | ||
353 | char[] partsDelimiter = {','}; | ||
354 | string[] lines = data.Split(lineDelimiter); | ||
355 | |||
356 | foreach (string line in lines) | ||
357 | { | ||
358 | string nextLine = line.Trim(); | ||
359 | //replace with switch, or even better, do some proper parsing | ||
360 | if (nextLine.StartsWith("MoveTo")) | ||
361 | { | ||
362 | float x = 0; | ||
363 | float y = 0; | ||
364 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); | ||
365 | startPoint.X = (int) x; | ||
366 | startPoint.Y = (int) y; | ||
367 | } | ||
368 | else if (nextLine.StartsWith("LineTo")) | ||
369 | { | ||
370 | float x = 0; | ||
371 | float y = 0; | ||
372 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); | ||
373 | endPoint.X = (int) x; | ||
374 | endPoint.Y = (int) y; | ||
375 | graph.DrawLine(drawPen, startPoint, endPoint); | ||
376 | startPoint.X = endPoint.X; | ||
377 | startPoint.Y = endPoint.Y; | ||
378 | } | ||
379 | else if (nextLine.StartsWith("Text")) | ||
380 | { | ||
381 | nextLine = nextLine.Remove(0, 4); | ||
382 | nextLine = nextLine.Trim(); | ||
383 | graph.DrawString(nextLine, myFont, myBrush, startPoint); | ||
384 | } | ||
385 | else if (nextLine.StartsWith("Image")) | ||
386 | { | ||
387 | float x = 0; | ||
388 | float y = 0; | ||
389 | GetParams(partsDelimiter, ref nextLine, 5, ref x, ref y); | ||
390 | endPoint.X = (int) x; | ||
391 | endPoint.Y = (int) y; | ||
392 | Image image = ImageHttpRequest(nextLine); | ||
393 | graph.DrawImage(image, (float) startPoint.X, (float) startPoint.Y, x, y); | ||
394 | startPoint.X += endPoint.X; | ||
395 | startPoint.Y += endPoint.Y; | ||
396 | } | ||
397 | else if (nextLine.StartsWith("Rectangle")) | ||
398 | { | ||
399 | float x = 0; | ||
400 | float y = 0; | ||
401 | GetParams(partsDelimiter, ref nextLine, 9, ref x, ref y); | ||
402 | endPoint.X = (int) x; | ||
403 | endPoint.Y = (int) y; | ||
404 | graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
405 | startPoint.X += endPoint.X; | ||
406 | startPoint.Y += endPoint.Y; | ||
407 | } | ||
408 | else if (nextLine.StartsWith("FillRectangle")) | ||
409 | { | ||
410 | float x = 0; | ||
411 | float y = 0; | ||
412 | GetParams(partsDelimiter, ref nextLine, 13, ref x, ref y); | ||
413 | endPoint.X = (int) x; | ||
414 | endPoint.Y = (int) y; | ||
415 | graph.FillRectangle(myBrush, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
416 | startPoint.X += endPoint.X; | ||
417 | startPoint.Y += endPoint.Y; | ||
418 | } | ||
419 | else if (nextLine.StartsWith("Ellipse")) | ||
420 | { | ||
421 | float x = 0; | ||
422 | float y = 0; | ||
423 | GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y); | ||
424 | endPoint.X = (int) x; | ||
425 | endPoint.Y = (int) y; | ||
426 | graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
427 | startPoint.X += endPoint.X; | ||
428 | startPoint.Y += endPoint.Y; | ||
429 | } | ||
430 | else if (nextLine.StartsWith("FontSize")) | ||
431 | { | ||
432 | nextLine = nextLine.Remove(0, 8); | ||
433 | nextLine = nextLine.Trim(); | ||
434 | fontSize = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
435 | myFont = new Font(fontName, fontSize); | ||
436 | } | ||
437 | else if (nextLine.StartsWith("FontName")) | ||
438 | { | ||
439 | nextLine = nextLine.Remove(0, 8); | ||
440 | fontName = nextLine.Trim(); | ||
441 | myFont = new Font(fontName, fontSize); | ||
442 | } | ||
443 | else if (nextLine.StartsWith("PenSize")) | ||
444 | { | ||
445 | nextLine = nextLine.Remove(0, 7); | ||
446 | nextLine = nextLine.Trim(); | ||
447 | float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
448 | drawPen.Width = size; | ||
449 | } | ||
450 | else if (nextLine.StartsWith("PenColour")) | ||
451 | { | ||
452 | nextLine = nextLine.Remove(0, 9); | ||
453 | nextLine = nextLine.Trim(); | ||
454 | int hex = 0; | ||
455 | |||
456 | Color newColour; | ||
457 | if (Int32.TryParse(nextLine, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex)) | ||
458 | { | ||
459 | newColour = Color.FromArgb(hex); | ||
460 | } | ||
461 | else | ||
462 | { | ||
463 | // this doesn't fail, it just returns black if nothing is found | ||
464 | newColour = Color.FromName(nextLine); | ||
465 | } | ||
466 | |||
467 | myBrush.Color = newColour; | ||
468 | drawPen.Color = newColour; | ||
469 | } | ||
470 | } | ||
471 | } | ||
472 | |||
473 | private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y) | ||
474 | { | ||
475 | line = line.Remove(0, startLength); | ||
476 | string[] parts = line.Split(partsDelimiter); | ||
477 | if (parts.Length == 2) | ||
478 | { | ||
479 | string xVal = parts[0].Trim(); | ||
480 | string yVal = parts[1].Trim(); | ||
481 | x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture); | ||
482 | y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture); | ||
483 | } | ||
484 | else if (parts.Length > 2) | ||
485 | { | ||
486 | string xVal = parts[0].Trim(); | ||
487 | string yVal = parts[1].Trim(); | ||
488 | x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture); | ||
489 | y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture); | ||
490 | |||
491 | line = ""; | ||
492 | for (int i = 2; i < parts.Length; i++) | ||
493 | { | ||
494 | line = line + parts[i].Trim(); | ||
495 | line = line + " "; | ||
496 | } | ||
497 | } | ||
498 | } | ||
499 | |||
500 | private Bitmap ImageHttpRequest(string url) | ||
501 | { | ||
502 | WebRequest request = HttpWebRequest.Create(url); | ||
503 | //Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used. | ||
504 | //Ckrinke Stream str = null; | ||
505 | HttpWebResponse response = (HttpWebResponse) (request).GetResponse(); | ||
506 | if (response.StatusCode == HttpStatusCode.OK) | ||
507 | { | ||
508 | Bitmap image = new Bitmap(response.GetResponseStream()); | ||
509 | return image; | ||
510 | } | ||
511 | |||
512 | return null; | ||
513 | } | ||
514 | } | ||
515 | } | ||