aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Scripting/DynamicTexture
diff options
context:
space:
mode:
authorJeff Ames2008-05-01 14:31:30 +0000
committerJeff Ames2008-05-01 14:31:30 +0000
commitd51ce47b2d7635b17f3dd429158e8f59b78b83aa (patch)
treed3595bd5194199184059aa398b91a51dc6c799cf /OpenSim/Region/Environment/Modules/Scripting/DynamicTexture
parent* Looks like I had the bamboo build right in the first place - it was just th... (diff)
downloadopensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Scripting/DynamicTexture')
-rw-r--r--OpenSim/Region/Environment/Modules/Scripting/DynamicTexture/DynamicTextureModule.cs564
1 files changed, 282 insertions, 282 deletions
diff --git a/OpenSim/Region/Environment/Modules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/Environment/Modules/Scripting/DynamicTexture/DynamicTextureModule.cs
index 68ca5e9..c0e3d3b 100644
--- a/OpenSim/Region/Environment/Modules/Scripting/DynamicTexture/DynamicTextureModule.cs
+++ b/OpenSim/Region/Environment/Modules/Scripting/DynamicTexture/DynamicTextureModule.cs
@@ -1,283 +1,283 @@
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.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing; 30using System.Drawing;
31using System.Drawing.Imaging; 31using System.Drawing.Imaging;
32using libsecondlife; 32using libsecondlife;
33using Nini.Config; 33using Nini.Config;
34using OpenJPEGNet; 34using OpenJPEGNet;
35using OpenSim.Framework; 35using OpenSim.Framework;
36using OpenSim.Region.Environment.Interfaces; 36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes; 37using OpenSim.Region.Environment.Scenes;
38 38
39namespace OpenSim.Region.Environment.Modules.Scripting.DynamicTexture 39namespace OpenSim.Region.Environment.Modules.Scripting.DynamicTexture
40{ 40{
41 public class DynamicTextureModule : IRegionModule, IDynamicTextureManager 41 public class DynamicTextureModule : IRegionModule, IDynamicTextureManager
42 { 42 {
43 private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>(); 43 private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
44 44
45 private Dictionary<string, IDynamicTextureRender> RenderPlugins = 45 private Dictionary<string, IDynamicTextureRender> RenderPlugins =
46 new Dictionary<string, IDynamicTextureRender>(); 46 new Dictionary<string, IDynamicTextureRender>();
47 47
48 private Dictionary<LLUUID, DynamicTextureUpdater> Updaters = new Dictionary<LLUUID, DynamicTextureUpdater>(); 48 private Dictionary<LLUUID, DynamicTextureUpdater> Updaters = new Dictionary<LLUUID, DynamicTextureUpdater>();
49 49
50 #region IDynamicTextureManager Members 50 #region IDynamicTextureManager Members
51 51
52 public void RegisterRender(string handleType, IDynamicTextureRender render) 52 public void RegisterRender(string handleType, IDynamicTextureRender render)
53 { 53 {
54 if (!RenderPlugins.ContainsKey(handleType)) 54 if (!RenderPlugins.ContainsKey(handleType))
55 { 55 {
56 RenderPlugins.Add(handleType, render); 56 RenderPlugins.Add(handleType, render);
57 } 57 }
58 } 58 }
59 59
60 public void ReturnData(LLUUID id, byte[] data) 60 public void ReturnData(LLUUID id, byte[] data)
61 { 61 {
62 if (Updaters.ContainsKey(id)) 62 if (Updaters.ContainsKey(id))
63 { 63 {
64 DynamicTextureUpdater updater = Updaters[id]; 64 DynamicTextureUpdater updater = Updaters[id];
65 if (RegisteredScenes.ContainsKey(updater.SimUUID)) 65 if (RegisteredScenes.ContainsKey(updater.SimUUID))
66 { 66 {
67 Scene scene = RegisteredScenes[updater.SimUUID]; 67 Scene scene = RegisteredScenes[updater.SimUUID];
68 updater.DataReceived(data, scene); 68 updater.DataReceived(data, scene);
69 } 69 }
70 } 70 }
71 } 71 }
72 72
73 73
74 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url, 74 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
75 string extraParams, int updateTimer) 75 string extraParams, int updateTimer)
76 { 76 {
77 return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, false, 255); 77 return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, false, 255);
78 } 78 }
79 79
80 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url, 80 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
81 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) 81 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
82 { 82 {
83 if (RenderPlugins.ContainsKey(contentType)) 83 if (RenderPlugins.ContainsKey(contentType))
84 { 84 {
85 //Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType); 85 //Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
86 86
87 DynamicTextureUpdater updater = new DynamicTextureUpdater(); 87 DynamicTextureUpdater updater = new DynamicTextureUpdater();
88 updater.SimUUID = simID; 88 updater.SimUUID = simID;
89 updater.PrimID = primID; 89 updater.PrimID = primID;
90 updater.ContentType = contentType; 90 updater.ContentType = contentType;
91 updater.Url = url; 91 updater.Url = url;
92 updater.UpdateTimer = updateTimer; 92 updater.UpdateTimer = updateTimer;
93 updater.UpdaterID = LLUUID.Random(); 93 updater.UpdaterID = LLUUID.Random();
94 updater.Params = extraParams; 94 updater.Params = extraParams;
95 updater.BlendWithOldTexture = SetBlending; 95 updater.BlendWithOldTexture = SetBlending;
96 updater.FrontAlpha = AlphaValue; 96 updater.FrontAlpha = AlphaValue;
97 97
98 if (!Updaters.ContainsKey(updater.UpdaterID)) 98 if (!Updaters.ContainsKey(updater.UpdaterID))
99 { 99 {
100 Updaters.Add(updater.UpdaterID, updater); 100 Updaters.Add(updater.UpdaterID, updater);
101 } 101 }
102 102
103 RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams); 103 RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams);
104 return updater.UpdaterID; 104 return updater.UpdaterID;
105 } 105 }
106 return LLUUID.Zero; 106 return LLUUID.Zero;
107 } 107 }
108 108
109 public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data, 109 public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
110 string extraParams, int updateTimer) 110 string extraParams, int updateTimer)
111 { 111 {
112 return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, false, 255); 112 return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, false, 255);
113 } 113 }
114 114
115 public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data, 115 public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
116 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) 116 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
117 { 117 {
118 if (RenderPlugins.ContainsKey(contentType)) 118 if (RenderPlugins.ContainsKey(contentType))
119 { 119 {
120 DynamicTextureUpdater updater = new DynamicTextureUpdater(); 120 DynamicTextureUpdater updater = new DynamicTextureUpdater();
121 updater.SimUUID = simID; 121 updater.SimUUID = simID;
122 updater.PrimID = primID; 122 updater.PrimID = primID;
123 updater.ContentType = contentType; 123 updater.ContentType = contentType;
124 updater.BodyData = data; 124 updater.BodyData = data;
125 updater.UpdateTimer = updateTimer; 125 updater.UpdateTimer = updateTimer;
126 updater.UpdaterID = LLUUID.Random(); 126 updater.UpdaterID = LLUUID.Random();
127 updater.Params = extraParams; 127 updater.Params = extraParams;
128 updater.BlendWithOldTexture = SetBlending; 128 updater.BlendWithOldTexture = SetBlending;
129 updater.FrontAlpha = AlphaValue; 129 updater.FrontAlpha = AlphaValue;
130 130
131 if (!Updaters.ContainsKey(updater.UpdaterID)) 131 if (!Updaters.ContainsKey(updater.UpdaterID))
132 { 132 {
133 Updaters.Add(updater.UpdaterID, updater); 133 Updaters.Add(updater.UpdaterID, updater);
134 } 134 }
135 135
136 RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams); 136 RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams);
137 return updater.UpdaterID; 137 return updater.UpdaterID;
138 } 138 }
139 return LLUUID.Zero; 139 return LLUUID.Zero;
140 } 140 }
141 141
142 #endregion 142 #endregion
143 143
144 #region IRegionModule Members 144 #region IRegionModule Members
145 145
146 public void Initialise(Scene scene, IConfigSource config) 146 public void Initialise(Scene scene, IConfigSource config)
147 { 147 {
148 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) 148 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
149 { 149 {
150 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene); 150 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
151 scene.RegisterModuleInterface<IDynamicTextureManager>(this); 151 scene.RegisterModuleInterface<IDynamicTextureManager>(this);
152 } 152 }
153 } 153 }
154 154
155 public void PostInitialise() 155 public void PostInitialise()
156 { 156 {
157 } 157 }
158 158
159 public void Close() 159 public void Close()
160 { 160 {
161 } 161 }
162 162
163 public string Name 163 public string Name
164 { 164 {
165 get { return "DynamicTextureModule"; } 165 get { return "DynamicTextureModule"; }
166 } 166 }
167 167
168 public bool IsSharedModule 168 public bool IsSharedModule
169 { 169 {
170 get { return true; } 170 get { return true; }
171 } 171 }
172 172
173 #endregion 173 #endregion
174 174
175 #region Nested type: DynamicTextureUpdater 175 #region Nested type: DynamicTextureUpdater
176 176
177 public class DynamicTextureUpdater 177 public class DynamicTextureUpdater
178 { 178 {
179 public bool BlendWithOldTexture = false; 179 public bool BlendWithOldTexture = false;
180 public string BodyData; 180 public string BodyData;
181 public string ContentType; 181 public string ContentType;
182 public byte FrontAlpha = 255; 182 public byte FrontAlpha = 255;
183 public LLUUID LastAssetID; 183 public LLUUID LastAssetID;
184 public string Params; 184 public string Params;
185 public LLUUID PrimID; 185 public LLUUID PrimID;
186 public bool SetNewFrontAlpha = false; 186 public bool SetNewFrontAlpha = false;
187 public LLUUID SimUUID; 187 public LLUUID SimUUID;
188 public LLUUID UpdaterID; 188 public LLUUID UpdaterID;
189 public int UpdateTimer; 189 public int UpdateTimer;
190 public string Url; 190 public string Url;
191 191
192 public DynamicTextureUpdater() 192 public DynamicTextureUpdater()
193 { 193 {
194 LastAssetID = LLUUID.Zero; 194 LastAssetID = LLUUID.Zero;
195 UpdateTimer = 0; 195 UpdateTimer = 0;
196 BodyData = null; 196 BodyData = null;
197 } 197 }
198 198
199 public void DataReceived(byte[] data, Scene scene) 199 public void DataReceived(byte[] data, Scene scene)
200 { 200 {
201 SceneObjectPart part = scene.GetSceneObjectPart(PrimID); 201 SceneObjectPart part = scene.GetSceneObjectPart(PrimID);
202 byte[] assetData; 202 byte[] assetData;
203 AssetBase oldAsset = null; 203 AssetBase oldAsset = null;
204 if (BlendWithOldTexture) 204 if (BlendWithOldTexture)
205 { 205 {
206 LLUUID lastTextureID = part.Shape.Textures.DefaultTexture.TextureID; 206 LLUUID lastTextureID = part.Shape.Textures.DefaultTexture.TextureID;
207 oldAsset = scene.AssetCache.GetAsset(lastTextureID, true); 207 oldAsset = scene.AssetCache.GetAsset(lastTextureID, true);
208 if (oldAsset != null) 208 if (oldAsset != null)
209 { 209 {
210 assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha); 210 assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha);
211 } 211 }
212 else 212 else
213 { 213 {
214 assetData = new byte[data.Length]; 214 assetData = new byte[data.Length];
215 Array.Copy(data, assetData, data.Length); 215 Array.Copy(data, assetData, data.Length);
216 } 216 }
217 } 217 }
218 else 218 else
219 { 219 {
220 assetData = new byte[data.Length]; 220 assetData = new byte[data.Length];
221 Array.Copy(data, assetData, data.Length); 221 Array.Copy(data, assetData, data.Length);
222 } 222 }
223 223
224 //TODO delete the last asset(data), if it was a dynamic texture 224 //TODO delete the last asset(data), if it was a dynamic texture
225 AssetBase asset = new AssetBase(); 225 AssetBase asset = new AssetBase();
226 asset.FullID = LLUUID.Random(); 226 asset.FullID = LLUUID.Random();
227 asset.Data = assetData; 227 asset.Data = assetData;
228 asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000); 228 asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
229 asset.Type = 0; 229 asset.Type = 0;
230 asset.Description = "dynamic image"; 230 asset.Description = "dynamic image";
231 asset.Local = false; 231 asset.Local = false;
232 asset.Temporary = true; 232 asset.Temporary = true;
233 scene.AssetCache.AddAsset(asset); 233 scene.AssetCache.AddAsset(asset);
234 234
235 LastAssetID = asset.FullID; 235 LastAssetID = asset.FullID;
236 236
237 237
238 part.Shape.Textures = new LLObject.TextureEntry(asset.FullID); 238 part.Shape.Textures = new LLObject.TextureEntry(asset.FullID);
239 part.ScheduleFullUpdate(); 239 part.ScheduleFullUpdate();
240 } 240 }
241 241
242 private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha) 242 private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha)
243 { 243 {
244 Bitmap image1 = new Bitmap(OpenJPEG.DecodeToImage(frontImage)); 244 Bitmap image1 = new Bitmap(OpenJPEG.DecodeToImage(frontImage));
245 Bitmap image2 = new Bitmap(OpenJPEG.DecodeToImage(backImage)); 245 Bitmap image2 = new Bitmap(OpenJPEG.DecodeToImage(backImage));
246 if (setNewAlpha) 246 if (setNewAlpha)
247 { 247 {
248 SetAlpha(ref image1, newAlpha); 248 SetAlpha(ref image1, newAlpha);
249 } 249 }
250 Bitmap joint = MergeBitMaps(image1, image2); 250 Bitmap joint = MergeBitMaps(image1, image2);
251 251
252 return OpenJPEG.EncodeFromImage(joint, true); 252 return OpenJPEG.EncodeFromImage(joint, true);
253 } 253 }
254 254
255 public Bitmap MergeBitMaps(Bitmap front, Bitmap back) 255 public Bitmap MergeBitMaps(Bitmap front, Bitmap back)
256 { 256 {
257 Bitmap joint; 257 Bitmap joint;
258 Graphics jG; 258 Graphics jG;
259 259
260 joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb); 260 joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb);
261 jG = Graphics.FromImage(joint); 261 jG = Graphics.FromImage(joint);
262 262
263 jG.DrawImage(back, 0, 0, back.Width, back.Height); 263 jG.DrawImage(back, 0, 0, back.Width, back.Height);
264 jG.DrawImage(front, 0, 0, back.Width, back.Height); 264 jG.DrawImage(front, 0, 0, back.Width, back.Height);
265 265
266 return joint; 266 return joint;
267 } 267 }
268 268
269 private void SetAlpha(ref Bitmap b, byte alpha) 269 private void SetAlpha(ref Bitmap b, byte alpha)
270 { 270 {
271 for (int w = 0; w < b.Width; w++) 271 for (int w = 0; w < b.Width; w++)
272 { 272 {
273 for (int h = 0; h < b.Height; h++) 273 for (int h = 0; h < b.Height; h++)
274 { 274 {
275 b.SetPixel(w, h, Color.FromArgb(alpha, b.GetPixel(w, h))); 275 b.SetPixel(w, h, Color.FromArgb(alpha, b.GetPixel(w, h)));
276 } 276 }
277 } 277 }
278 } 278 }
279 } 279 }
280 280
281 #endregion 281 #endregion
282 } 282 }
283} \ No newline at end of file 283} \ No newline at end of file