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