diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | 59 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs | 96 |
2 files changed, 105 insertions, 50 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index 259a333..6509bf3 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | |||
@@ -42,6 +42,10 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
42 | { | 42 | { |
43 | public class DynamicTextureModule : IRegionModule, IDynamicTextureManager | 43 | public class DynamicTextureModule : IRegionModule, IDynamicTextureManager |
44 | { | 44 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private const int ALL_SIDES = -1; | ||
48 | |||
45 | private Dictionary<UUID, Scene> RegisteredScenes = new Dictionary<UUID, Scene>(); | 49 | private Dictionary<UUID, Scene> RegisteredScenes = new Dictionary<UUID, Scene>(); |
46 | 50 | ||
47 | private Dictionary<string, IDynamicTextureRender> RenderPlugins = | 51 | private Dictionary<string, IDynamicTextureRender> RenderPlugins = |
@@ -106,6 +110,12 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
106 | public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, | 110 | public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, |
107 | string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) | 111 | string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) |
108 | { | 112 | { |
113 | return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, SetBlending, AlphaValue, ALL_SIDES); | ||
114 | } | ||
115 | |||
116 | public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, | ||
117 | string extraParams, int updateTimer, bool SetBlending, byte AlphaValue, int face) | ||
118 | { | ||
109 | if (RenderPlugins.ContainsKey(contentType)) | 119 | if (RenderPlugins.ContainsKey(contentType)) |
110 | { | 120 | { |
111 | //m_log.Debug("dynamic texture being created: " + url + " of type " + contentType); | 121 | //m_log.Debug("dynamic texture being created: " + url + " of type " + contentType); |
@@ -120,6 +130,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
120 | updater.Params = extraParams; | 130 | updater.Params = extraParams; |
121 | updater.BlendWithOldTexture = SetBlending; | 131 | updater.BlendWithOldTexture = SetBlending; |
122 | updater.FrontAlpha = AlphaValue; | 132 | updater.FrontAlpha = AlphaValue; |
133 | updater.Face = face; | ||
123 | 134 | ||
124 | lock (Updaters) | 135 | lock (Updaters) |
125 | { | 136 | { |
@@ -144,6 +155,12 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
144 | public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, | 155 | public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, |
145 | string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) | 156 | string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) |
146 | { | 157 | { |
158 | return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, SetBlending, AlphaValue, ALL_SIDES); | ||
159 | } | ||
160 | |||
161 | public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, | ||
162 | string extraParams, int updateTimer, bool SetBlending, byte AlphaValue, int face) | ||
163 | { | ||
147 | if (RenderPlugins.ContainsKey(contentType)) | 164 | if (RenderPlugins.ContainsKey(contentType)) |
148 | { | 165 | { |
149 | DynamicTextureUpdater updater = new DynamicTextureUpdater(); | 166 | DynamicTextureUpdater updater = new DynamicTextureUpdater(); |
@@ -156,6 +173,8 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
156 | updater.Params = extraParams; | 173 | updater.Params = extraParams; |
157 | updater.BlendWithOldTexture = SetBlending; | 174 | updater.BlendWithOldTexture = SetBlending; |
158 | updater.FrontAlpha = AlphaValue; | 175 | updater.FrontAlpha = AlphaValue; |
176 | updater.Face = face; | ||
177 | updater.Url = "Local image"; | ||
159 | 178 | ||
160 | lock (Updaters) | 179 | lock (Updaters) |
161 | { | 180 | { |
@@ -232,6 +251,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
232 | public UUID SimUUID; | 251 | public UUID SimUUID; |
233 | public UUID UpdaterID; | 252 | public UUID UpdaterID; |
234 | public int UpdateTimer; | 253 | public int UpdateTimer; |
254 | public int Face; | ||
235 | public string Url; | 255 | public string Url; |
236 | 256 | ||
237 | public DynamicTextureUpdater() | 257 | public DynamicTextureUpdater() |
@@ -249,7 +269,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
249 | 269 | ||
250 | SceneObjectPart part = scene.GetSceneObjectPart(PrimID); | 270 | SceneObjectPart part = scene.GetSceneObjectPart(PrimID); |
251 | 271 | ||
252 | if (data == null) | 272 | if (data == null || data.Length <= 1) |
253 | { | 273 | { |
254 | string msg = | 274 | string msg = |
255 | String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url); | 275 | String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url); |
@@ -287,34 +307,51 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
287 | asset.Data = assetData; | 307 | asset.Data = assetData; |
288 | asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000); | 308 | asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000); |
289 | asset.Type = 0; | 309 | asset.Type = 0; |
290 | asset.Description = "dynamic image"; | 310 | asset.Description = String.Format("URL image : {0}", Url); |
291 | asset.Local = false; | 311 | asset.Local = false; |
292 | asset.Temporary = true; | 312 | asset.Temporary = true; |
293 | scene.AssetService.Store(asset); | 313 | scene.AssetService.Store(asset); |
294 | 314 | ||
295 | LastAssetID = asset.FullID; | ||
296 | |||
297 | IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>(); | 315 | IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>(); |
298 | if (cacheLayerDecode != null) | 316 | if (cacheLayerDecode != null) |
299 | { | 317 | { |
300 | cacheLayerDecode.syncdecode(asset.FullID, asset.Data); | 318 | cacheLayerDecode.syncdecode(asset.FullID, asset.Data); |
319 | cacheLayerDecode = null; | ||
320 | LastAssetID = asset.FullID; | ||
301 | } | 321 | } |
302 | cacheLayerDecode = null; | ||
303 | 322 | ||
304 | // mostly keep the values from before | 323 | // mostly keep the values from before |
305 | Primitive.TextureEntry tmptex = part.Shape.Textures; | 324 | Primitive.TextureEntry tmptex = part.Shape.Textures; |
306 | 325 | ||
307 | // remove the old asset from the cache | 326 | // remove the old asset from the cache later |
308 | // UUID oldID = tmptex.DefaultTexture.TextureID; | 327 | UUID oldID = tmptex.DefaultTexture.TextureID; |
309 | 328 | ||
310 | tmptex.DefaultTexture.TextureID = asset.FullID; | 329 | if (Face == ALL_SIDES) |
330 | { | ||
331 | tmptex.DefaultTexture.TextureID = asset.FullID; | ||
332 | } | ||
333 | else | ||
334 | { | ||
335 | try | ||
336 | { | ||
337 | Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face); | ||
338 | texface.TextureID = asset.FullID; | ||
339 | tmptex.FaceTextures[Face] = texface; | ||
340 | } | ||
341 | catch(Exception) | ||
342 | { | ||
343 | tmptex.DefaultTexture.TextureID = asset.FullID; | ||
344 | } | ||
345 | } | ||
346 | |||
311 | // I'm pretty sure we always want to force this to true | 347 | // I'm pretty sure we always want to force this to true |
312 | // I'm pretty sure noone whats to set fullbright true if it wasn't true before. | 348 | // I'm pretty sure noone whats to set fullbright true if it wasn't true before. |
313 | // tmptex.DefaultTexture.Fullbright = true; | 349 | // tmptex.DefaultTexture.Fullbright = true; |
314 | 350 | ||
315 | part.Shape.Textures = tmptex; | 351 | part.UpdateTexture(tmptex); |
316 | part.ScheduleFullUpdate(); | 352 | |
317 | 353 | // scene.CommsManager.AssetCache.ExpireAsset(oldID); | |
354 | scene.AssetService.Delete(oldID.ToString()); | ||
318 | } | 355 | } |
319 | 356 | ||
320 | private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha) | 357 | private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha) |
diff --git a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs index 864d6ac..61c37b9 100644 --- a/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/LoadImageURL/LoadImageURLModule.cs | |||
@@ -162,62 +162,80 @@ namespace OpenSim.Region.CoreModules.Scripting.LoadImageURL | |||
162 | 162 | ||
163 | private void HttpRequestReturn(IAsyncResult result) | 163 | private void HttpRequestReturn(IAsyncResult result) |
164 | { | 164 | { |
165 | |||
165 | RequestState state = (RequestState) result.AsyncState; | 166 | RequestState state = (RequestState) result.AsyncState; |
166 | WebRequest request = (WebRequest) state.Request; | 167 | WebRequest request = (WebRequest) state.Request; |
168 | Stream stream = null; | ||
169 | byte[] imageJ2000 = new byte[0]; | ||
170 | |||
167 | try | 171 | try |
168 | { | 172 | { |
169 | HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); | 173 | HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); |
170 | if (response.StatusCode == HttpStatusCode.OK) | 174 | if (response != null && response.StatusCode == HttpStatusCode.OK) |
171 | { | 175 | { |
172 | Bitmap image = new Bitmap(response.GetResponseStream()); | 176 | stream = response.GetResponseStream(); |
173 | Size newsize; | 177 | if(stream != null) |
174 | |||
175 | // TODO: make this a bit less hard coded | ||
176 | if ((image.Height < 64) && (image.Width < 64)) | ||
177 | { | ||
178 | newsize = new Size(32, 32); | ||
179 | } | ||
180 | else if ((image.Height < 128) && (image.Width < 128)) | ||
181 | { | ||
182 | newsize = new Size(64, 64); | ||
183 | } | ||
184 | else if ((image.Height < 256) && (image.Width < 256)) | ||
185 | { | ||
186 | newsize = new Size(128, 128); | ||
187 | } | ||
188 | else if ((image.Height < 512 && image.Width < 512)) | ||
189 | { | ||
190 | newsize = new Size(256, 256); | ||
191 | } | ||
192 | else if ((image.Height < 1024 && image.Width < 1024)) | ||
193 | { | 178 | { |
194 | newsize = new Size(512, 512); | 179 | Bitmap image = new Bitmap(stream); |
180 | Size newsize; | ||
181 | |||
182 | // TODO: make this a bit less hard coded | ||
183 | if ((image.Height < 64) && (image.Width < 64)) | ||
184 | { | ||
185 | newsize = new Size(32, 32); | ||
186 | } | ||
187 | else if ((image.Height < 128) && (image.Width < 128)) | ||
188 | { | ||
189 | newsize = new Size(64, 64); | ||
190 | } | ||
191 | else if ((image.Height < 256) && (image.Width < 256)) | ||
192 | { | ||
193 | newsize = new Size(128, 128); | ||
194 | } | ||
195 | else if ((image.Height < 512 && image.Width < 512)) | ||
196 | { | ||
197 | newsize = new Size(256, 256); | ||
198 | } | ||
199 | else if ((image.Height < 1024 && image.Width < 1024)) | ||
200 | { | ||
201 | newsize = new Size(512, 512); | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | newsize = new Size(1024, 1024); | ||
206 | } | ||
207 | |||
208 | Bitmap resize = new Bitmap(image, newsize); | ||
209 | |||
210 | try | ||
211 | { | ||
212 | imageJ2000 = OpenJPEG.EncodeFromImage(resize, true); | ||
213 | } | ||
214 | catch (Exception) | ||
215 | { | ||
216 | m_log.Error("[LOADIMAGEURLMODULE]: OpenJpeg Encode Failed. Empty byte data returned!"); | ||
217 | } | ||
195 | } | 218 | } |
196 | else | 219 | else |
197 | { | 220 | { |
198 | newsize = new Size(1024, 1024); | 221 | m_log.WarnFormat("[LOADIMAGEURLMODULE] No data returned"); |
199 | } | ||
200 | |||
201 | Bitmap resize = new Bitmap(image, newsize); | ||
202 | byte[] imageJ2000 = new byte[0]; | ||
203 | |||
204 | try | ||
205 | { | ||
206 | imageJ2000 = OpenJPEG.EncodeFromImage(resize, true); | ||
207 | } | ||
208 | catch (Exception) | ||
209 | { | ||
210 | m_log.Error("[LOADIMAGEURLMODULE]: OpenJpeg Encode Failed. Empty byte data returned!"); | ||
211 | } | 222 | } |
212 | |||
213 | m_textureManager.ReturnData(state.RequestID, imageJ2000); | ||
214 | return; | ||
215 | } | 223 | } |
216 | } | 224 | } |
217 | catch (WebException) | 225 | catch (WebException) |
218 | { | 226 | { |
219 | 227 | ||
220 | } | 228 | } |
229 | finally | ||
230 | { | ||
231 | if(stream != null) | ||
232 | { | ||
233 | stream.Close(); | ||
234 | } | ||
235 | } | ||
236 | m_log.DebugFormat("[LOADIMAGEURLMODULE] Returning {0} bytes of image data for request {1}", | ||
237 | imageJ2000.Length, state.RequestID); | ||
238 | m_textureManager.ReturnData(state.RequestID, imageJ2000); | ||
221 | } | 239 | } |
222 | 240 | ||
223 | #region Nested type: RequestState | 241 | #region Nested type: RequestState |