fix indexing again, because apparently I'm bad at math now?

This commit is contained in:
atravita-mods 2022-08-23 14:34:23 -04:00 committed by Jesse Plamondon-Willard
parent a3b8546ec8
commit 496c438be2
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
1 changed files with 5 additions and 3 deletions

View File

@ -219,15 +219,17 @@ namespace StardewModdingAPI.Framework.Content
// merge pixels // merge pixels
for (int i = startIndex; i <= endIndex; i++) for (int i = startIndex; i <= endIndex; i++)
{ {
int targetIndex = i - sourceoffset;
// ref locals here? Not sure. // ref locals here? Not sure.
Color above = sourceData[i]; Color above = sourceData[i];
Color below = mergedData[i - sourceoffset]; Color below = mergedData[targetIndex];
// shortcut transparency // shortcut transparency
if (above.A < MinOpacity) if (above.A < MinOpacity)
continue; continue;
if (below.A < MinOpacity || above.A == byte.MaxValue) if (below.A < MinOpacity || above.A == byte.MaxValue)
mergedData[i] = above; mergedData[targetIndex] = above;
// merge pixels // merge pixels
else else
@ -236,7 +238,7 @@ namespace StardewModdingAPI.Framework.Content
// premultiplied by the content pipeline. The formula is derived from // premultiplied by the content pipeline. The formula is derived from
// https://blogs.msdn.microsoft.com/shawnhar/2009/11/06/premultiplied-alpha/. // https://blogs.msdn.microsoft.com/shawnhar/2009/11/06/premultiplied-alpha/.
float alphaBelow = 1 - (above.A / 255f); float alphaBelow = 1 - (above.A / 255f);
mergedData[i] = new Color( mergedData[targetIndex] = new Color(
r: (int)(above.R + (below.R * alphaBelow)), r: (int)(above.R + (below.R * alphaBelow)),
g: (int)(above.G + (below.G * alphaBelow)), g: (int)(above.G + (below.G * alphaBelow)),
b: (int)(above.B + (below.B * alphaBelow)), b: (int)(above.B + (below.B * alphaBelow)),