summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentManagers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-02-22 17:38:59 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-02-22 17:38:59 -0500
commit6fc3be52bc2faaa85bea2febe6953fb5b51dac3a (patch)
treeff1cc0745030691c9d4c4e1d8a88e912722c7d29 /src/SMAPI/Framework/ContentManagers
parent3c29ae6a1e77ba098b4d9421cacb0fc37510227c (diff)
downloadSMAPI-6fc3be52bc2faaa85bea2febe6953fb5b51dac3a.tar.gz
SMAPI-6fc3be52bc2faaa85bea2febe6953fb5b51dac3a.tar.bz2
SMAPI-6fc3be52bc2faaa85bea2febe6953fb5b51dac3a.zip
avoid SetData when premultiplying texture with no semi-transparency
Diffstat (limited to 'src/SMAPI/Framework/ContentManagers')
-rw-r--r--src/SMAPI/Framework/ContentManagers/ModContentManager.cs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
index 21f88d47..50ea6e61 100644
--- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
@@ -252,16 +252,20 @@ namespace StardewModdingAPI.Framework.ContentManagers
// premultiply pixels
Color[] data = new Color[texture.Width * texture.Height];
texture.GetData(data);
+ bool changed = false;
for (int i = 0; i < data.Length; i++)
{
- var pixel = data[i];
- if (pixel.A == byte.MinValue || pixel.A == byte.MaxValue)
+ Color pixel = data[i];
+ if (pixel.A is (byte.MinValue or byte.MaxValue))
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())
+ changed = true;
}
- texture.SetData(data);
+ if (changed)
+ texture.SetData(data);
+
return texture;
}