aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Environment/ModuleLoader.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/DynamicTextureModule.cs11
-rw-r--r--OpenSim/Region/Environment/Modules/LoadImageURLModule.cs123
3 files changed, 132 insertions, 4 deletions
diff --git a/OpenSim/Region/Environment/ModuleLoader.cs b/OpenSim/Region/Environment/ModuleLoader.cs
index 4811cf0..b27fb11 100644
--- a/OpenSim/Region/Environment/ModuleLoader.cs
+++ b/OpenSim/Region/Environment/ModuleLoader.cs
@@ -75,7 +75,7 @@ namespace OpenSim.Region.Environment
75 } 75 }
76 } 76 }
77 77
78 private void InitializeModule(IRegionModule module, Scene scene) 78 public void InitializeModule(IRegionModule module, Scene scene)
79 { 79 {
80 module.Initialise(scene); 80 module.Initialise(scene);
81 scene.AddModule(module.Name, module); 81 scene.AddModule(module.Name, module);
diff --git a/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs b/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
index 51a5534..bac0d59 100644
--- a/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
+++ b/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
@@ -96,9 +96,10 @@ namespace OpenSim.Region.Environment.Modules
96 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url, 96 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
97 string extraParams, int updateTimer) 97 string extraParams, int updateTimer)
98 { 98 {
99 Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
100 if (RenderPlugins.ContainsKey(contentType)) 99 if (RenderPlugins.ContainsKey(contentType))
101 { 100 {
101 //Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
102
102 DynamicTextureUpdater updater = new DynamicTextureUpdater(); 103 DynamicTextureUpdater updater = new DynamicTextureUpdater();
103 updater.SimUUID = simID; 104 updater.SimUUID = simID;
104 updater.PrimID = primID; 105 updater.PrimID = primID;
@@ -166,12 +167,16 @@ namespace OpenSim.Region.Environment.Modules
166 public void DataReceived(byte[] data, Scene scene) 167 public void DataReceived(byte[] data, Scene scene)
167 { 168 {
168 //TODO delete the last asset(data), if it was a dynamic texture 169 //TODO delete the last asset(data), if it was a dynamic texture
169 170 byte[] assetData = new byte[data.Length];
171 Array.Copy(data, assetData, data.Length);
170 AssetBase asset = new AssetBase(); 172 AssetBase asset = new AssetBase();
171 asset.FullID = LLUUID.Random(); 173 asset.FullID = LLUUID.Random();
172 asset.Data = data; 174 asset.Data = assetData;
173 asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000); 175 asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
174 asset.Type = 0; 176 asset.Type = 0;
177 asset.Description = "dynamic image";
178 asset.Local = false;
179 asset.Temporary = false;
175 scene.commsManager.AssetCache.AddAsset(asset); 180 scene.commsManager.AssetCache.AddAsset(asset);
176 181
177 LastAssetID = asset.FullID; 182 LastAssetID = asset.FullID;
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}