diff options
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index 00c4682..53a5fd1 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Drawing; | 30 | using System.Drawing; |
31 | using System.Drawing.Drawing2D; | ||
31 | using System.Drawing.Imaging; | 32 | using System.Drawing.Imaging; |
32 | using Nini.Config; | 33 | using Nini.Config; |
33 | using OpenMetaverse; | 34 | using OpenMetaverse; |
@@ -454,7 +455,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
454 | } | 455 | } |
455 | } | 456 | } |
456 | 457 | ||
457 | part.UpdateTextureEntry(tmptex.GetBytes()); | 458 | part.UpdateTextureEntry(tmptex); |
458 | } | 459 | } |
459 | 460 | ||
460 | return oldID; | 461 | return oldID; |
@@ -508,6 +509,9 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
508 | assetData = BlendTextures(data, oldAsset.Data, FrontAlpha); | 509 | assetData = BlendTextures(data, oldAsset.Data, FrontAlpha); |
509 | } | 510 | } |
510 | } | 511 | } |
512 | else if(FrontAlpha < 255) | ||
513 | assetData = BlendTextures(data, null, FrontAlpha); | ||
514 | |||
511 | 515 | ||
512 | if (assetData == null) | 516 | if (assetData == null) |
513 | { | 517 | { |
@@ -567,6 +571,25 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
567 | Bitmap image1 = new Bitmap(image); | 571 | Bitmap image1 = new Bitmap(image); |
568 | image.Dispose(); | 572 | image.Dispose(); |
569 | 573 | ||
574 | if(backImage == null) | ||
575 | { | ||
576 | SetAlpha(ref image1, newAlpha); | ||
577 | byte[] result = new byte[0]; | ||
578 | |||
579 | try | ||
580 | { | ||
581 | result = OpenJPEG.EncodeFromImage(image1, false); | ||
582 | } | ||
583 | catch (Exception e) | ||
584 | { | ||
585 | m_log.ErrorFormat( | ||
586 | "[DYNAMICTEXTUREMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", | ||
587 | e.Message, e.StackTrace); | ||
588 | } | ||
589 | image1.Dispose(); | ||
590 | return result; | ||
591 | } | ||
592 | |||
570 | if (!OpenJPEG.DecodeToImage(backImage, out managedImage, out image) || image == null) | 593 | if (!OpenJPEG.DecodeToImage(backImage, out managedImage, out image) || image == null) |
571 | { | 594 | { |
572 | image1.Dispose(); | 595 | image1.Dispose(); |
@@ -576,10 +599,7 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
576 | Bitmap image2 = new Bitmap(image); | 599 | Bitmap image2 = new Bitmap(image); |
577 | image.Dispose(); | 600 | image.Dispose(); |
578 | 601 | ||
579 | if (newAlpha < 255) | 602 | using(Bitmap joint = MergeBitMaps(image1, image2, newAlpha)) |
580 | SetAlpha(ref image1, newAlpha); | ||
581 | |||
582 | using(Bitmap joint = MergeBitMaps(image1, image2)) | ||
583 | { | 603 | { |
584 | image1.Dispose(); | 604 | image1.Dispose(); |
585 | image2.Dispose(); | 605 | image2.Dispose(); |
@@ -594,23 +614,49 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
594 | { | 614 | { |
595 | m_log.ErrorFormat( | 615 | m_log.ErrorFormat( |
596 | "[DYNAMICTEXTUREMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", | 616 | "[DYNAMICTEXTUREMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", |
597 | e.Message, e.StackTrace); | 617 | e.Message, e.StackTrace); |
598 | } | 618 | } |
599 | 619 | ||
600 | return result; | 620 | return result; |
601 | } | 621 | } |
602 | } | 622 | } |
603 | 623 | ||
604 | public Bitmap MergeBitMaps(Bitmap front, Bitmap back) | 624 | public Bitmap MergeBitMaps(Bitmap front, Bitmap back, byte alpha) |
605 | { | 625 | { |
606 | Bitmap joint; | 626 | Bitmap joint; |
607 | Graphics jG; | 627 | Graphics jG; |
628 | if(alpha >= 255) | ||
629 | { | ||
630 | joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb); | ||
631 | using (jG = Graphics.FromImage(joint)) | ||
632 | { | ||
633 | jG.CompositingMode = CompositingMode.SourceOver; | ||
634 | jG.CompositingQuality = CompositingQuality.HighQuality; | ||
635 | |||
636 | jG.DrawImage(back, 0, 0, back.Width, back.Height); | ||
637 | jG.DrawImage(front, 0, 0, back.Width, back.Height); | ||
638 | return joint; | ||
639 | } | ||
640 | } | ||
641 | ColorMatrix matrix = new ColorMatrix(new float[][]{ | ||
642 | new float[] {1F, 0, 0, 0, 0}, | ||
643 | new float[] {0, 1F, 0, 0, 0}, | ||
644 | new float[] {0, 0, 1F, 0, 0}, | ||
645 | new float[] {0, 0, 0, alpha/255f, 0}, | ||
646 | new float[] {0, 0, 0, 0, 1F}}); | ||
647 | |||
648 | ImageAttributes imageAttributes = new ImageAttributes(); | ||
608 | 649 | ||
650 | imageAttributes.SetColorMatrix(matrix); | ||
609 | joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb); | 651 | joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb); |
610 | using(jG = Graphics.FromImage(joint)) | 652 | using (jG = Graphics.FromImage(joint)) |
611 | { | 653 | { |
654 | jG.CompositingMode = CompositingMode.SourceOver; | ||
655 | jG.CompositingQuality = CompositingQuality.HighQuality; | ||
656 | |||
612 | jG.DrawImage(back, 0, 0, back.Width, back.Height); | 657 | jG.DrawImage(back, 0, 0, back.Width, back.Height); |
613 | jG.DrawImage(front, 0, 0, back.Width, back.Height); | 658 | if(alpha > 0) |
659 | jG.DrawImage(front, new Rectangle(0, 0, back.Width, back.Height), 0, 0, front.Width, front.Height, GraphicsUnit.Pixel,imageAttributes); | ||
614 | return joint; | 660 | return joint; |
615 | } | 661 | } |
616 | } | 662 | } |