summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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)
);
}