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.cs180
1 files changed, 0 insertions, 180 deletions
diff --git a/OpenSim/Region/Environment/Modules/LoadImageURLModule.cs b/OpenSim/Region/Environment/Modules/LoadImageURLModule.cs
deleted file mode 100644
index 6c8b028..0000000
--- a/OpenSim/Region/Environment/Modules/LoadImageURLModule.cs
+++ /dev/null
@@ -1,180 +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
28using System;
29using System.Drawing;
30using System.IO;
31using System.Net;
32using libsecondlife;
33using Nini.Config;
34using OpenJPEGNet;
35using OpenSim.Region.Environment.Interfaces;
36using OpenSim.Region.Environment.Scenes;
37
38namespace OpenSim.Region.Environment.Modules
39{
40
41 public class LoadImageURLModule : IRegionModule, IDynamicTextureRender
42 {
43 private string m_name = "LoadImageURL";
44 private IDynamicTextureManager m_textureManager;
45 private Scene m_scene;
46
47 public void Initialise(Scene scene, IConfigSource config)
48 {
49 if (m_scene == null)
50 {
51 m_scene = scene;
52 }
53 }
54
55 public void PostInitialise()
56 {
57 m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
58 if (m_textureManager != null)
59 {
60 m_textureManager.RegisterRender(GetContentType(), this);
61 }
62 }
63
64 public void Close()
65 {
66 }
67
68 public string Name
69 {
70 get { return m_name; }
71 }
72
73 public bool IsSharedModule
74 {
75 get { return true; }
76 }
77
78 public string GetName()
79 {
80 return m_name;
81 }
82
83 public string GetContentType()
84 {
85 return ("image");
86 }
87
88 public bool SupportsAsynchronous()
89 {
90 return true;
91 }
92
93 public byte[] ConvertUrl(string url, string extraParams)
94 {
95 return null;
96 }
97
98 public byte[] ConvertStream(Stream data, string extraParams)
99 {
100 return null;
101 }
102
103 public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
104 {
105 MakeHttpRequest(url, id);
106 return true;
107 }
108
109 public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
110 {
111 return false;
112 }
113
114 private void MakeHttpRequest(string url, LLUUID requestID)
115 {
116 WebRequest request = HttpWebRequest.Create(url);
117 RequestState state = new RequestState((HttpWebRequest) request, requestID);
118 IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state);
119
120 TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
121 state.TimeOfRequest = (int) t.TotalSeconds;
122 }
123
124 private void HttpRequestReturn(IAsyncResult result)
125 {
126 RequestState state = (RequestState) result.AsyncState;
127 WebRequest request = (WebRequest) state.Request;
128 HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(result);
129 if (response.StatusCode == HttpStatusCode.OK)
130 {
131 Bitmap image = new Bitmap(response.GetResponseStream());
132 Size newsize;
133
134 // TODO: make this a bit less hard coded
135 if ((image.Height < 64) && (image.Width < 64))
136 {
137 newsize = new Size(32, 32);
138 }
139 else if ((image.Height < 128) && (image.Width < 128))
140 {
141 newsize = new Size(64, 64);
142 }
143 else if ((image.Height <256) && (image.Width < 256))
144 {
145 newsize = new Size(128, 128);
146 }
147 else if ((image.Height < 512 && image.Width < 512))
148 {
149 newsize = new Size(256, 256);
150 }
151 else if ((image.Height < 1024 && image.Width < 1024))
152 {
153 newsize = new Size(512, 512);
154 }
155 else
156 {
157 newsize = new Size(1024,1024);
158 }
159
160 Bitmap resize = new Bitmap(image, newsize);
161 byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true);
162
163 m_textureManager.ReturnData(state.RequestID, imageJ2000);
164 }
165 }
166
167 public class RequestState
168 {
169 public HttpWebRequest Request = null;
170 public LLUUID RequestID = LLUUID.Zero;
171 public int TimeOfRequest = 0;
172
173 public RequestState(HttpWebRequest request, LLUUID requestID)
174 {
175 Request = request;
176 RequestID = requestID;
177 }
178 }
179 }
180}