mantis 8442 more changes to alpha blending

0.9.1.0-post-fixes
UbitUmarov 2019-01-16 20:24:16 +00:00
parent d8e5b7385e
commit b2810c4ca7
2 changed files with 63 additions and 23 deletions

View File

@ -625,19 +625,40 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
{ {
Bitmap joint; Bitmap joint;
Graphics jG; Graphics jG;
if(alpha >= 255) int Width = back.Width;
int Height = back.Height;
PixelFormat format;
if(alpha < 255 || front.PixelFormat == PixelFormat.Format32bppArgb || back.PixelFormat == PixelFormat.Format32bppArgb)
format = PixelFormat.Format32bppArgb;
else
format = PixelFormat.Format32bppRgb;
joint = new Bitmap(Width, Height, format);
if (alpha >= 255)
{ {
joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb);
using (jG = Graphics.FromImage(joint)) using (jG = Graphics.FromImage(joint))
{ {
jG.CompositingMode = CompositingMode.SourceOver;
jG.CompositingQuality = CompositingQuality.HighQuality; jG.CompositingQuality = CompositingQuality.HighQuality;
jG.DrawImage(back, 0, 0, back.Width, back.Height); jG.CompositingMode = CompositingMode.SourceCopy;
jG.DrawImage(front, 0, 0, back.Width, back.Height); jG.DrawImage(back, 0, 0, Width, Height);
jG.CompositingMode = CompositingMode.SourceOver;
jG.DrawImage(front, 0, 0, Width, Height);
return joint; return joint;
} }
} }
using (jG = Graphics.FromImage(joint))
{
jG.CompositingQuality = CompositingQuality.HighQuality;
jG.CompositingMode = CompositingMode.SourceCopy;
jG.DrawImage(back, 0, 0, Width, Height);
if (alpha > 0)
{
ColorMatrix matrix = new ColorMatrix(new float[][]{ ColorMatrix matrix = new ColorMatrix(new float[][]{
new float[] {1F, 0, 0, 0, 0}, new float[] {1F, 0, 0, 0, 0},
new float[] {0, 1F, 0, 0, 0}, new float[] {0, 1F, 0, 0, 0},
@ -646,30 +667,43 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture
new float[] {0, 0, 0, 0, 1F}}); new float[] {0, 0, 0, 0, 1F}});
ImageAttributes imageAttributes = new ImageAttributes(); ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(matrix); imageAttributes.SetColorMatrix(matrix);
joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb);
using (jG = Graphics.FromImage(joint))
{
jG.CompositingMode = CompositingMode.SourceOver;
jG.CompositingQuality = CompositingQuality.HighQuality;
jG.DrawImage(back, 0, 0, back.Width, back.Height); jG.CompositingMode = CompositingMode.SourceOver;
if(alpha > 0) jG.DrawImage(front, new Rectangle(0, 0, Width, Height), 0, 0, front.Width, front.Height, GraphicsUnit.Pixel, imageAttributes);
jG.DrawImage(front, new Rectangle(0, 0, back.Width, back.Height), 0, 0, front.Width, front.Height, GraphicsUnit.Pixel,imageAttributes); }
return joint; return joint;
} }
} }
private void SetAlpha(ref Bitmap b, byte alpha) private void SetAlpha(ref Bitmap b, byte alpha)
{ {
for (int w = 0; w < b.Width; w++) int Width = b.Width;
int Height = b.Height;
Bitmap joint = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
if(alpha > 0)
{ {
for (int h = 0; h < b.Height; h++) ColorMatrix matrix = new ColorMatrix(new float[][]{
new float[] {1F, 0, 0, 0, 0},
new float[] {0, 1F, 0, 0, 0},
new float[] {0, 0, 1F, 0, 0},
new float[] {0, 0, 0, alpha/255f, 0},
new float[] {0, 0, 0, 0, 1F}});
ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(matrix);
using (Graphics jG = Graphics.FromImage(joint))
{ {
b.SetPixel(w, h, Color.FromArgb(alpha, b.GetPixel(w, h))); jG.CompositingQuality = CompositingQuality.HighQuality;
jG.CompositingMode = CompositingMode.SourceCopy;
jG.DrawImage(b, new Rectangle(0, 0, Width, Height), 0, 0, Width, Height, GraphicsUnit.Pixel, imageAttributes);
} }
} }
Bitmap t = b;
b = joint;
t.Dispose();
} }
} }

View File

@ -354,6 +354,10 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
// under lock. // under lock.
lock (this) lock (this)
{ {
if (alpha == 256 && bgColor.A != 255)
alpha = bgColor.A;
if (alpha == 256) if (alpha == 256)
{ {
bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb); bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb);
@ -367,13 +371,15 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender
{ {
bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
graph = Graphics.FromImage(bitmap); graph = Graphics.FromImage(bitmap);
Color newbg = Color.FromArgb(alpha,bgColor); Color newbg = Color.FromArgb(alpha,bgColor);
using (SolidBrush bgFillBrush = new SolidBrush(newbg)) using (SolidBrush bgFillBrush = new SolidBrush(newbg))
{ {
graph.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
graph.FillRectangle(bgFillBrush, 0, 0, width, height); graph.FillRectangle(bgFillBrush, 0, 0, width, height);
} }
} }
graph.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
GDIDraw(data, graph, altDataDelim, out reuseable); GDIDraw(data, graph, altDataDelim, out reuseable);
} }