aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/LoadImageURLModule.cs
diff options
context:
space:
mode:
authorMW2007-10-15 08:51:59 +0000
committerMW2007-10-15 08:51:59 +0000
commitc2462bc8bb76b215437412c7dae839b5d0925df8 (patch)
tree0c470d1dd9191d68e1b730494deb1ebccb8d1c7d /OpenSim/Region/Environment/Modules/LoadImageURLModule.cs
parent* Applied Chillken patch #419: consolidate_ports-r2096-3.patch - consolidated... (diff)
downloadopensim-SC-c2462bc8bb76b215437412c7dae839b5d0925df8.zip
opensim-SC-c2462bc8bb76b215437412c7dae839b5d0925df8.tar.gz
opensim-SC-c2462bc8bb76b215437412c7dae839b5d0925df8.tar.bz2
opensim-SC-c2462bc8bb76b215437412c7dae839b5d0925df8.tar.xz
Added "LoadImageUrl" module , that is a dynamic texture render, that works with the DynamicTextureModule to allow loading of a image from a webserver and a texture of that image created.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/LoadImageURLModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/LoadImageURLModule.cs123
1 files changed, 123 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/LoadImageURLModule.cs b/OpenSim/Region/Environment/Modules/LoadImageURLModule.cs
new file mode 100644
index 0000000..f1f479d
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/LoadImageURLModule.cs
@@ -0,0 +1,123 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Net;
5using System.IO;
6using System.Drawing;
7using libsecondlife;
8using OpenJPEGNet;
9using OpenSim.Region.Environment.Scenes;
10using OpenSim.Region.Environment.Interfaces;
11
12namespace OpenSim.Region.Environment.Modules
13{
14 public class LoadImageURLModule : IRegionModule , IDynamicTextureRender
15 {
16 private string m_name = "LoadImageURL";
17 private IDynamicTextureManager m_textureManager;
18 private Scene m_scene;
19
20 public void Initialise(Scene scene)
21 {
22 if (m_scene == null)
23 {
24 m_scene = scene;
25 }
26 }
27
28 public void PostInitialise()
29 {
30 m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
31 m_textureManager.RegisterRender(GetContentType(), this);
32 }
33
34 public void Close()
35 {
36 }
37
38 public string Name
39 {
40 get { return m_name; }
41 }
42
43 public bool IsSharedModule
44 {
45 get { return true; }
46 }
47
48 public string GetName()
49 {
50 return m_name;
51 }
52
53 public string GetContentType()
54 {
55 return ("image");
56 }
57
58 public bool SupportsAsynchronous()
59 {
60 return true;
61 }
62
63 public byte[] ConvertUrl(string url, string extraParams)
64 {
65 return null;
66 }
67
68 public byte[] ConvertStream(Stream data, string extraParams)
69 {
70 return null;
71 }
72
73 public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
74 {
75 MakeHttpRequest(url, id);
76 return true;
77 }
78
79 public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
80 {
81 return false;
82 }
83
84 private void MakeHttpRequest(string url, LLUUID requestID)
85 {
86 WebRequest request = HttpWebRequest.Create(url);
87 RequestState state = new RequestState((HttpWebRequest)request, requestID);
88 IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state);
89
90 TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
91 state.TimeOfRequest = (int)t.TotalSeconds;
92 }
93
94 private void HttpRequestReturn(IAsyncResult result)
95 {
96 RequestState state = (RequestState)result.AsyncState;
97 WebRequest request = (WebRequest)state.Request;
98 HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
99 if (response.StatusCode == HttpStatusCode.OK)
100 {
101 Bitmap image = new Bitmap(response.GetResponseStream());
102 Bitmap resize = new Bitmap(image, new Size(512, 512));
103 byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true);
104
105 m_textureManager.ReturnData(state.RequestID, imageJ2000);
106 }
107 }
108
109 public class RequestState
110 {
111 public HttpWebRequest Request = null;
112 public LLUUID RequestID = LLUUID.Zero;
113 public int TimeOfRequest = 0;
114
115 public RequestState(HttpWebRequest request, LLUUID requestID)
116 {
117 Request = request;
118 RequestID = requestID;
119 }
120 }
121
122 }
123}