aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/DynamicTextureModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/DynamicTextureModule.cs94
1 files changed, 90 insertions, 4 deletions
diff --git a/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs b/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
index fe7b763..2988feb 100644
--- a/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
+++ b/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
@@ -27,12 +27,14 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Drawing;
30using System.Collections.Generic; 31using System.Collections.Generic;
31using libsecondlife; 32using libsecondlife;
32using Nini.Config; 33using Nini.Config;
33using OpenSim.Framework; 34using OpenSim.Framework;
34using OpenSim.Region.Environment.Interfaces; 35using OpenSim.Region.Environment.Interfaces;
35using OpenSim.Region.Environment.Scenes; 36using OpenSim.Region.Environment.Scenes;
37using OpenJPEGNet;
36 38
37namespace OpenSim.Region.Environment.Modules 39namespace OpenSim.Region.Environment.Modules
38{ 40{
@@ -93,9 +95,16 @@ namespace OpenSim.Region.Environment.Modules
93 } 95 }
94 } 96 }
95 97
98
96 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url, 99 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
97 string extraParams, int updateTimer) 100 string extraParams, int updateTimer)
98 { 101 {
102 return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, false, 255);
103 }
104
105 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
106 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
107 {
99 if (RenderPlugins.ContainsKey(contentType)) 108 if (RenderPlugins.ContainsKey(contentType))
100 { 109 {
101 //Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType); 110 //Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
@@ -108,6 +117,8 @@ namespace OpenSim.Region.Environment.Modules
108 updater.UpdateTimer = updateTimer; 117 updater.UpdateTimer = updateTimer;
109 updater.UpdaterID = LLUUID.Random(); 118 updater.UpdaterID = LLUUID.Random();
110 updater.Params = extraParams; 119 updater.Params = extraParams;
120 updater.BlendWithOldTexture = SetBlending;
121 updater.FrontAlpha = AlphaValue;
111 122
112 if (!Updaters.ContainsKey(updater.UpdaterID)) 123 if (!Updaters.ContainsKey(updater.UpdaterID))
113 { 124 {
@@ -121,7 +132,13 @@ namespace OpenSim.Region.Environment.Modules
121 } 132 }
122 133
123 public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data, 134 public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
124 string extraParams, int updateTimer) 135 string extraParams, int updateTimer)
136 {
137 return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, false, 255);
138 }
139
140 public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
141 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
125 { 142 {
126 if (RenderPlugins.ContainsKey(contentType)) 143 if (RenderPlugins.ContainsKey(contentType))
127 { 144 {
@@ -133,6 +150,8 @@ namespace OpenSim.Region.Environment.Modules
133 updater.UpdateTimer = updateTimer; 150 updater.UpdateTimer = updateTimer;
134 updater.UpdaterID = LLUUID.Random(); 151 updater.UpdaterID = LLUUID.Random();
135 updater.Params = extraParams; 152 updater.Params = extraParams;
153 updater.BlendWithOldTexture = SetBlending;
154 updater.FrontAlpha = AlphaValue;
136 155
137 if (!Updaters.ContainsKey(updater.UpdaterID)) 156 if (!Updaters.ContainsKey(updater.UpdaterID))
138 { 157 {
@@ -156,6 +175,9 @@ namespace OpenSim.Region.Environment.Modules
156 public int UpdateTimer; 175 public int UpdateTimer;
157 public LLUUID LastAssetID; 176 public LLUUID LastAssetID;
158 public string Params; 177 public string Params;
178 public bool BlendWithOldTexture = false;
179 public bool SetNewFrontAlpha = false;
180 public byte FrontAlpha = 255;
159 181
160 public DynamicTextureUpdater() 182 public DynamicTextureUpdater()
161 { 183 {
@@ -166,9 +188,30 @@ namespace OpenSim.Region.Environment.Modules
166 188
167 public void DataReceived(byte[] data, Scene scene) 189 public void DataReceived(byte[] data, Scene scene)
168 { 190 {
191 SceneObjectPart part = scene.GetSceneObjectPart(PrimID);
192 byte[] assetData;
193 AssetBase oldAsset = null;
194 if (BlendWithOldTexture)
195 {
196 LLUUID lastTextureID = part.Shape.Textures.DefaultTexture.TextureID;
197 oldAsset = scene.AssetCache.GetAsset(lastTextureID, true);
198 if (oldAsset != null)
199 {
200 assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha);
201 }
202 else
203 {
204 assetData = new byte[data.Length];
205 Array.Copy(data, assetData, data.Length);
206 }
207 }
208 else
209 {
210 assetData = new byte[data.Length];
211 Array.Copy(data, assetData, data.Length);
212 }
213
169 //TODO delete the last asset(data), if it was a dynamic texture 214 //TODO delete the last asset(data), if it was a dynamic texture
170 byte[] assetData = new byte[data.Length];
171 Array.Copy(data, assetData, data.Length);
172 AssetBase asset = new AssetBase(); 215 AssetBase asset = new AssetBase();
173 asset.FullID = LLUUID.Random(); 216 asset.FullID = LLUUID.Random();
174 asset.Data = assetData; 217 asset.Data = assetData;
@@ -181,10 +224,53 @@ namespace OpenSim.Region.Environment.Modules
181 224
182 LastAssetID = asset.FullID; 225 LastAssetID = asset.FullID;
183 226
184 SceneObjectPart part = scene.GetSceneObjectPart(PrimID); 227
185 part.Shape.Textures = new LLObject.TextureEntry(asset.FullID); 228 part.Shape.Textures = new LLObject.TextureEntry(asset.FullID);
186 part.ScheduleFullUpdate(); 229 part.ScheduleFullUpdate();
187 } 230 }
231
232 private byte[] BlendTextures(byte[] frontImage, byte[] backImage)
233 {
234 return BlendTextures(frontImage, backImage, false, 0);
235 }
236
237 private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha)
238 {
239 Bitmap image1 = new Bitmap(OpenJPEG.DecodeToImage(frontImage));
240 Bitmap image2 = new Bitmap(OpenJPEG.DecodeToImage(backImage));
241 if (setNewAlpha)
242 {
243 SetAlpha(ref image1, newAlpha);
244 }
245 Bitmap joint = MergeBitMaps(image1, image2);
246
247 return OpenJPEG.EncodeFromImage(joint, true);
248 }
249
250 public Bitmap MergeBitMaps(Bitmap front, Bitmap back)
251 {
252 Bitmap joint;
253 Graphics jG;
254
255 joint = new Bitmap(back.Width, back.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
256 jG = Graphics.FromImage(joint);
257
258 jG.DrawImage(back, 0, 0, back.Width, back.Height);
259 jG.DrawImage(front, 0, 0, back.Width, back.Height);
260
261 return joint;
262 }
263
264 private void SetAlpha(ref Bitmap b, byte alpha)
265 {
266 for (int w = 0; w < b.Width; w++)
267 {
268 for (int h = 0; h < b.Height; h++)
269 {
270 b.SetPixel(w, h, Color.FromArgb(alpha, b.GetPixel(w, h)));
271 }
272 }
273 }
188 } 274 }
189 } 275 }
190} \ No newline at end of file 276} \ No newline at end of file