avoid SetData when premultiplying texture with no semi-transparency
This commit is contained in:
parent
3c29ae6a1e
commit
6fc3be52bc
|
@ -252,16 +252,20 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
// premultiply pixels
|
// premultiply pixels
|
||||||
Color[] data = new Color[texture.Width * texture.Height];
|
Color[] data = new Color[texture.Width * texture.Height];
|
||||||
texture.GetData(data);
|
texture.GetData(data);
|
||||||
|
bool changed = false;
|
||||||
for (int i = 0; i < data.Length; i++)
|
for (int i = 0; i < data.Length; i++)
|
||||||
{
|
{
|
||||||
var pixel = data[i];
|
Color pixel = data[i];
|
||||||
if (pixel.A == byte.MinValue || pixel.A == byte.MaxValue)
|
if (pixel.A is (byte.MinValue or byte.MaxValue))
|
||||||
continue; // no need to change fully transparent/opaque pixels
|
continue; // no need to change fully transparent/opaque pixels
|
||||||
|
|
||||||
data[i] = new Color(pixel.R * pixel.A / byte.MaxValue, pixel.G * pixel.A / byte.MaxValue, pixel.B * pixel.A / byte.MaxValue, pixel.A); // slower version: Color.FromNonPremultiplied(data[i].ToVector4())
|
data[i] = new Color(pixel.R * pixel.A / byte.MaxValue, pixel.G * pixel.A / byte.MaxValue, pixel.B * pixel.A / byte.MaxValue, pixel.A); // slower version: Color.FromNonPremultiplied(data[i].ToVector4())
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changed)
|
||||||
texture.SetData(data);
|
texture.SetData(data);
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue