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