aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Scripting/LoadImageURL/LoadImageURLModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Scripting/LoadImageURL/LoadImageURLModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Scripting/LoadImageURL/LoadImageURLModule.cs380
1 files changed, 190 insertions, 190 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/LoadImageURL/LoadImageURLModule.cs b/OpenSim/Region/Environment/Modules/Scripting/LoadImageURL/LoadImageURLModule.cs
index a0408cd..c828ef0 100644
--- a/OpenSim/Region/Environment/Modules/Scripting/LoadImageURL/LoadImageURLModule.cs
+++ b/OpenSim/Region/Environment/Modules/Scripting/LoadImageURL/LoadImageURLModule.cs
@@ -1,191 +1,191 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Drawing; 29using System.Drawing;
30using System.IO; 30using System.IO;
31using System.Net; 31using System.Net;
32using libsecondlife; 32using libsecondlife;
33using Nini.Config; 33using Nini.Config;
34using OpenJPEGNet; 34using OpenJPEGNet;
35using OpenSim.Region.Environment.Interfaces; 35using OpenSim.Region.Environment.Interfaces;
36using OpenSim.Region.Environment.Scenes; 36using OpenSim.Region.Environment.Scenes;
37 37
38namespace OpenSim.Region.Environment.Modules.Scripting.LoadImageURL 38namespace OpenSim.Region.Environment.Modules.Scripting.LoadImageURL
39{ 39{
40 public class LoadImageURLModule : IRegionModule, IDynamicTextureRender 40 public class LoadImageURLModule : IRegionModule, IDynamicTextureRender
41 { 41 {
42 private string m_name = "LoadImageURL"; 42 private string m_name = "LoadImageURL";
43 private Scene m_scene; 43 private Scene m_scene;
44 private IDynamicTextureManager m_textureManager; 44 private IDynamicTextureManager m_textureManager;
45 45
46 #region IDynamicTextureRender Members 46 #region IDynamicTextureRender Members
47 47
48 public string GetName() 48 public string GetName()
49 { 49 {
50 return m_name; 50 return m_name;
51 } 51 }
52 52
53 public string GetContentType() 53 public string GetContentType()
54 { 54 {
55 return ("image"); 55 return ("image");
56 } 56 }
57 57
58 public bool SupportsAsynchronous() 58 public bool SupportsAsynchronous()
59 { 59 {
60 return true; 60 return true;
61 } 61 }
62 62
63 public byte[] ConvertUrl(string url, string extraParams) 63 public byte[] ConvertUrl(string url, string extraParams)
64 { 64 {
65 return null; 65 return null;
66 } 66 }
67 67
68 public byte[] ConvertStream(Stream data, string extraParams) 68 public byte[] ConvertStream(Stream data, string extraParams)
69 { 69 {
70 return null; 70 return null;
71 } 71 }
72 72
73 public bool AsyncConvertUrl(LLUUID id, string url, string extraParams) 73 public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
74 { 74 {
75 MakeHttpRequest(url, id); 75 MakeHttpRequest(url, id);
76 return true; 76 return true;
77 } 77 }
78 78
79 public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams) 79 public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
80 { 80 {
81 return false; 81 return false;
82 } 82 }
83 83
84 #endregion 84 #endregion
85 85
86 #region IRegionModule Members 86 #region IRegionModule Members
87 87
88 public void Initialise(Scene scene, IConfigSource config) 88 public void Initialise(Scene scene, IConfigSource config)
89 { 89 {
90 if (m_scene == null) 90 if (m_scene == null)
91 { 91 {
92 m_scene = scene; 92 m_scene = scene;
93 } 93 }
94 } 94 }
95 95
96 public void PostInitialise() 96 public void PostInitialise()
97 { 97 {
98 m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>(); 98 m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
99 if (m_textureManager != null) 99 if (m_textureManager != null)
100 { 100 {
101 m_textureManager.RegisterRender(GetContentType(), this); 101 m_textureManager.RegisterRender(GetContentType(), this);
102 } 102 }
103 } 103 }
104 104
105 public void Close() 105 public void Close()
106 { 106 {
107 } 107 }
108 108
109 public string Name 109 public string Name
110 { 110 {
111 get { return m_name; } 111 get { return m_name; }
112 } 112 }
113 113
114 public bool IsSharedModule 114 public bool IsSharedModule
115 { 115 {
116 get { return true; } 116 get { return true; }
117 } 117 }
118 118
119 #endregion 119 #endregion
120 120
121 private void MakeHttpRequest(string url, LLUUID requestID) 121 private void MakeHttpRequest(string url, LLUUID requestID)
122 { 122 {
123 WebRequest request = HttpWebRequest.Create(url); 123 WebRequest request = HttpWebRequest.Create(url);
124 RequestState state = new RequestState((HttpWebRequest) request, requestID); 124 RequestState state = new RequestState((HttpWebRequest) request, requestID);
125 IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state); 125 IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state);
126 126
127 TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); 127 TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
128 state.TimeOfRequest = (int) t.TotalSeconds; 128 state.TimeOfRequest = (int) t.TotalSeconds;
129 } 129 }
130 130
131 private void HttpRequestReturn(IAsyncResult result) 131 private void HttpRequestReturn(IAsyncResult result)
132 { 132 {
133 RequestState state = (RequestState) result.AsyncState; 133 RequestState state = (RequestState) result.AsyncState;
134 WebRequest request = (WebRequest) state.Request; 134 WebRequest request = (WebRequest) state.Request;
135 HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(result); 135 HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(result);
136 if (response.StatusCode == HttpStatusCode.OK) 136 if (response.StatusCode == HttpStatusCode.OK)
137 { 137 {
138 Bitmap image = new Bitmap(response.GetResponseStream()); 138 Bitmap image = new Bitmap(response.GetResponseStream());
139 Size newsize; 139 Size newsize;
140 140
141 // TODO: make this a bit less hard coded 141 // TODO: make this a bit less hard coded
142 if ((image.Height < 64) && (image.Width < 64)) 142 if ((image.Height < 64) && (image.Width < 64))
143 { 143 {
144 newsize = new Size(32, 32); 144 newsize = new Size(32, 32);
145 } 145 }
146 else if ((image.Height < 128) && (image.Width < 128)) 146 else if ((image.Height < 128) && (image.Width < 128))
147 { 147 {
148 newsize = new Size(64, 64); 148 newsize = new Size(64, 64);
149 } 149 }
150 else if ((image.Height < 256) && (image.Width < 256)) 150 else if ((image.Height < 256) && (image.Width < 256))
151 { 151 {
152 newsize = new Size(128, 128); 152 newsize = new Size(128, 128);
153 } 153 }
154 else if ((image.Height < 512 && image.Width < 512)) 154 else if ((image.Height < 512 && image.Width < 512))
155 { 155 {
156 newsize = new Size(256, 256); 156 newsize = new Size(256, 256);
157 } 157 }
158 else if ((image.Height < 1024 && image.Width < 1024)) 158 else if ((image.Height < 1024 && image.Width < 1024))
159 { 159 {
160 newsize = new Size(512, 512); 160 newsize = new Size(512, 512);
161 } 161 }
162 else 162 else
163 { 163 {
164 newsize = new Size(1024, 1024); 164 newsize = new Size(1024, 1024);
165 } 165 }
166 166
167 Bitmap resize = new Bitmap(image, newsize); 167 Bitmap resize = new Bitmap(image, newsize);
168 byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true); 168 byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true);
169 169
170 m_textureManager.ReturnData(state.RequestID, imageJ2000); 170 m_textureManager.ReturnData(state.RequestID, imageJ2000);
171 } 171 }
172 } 172 }
173 173
174 #region Nested type: RequestState 174 #region Nested type: RequestState
175 175
176 public class RequestState 176 public class RequestState
177 { 177 {
178 public HttpWebRequest Request = null; 178 public HttpWebRequest Request = null;
179 public LLUUID RequestID = LLUUID.Zero; 179 public LLUUID RequestID = LLUUID.Zero;
180 public int TimeOfRequest = 0; 180 public int TimeOfRequest = 0;
181 181
182 public RequestState(HttpWebRequest request, LLUUID requestID) 182 public RequestState(HttpWebRequest request, LLUUID requestID)
183 { 183 {
184 Request = request; 184 Request = request;
185 RequestID = requestID; 185 RequestID = requestID;
186 } 186 }
187 } 187 }
188 188
189 #endregion 189 #endregion
190 } 190 }
191} \ No newline at end of file 191} \ No newline at end of file