aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs147
1 files changed, 81 insertions, 66 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs
index a686a4d..090cb7d 100644
--- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs
@@ -135,17 +135,13 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
135 m_reuseableDynamicTextures.Store( 135 m_reuseableDynamicTextures.Store(
136 GenerateReusableTextureKey(texture.InputCommands, texture.InputParams), newTextureID); 136 GenerateReusableTextureKey(texture.InputCommands, texture.InputParams), newTextureID);
137 } 137 }
138 updater.newTextureID = newTextureID;
138 } 139 }
139 }
140 140
141 if (updater.UpdateTimer == 0)
142 {
143 lock (Updaters) 141 lock (Updaters)
144 { 142 {
145 if (!Updaters.ContainsKey(updater.UpdaterID)) 143 if (Updaters.ContainsKey(updater.UpdaterID))
146 {
147 Updaters.Remove(updater.UpdaterID); 144 Updaters.Remove(updater.UpdaterID);
148 }
149 } 145 }
150 } 146 }
151 } 147 }
@@ -172,21 +168,20 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
172 } 168 }
173 169
174 public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, 170 public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url,
175 string extraParams, int updateTimer) 171 string extraParams)
176 { 172 {
177 return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, false, 255); 173 return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, false, 255);
178 } 174 }
179 175
180 public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, 176 public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url,
181 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) 177 string extraParams, bool SetBlending, byte AlphaValue)
182 { 178 {
183 return AddDynamicTextureURL(simID, primID, contentType, url, 179 return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, SetBlending,
184 extraParams, updateTimer, SetBlending, 180 (DISP_TEMP|DISP_EXPIRE), AlphaValue, ALL_SIDES);
185 (int)(DISP_TEMP|DISP_EXPIRE), AlphaValue, ALL_SIDES);
186 } 181 }
187 182
188 public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, 183 public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url,
189 string extraParams, int updateTimer, bool SetBlending, 184 string extraParams, bool SetBlending,
190 int disp, byte AlphaValue, int face) 185 int disp, byte AlphaValue, int face)
191 { 186 {
192 if (RenderPlugins.ContainsKey(contentType)) 187 if (RenderPlugins.ContainsKey(contentType))
@@ -196,7 +191,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
196 updater.PrimID = primID; 191 updater.PrimID = primID;
197 updater.ContentType = contentType; 192 updater.ContentType = contentType;
198 updater.Url = url; 193 updater.Url = url;
199 updater.UpdateTimer = updateTimer;
200 updater.UpdaterID = UUID.Random(); 194 updater.UpdaterID = UUID.Random();
201 updater.Params = extraParams; 195 updater.Params = extraParams;
202 updater.BlendWithOldTexture = SetBlending; 196 updater.BlendWithOldTexture = SetBlending;
@@ -213,26 +207,27 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
213 } 207 }
214 208
215 RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams); 209 RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams);
216 return updater.UpdaterID; 210 return updater.newTextureID;
217 } 211 }
218 return UUID.Zero; 212 return UUID.Zero;
219 } 213 }
220 214
221 public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, 215 public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data,
222 string extraParams, int updateTimer) 216 string extraParams)
223 { 217 {
224 return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, false, 255); 218 return AddDynamicTextureData(simID, primID, contentType, data, extraParams, false,
219 (DISP_TEMP|DISP_EXPIRE), 255, ALL_SIDES);
225 } 220 }
226 221
227 public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, 222 public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data,
228 string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) 223 string extraParams, bool SetBlending, byte AlphaValue)
229 { 224 {
230 return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, SetBlending, 225 return AddDynamicTextureData(simID, primID, contentType, data, extraParams, SetBlending,
231 (int) (DISP_TEMP|DISP_EXPIRE), AlphaValue, ALL_SIDES); 226 (DISP_TEMP|DISP_EXPIRE), AlphaValue, ALL_SIDES);
232 } 227 }
233 228
234 public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, 229 public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data,
235 string extraParams, int updateTimer, bool SetBlending, int disp, byte AlphaValue, int face) 230 string extraParams, bool SetBlending, int disp, byte AlphaValue, int face)
236 { 231 {
237 if (!RenderPlugins.ContainsKey(contentType)) 232 if (!RenderPlugins.ContainsKey(contentType))
238 return UUID.Zero; 233 return UUID.Zero;
@@ -258,7 +253,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
258 updater.PrimID = primID; 253 updater.PrimID = primID;
259 updater.ContentType = contentType; 254 updater.ContentType = contentType;
260 updater.BodyData = data; 255 updater.BodyData = data;
261 updater.UpdateTimer = updateTimer;
262 updater.UpdaterID = UUID.Random(); 256 updater.UpdaterID = UUID.Random();
263 updater.Params = extraParams; 257 updater.Params = extraParams;
264 updater.BlendWithOldTexture = SetBlending; 258 updater.BlendWithOldTexture = SetBlending;
@@ -314,7 +308,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
314 updater.UpdatePart(part, (UUID)objReusableTextureUUID); 308 updater.UpdatePart(part, (UUID)objReusableTextureUUID);
315 } 309 }
316 310
317 return updater.UpdaterID; 311 return updater.newTextureID;
318 } 312 }
319 313
320 private string GenerateReusableTextureKey(string data, string extraParams) 314 private string GenerateReusableTextureKey(string data, string extraParams)
@@ -404,17 +398,15 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
404 public byte FrontAlpha = 255; 398 public byte FrontAlpha = 255;
405 public string Params; 399 public string Params;
406 public UUID PrimID; 400 public UUID PrimID;
407 public bool SetNewFrontAlpha = false;
408 public UUID SimUUID; 401 public UUID SimUUID;
409 public UUID UpdaterID; 402 public UUID UpdaterID;
410 public int UpdateTimer;
411 public int Face; 403 public int Face;
412 public int Disp; 404 public int Disp;
413 public string Url; 405 public string Url;
406 public UUID newTextureID;
414 407
415 public DynamicTextureUpdater() 408 public DynamicTextureUpdater()
416 { 409 {
417 UpdateTimer = 0;
418 BodyData = null; 410 BodyData = null;
419 } 411 }
420 412
@@ -436,16 +428,23 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
436 // FIXME: Need to return the appropriate ID if only a single face is replaced. 428 // FIXME: Need to return the appropriate ID if only a single face is replaced.
437 oldID = tmptex.DefaultTexture.TextureID; 429 oldID = tmptex.DefaultTexture.TextureID;
438 430
431 // not using parts number of faces because that fails on old meshs
439 if (Face == ALL_SIDES) 432 if (Face == ALL_SIDES)
440 { 433 {
441 oldID = tmptex.DefaultTexture.TextureID; 434 oldID = tmptex.DefaultTexture.TextureID;
442 tmptex.DefaultTexture.TextureID = textureID; 435 tmptex.DefaultTexture.TextureID = textureID;
436 for(int i = 0; i < tmptex.FaceTextures.Length; i++)
437 {
438 if(tmptex.FaceTextures[i] != null)
439 tmptex.FaceTextures[i].TextureID = textureID;
440 }
443 } 441 }
444 else 442 else
445 { 443 {
446 try 444 try
447 { 445 {
448 Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face); 446 Primitive.TextureEntryFace texface = tmptex.CreateFace((uint)Face);
447 oldID = texface.TextureID;
449 texface.TextureID = textureID; 448 texface.TextureID = textureID;
450 tmptex.FaceTextures[Face] = texface; 449 tmptex.FaceTextures[Face] = texface;
451 } 450 }
@@ -455,10 +454,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
455 } 454 }
456 } 455 }
457 456
458 // I'm pretty sure we always want to force this to true
459 // I'm pretty sure noone whats to set fullbright true if it wasn't true before.
460 // tmptex.DefaultTexture.Fullbright = true;
461
462 part.UpdateTextureEntry(tmptex.GetBytes()); 457 part.UpdateTextureEntry(tmptex.GetBytes());
463 } 458 }
464 459
@@ -478,26 +473,39 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
478 473
479 if (part == null || data == null || data.Length <= 1) 474 if (part == null || data == null || data.Length <= 1)
480 { 475 {
481 string msg = 476 string msg =
482 String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url); 477 String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url);
483 scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say, 478 scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say,
484 0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false); 479 0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false);
485 480
486 return UUID.Zero; 481 return UUID.Zero;
487 } 482 }
488 483
489 byte[] assetData = null; 484 byte[] assetData = null;
490 AssetBase oldAsset = null; 485 AssetBase oldAsset = null;
491 486
492 if (BlendWithOldTexture) 487 if (BlendWithOldTexture)
493 { 488 {
494 Primitive.TextureEntryFace defaultFace = part.Shape.Textures.DefaultTexture; 489 Primitive.TextureEntryFace curFace;
495 if (defaultFace != null) 490 if(Face == ALL_SIDES)
491 curFace = part.Shape.Textures.DefaultTexture;
492 else
496 { 493 {
497 oldAsset = scene.AssetService.Get(defaultFace.TextureID.ToString()); 494 try
495 {
496 curFace = part.Shape.Textures.GetFace((uint)Face);
497 }
498 catch
499 {
500 curFace = null;
501 }
502 }
503 if (curFace != null)
504 {
505 oldAsset = scene.AssetService.Get(curFace.TextureID.ToString());
498 506
499 if (oldAsset != null) 507 if (oldAsset != null)
500 assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha); 508 assetData = BlendTextures(data, oldAsset.Data, FrontAlpha);
501 } 509 }
502 } 510 }
503 511
@@ -548,42 +556,49 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
548 return asset.FullID; 556 return asset.FullID;
549 } 557 }
550 558
551 private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha) 559 private byte[] BlendTextures(byte[] frontImage, byte[] backImage, byte newAlpha)
552 { 560 {
553 ManagedImage managedImage; 561 ManagedImage managedImage;
554 Image image; 562 Image image;
555 563
556 if (OpenJPEG.DecodeToImage(frontImage, out managedImage, out image)) 564 if (!OpenJPEG.DecodeToImage(frontImage, out managedImage, out image) || image == null)
565 return null;
566
567 Bitmap image1 = new Bitmap(image);
568 image.Dispose();
569
570 if (!OpenJPEG.DecodeToImage(backImage, out managedImage, out image) || image == null)
557 { 571 {
558 Bitmap image1 = new Bitmap(image); 572 image1.Dispose();
573 return null;
574 }
559 575
560 if (OpenJPEG.DecodeToImage(backImage, out managedImage, out image)) 576 Bitmap image2 = new Bitmap(image);
561 { 577 image.Dispose();
562 Bitmap image2 = new Bitmap(image);
563 578
564 if (setNewAlpha) 579 if (newAlpha < 255)
565 SetAlpha(ref image1, newAlpha); 580 SetAlpha(ref image1, newAlpha);
566 581
567 Bitmap joint = MergeBitMaps(image1, image2); 582 using(Bitmap joint = MergeBitMaps(image1, image2))
583 {
584 image1.Dispose();
585 image2.Dispose();
568 586
569 byte[] result = new byte[0]; 587 byte[] result = new byte[0];
570 588
571 try 589 try
572 { 590 {
573 result = OpenJPEG.EncodeFromImage(joint, true); 591 result = OpenJPEG.EncodeFromImage(joint, true);
574 } 592 }
575 catch (Exception e) 593 catch (Exception e)
576 { 594 {
577 m_log.ErrorFormat( 595 m_log.ErrorFormat(
578 "[DYNAMICTEXTUREMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", 596 "[DYNAMICTEXTUREMODULE]: OpenJpeg Encode Failed. Exception {0}{1}",
579 e.Message, e.StackTrace); 597 e.Message, e.StackTrace);
580 }
581
582 return result;
583 } 598 }
584 }
585 599
586 return null; 600 return result;
601 }
587 } 602 }
588 603
589 public Bitmap MergeBitMaps(Bitmap front, Bitmap back) 604 public Bitmap MergeBitMaps(Bitmap front, Bitmap back)
@@ -592,12 +607,12 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
592 Graphics jG; 607 Graphics jG;
593 608
594 joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb); 609 joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb);
595 jG = Graphics.FromImage(joint); 610 using(jG = Graphics.FromImage(joint))
596 611 {
597 jG.DrawImage(back, 0, 0, back.Width, back.Height); 612 jG.DrawImage(back, 0, 0, back.Width, back.Height);
598 jG.DrawImage(front, 0, 0, back.Width, back.Height); 613 jG.DrawImage(front, 0, 0, back.Width, back.Height);
599 614 return joint;
600 return joint; 615 }
601 } 616 }
602 617
603 private void SetAlpha(ref Bitmap b, byte alpha) 618 private void SetAlpha(ref Bitmap b, byte alpha)