summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-06-07 12:33:48 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-06-07 12:33:48 -0400
commit8036bcdf007ef4c3e8b39778a2a202ba0b22edec (patch)
tree980c4e9f592a79bf5d295d2cf8a7df9c5bcc8f35
parent868eefb9a7d30c194a4d3e2b95565cebdcf053be (diff)
downloadSMAPI-8036bcdf007ef4c3e8b39778a2a202ba0b22edec.tar.gz
SMAPI-8036bcdf007ef4c3e8b39778a2a202ba0b22edec.tar.bz2
SMAPI-8036bcdf007ef4c3e8b39778a2a202ba0b22edec.zip
improve premultiplication performance
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/ContentManagers/ModContentManager.cs5
2 files changed, 4 insertions, 2 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 55339d57..6c9a9649 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -7,6 +7,7 @@
* MacOS files starting with `._` are now ignored and can no longer cause skipped mods.
* Simplified paranoid warning logs and reduced their log level.
* Reduced startup time when loading mod DLLs (thanks to ZaneYork!).
+ * Reduced processing time when a mod loads many unpacked images (thanks to Entoarox!).
* Fixed `BadImageFormatException` error detection.
* Fixed black maps on Android for mods which use `.tmx` files.
diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
index fda80a83..cfda55b9 100644
--- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
@@ -246,10 +246,11 @@ namespace StardewModdingAPI.Framework.ContentManagers
texture.GetData(data);
for (int i = 0; i < data.Length; i++)
{
- if (data[i].A == byte.MinValue || data[i].A == byte.MaxValue)
+ var pixel = data[i];
+ if (pixel.A == byte.MinValue || pixel.A == byte.MaxValue)
continue; // no need to change fully transparent/opaque pixels
- data[i] = 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())
}
texture.SetData(data);