summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-09-25 01:00:47 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-09-25 01:00:47 -0400
commit43e935b01761b657ed361d3ae67c7ca001cde623 (patch)
tree08b7a22ab02de2c02fb42281cd9536f3b7dca7d3 /src
parentb9844c4acd93411c2a7d21bd115cb4fee1791d76 (diff)
downloadSMAPI-43e935b01761b657ed361d3ae67c7ca001cde623.tar.gz
SMAPI-43e935b01761b657ed361d3ae67c7ca001cde623.tar.bz2
SMAPI-43e935b01761b657ed361d3ae67c7ca001cde623.zip
simplify alpha blending
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Framework/Content/AssetDataForImage.cs12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/SMAPI/Framework/Content/AssetDataForImage.cs b/src/SMAPI/Framework/Content/AssetDataForImage.cs
index cd372948..a8ec79a8 100644
--- a/src/SMAPI/Framework/Content/AssetDataForImage.cs
+++ b/src/SMAPI/Framework/Content/AssetDataForImage.cs
@@ -84,13 +84,13 @@ namespace StardewModdingAPI.Framework.Content
// merge pixels
// This performs a conventional alpha blend for the pixels, which are already
- // premultiplied by the content pipeline.
- float alphaAbove = above.A / 255f;
- float alphaBelow = (255 - above.A) / 255f;
+ // premultiplied by the content pipeline. The formula is derived from
+ // https://blogs.msdn.microsoft.com/shawnhar/2009/11/06/premultiplied-alpha/.
+ float alphaBelow = 1 - (above.A / 255f);
newData[i] = new Color(
- r: (int)((above.R * alphaAbove) + (below.R * alphaBelow)),
- g: (int)((above.G * alphaAbove) + (below.G * alphaBelow)),
- b: (int)((above.B * alphaAbove) + (below.B * alphaBelow)),
+ r: (int)(above.R + (below.R * alphaBelow)),
+ g: (int)(above.G + (below.G * alphaBelow)),
+ b: (int)(above.B + (below.B * alphaBelow)),
a: Math.Max(above.A, below.A)
);
}