1
0
mirror of synced 2025-01-31 12:13:49 +01:00

Fix additive blending on semi-transparent backgrounds.

This commit is contained in:
Jennifer Taylor 2021-05-22 23:24:51 +00:00
parent 2d69d1dc99
commit 2aa37c2e40
2 changed files with 12 additions and 12 deletions

View File

@ -35,12 +35,12 @@ except ImportError:
# Calculate alpha blending.
srcpercent = src[3] / 255.0
destpercent = dest[3] / 255.0
srcremaineder = 1.0 - srcpercent
new_alpha = (srcpercent + destpercent * srcremaineder)
srcremainder = 1.0 - srcpercent
new_alpha = max(min(0.0, srcpercent + destpercent * srcremainder), 1.0)
return (
clamp(((dest[0] * destpercent * srcremaineder) + (src[0] * srcpercent)) / new_alpha),
clamp(((dest[1] * destpercent * srcremaineder) + (src[1] * srcpercent)) / new_alpha),
clamp(((dest[2] * destpercent * srcremaineder) + (src[2] * srcpercent)) / new_alpha),
clamp(((dest[0] * destpercent * srcremainder) + (src[0] * srcpercent)) / new_alpha),
clamp(((dest[1] * destpercent * srcremainder) + (src[1] * srcpercent)) / new_alpha),
clamp(((dest[2] * destpercent * srcremainder) + (src[2] * srcpercent)) / new_alpha),
clamp(255 * new_alpha)
)
@ -64,7 +64,7 @@ except ImportError:
clamp(dest[0] + (src[0] * srcpercent)),
clamp(dest[1] + (src[1] * srcpercent)),
clamp(dest[2] + (src[2] * srcpercent)),
dest[3],
clamp(dest[3] + (255 * srcpercent)),
)
def blend_subtraction(

View File

@ -92,12 +92,12 @@ extern "C"
// Calculate alpha blending.
float srcpercent = src.a / 255.0;
float destpercent = dest.a / 255.0;
float srcremaineder = 1.0 - srcpercent;
float new_alpha = (srcpercent + destpercent * srcremaineder);
float srcremainder = 1.0 - srcpercent;
float new_alpha = fmin(fmax(0.0, srcpercent + destpercent * srcremainder), 1.0);
return (intcolor_t){
clamp(((dest.r * destpercent * srcremaineder) + (src.r * srcpercent)) / new_alpha),
clamp(((dest.g * destpercent * srcremaineder) + (src.g * srcpercent)) / new_alpha),
clamp(((dest.b * destpercent * srcremaineder) + (src.b * srcpercent)) / new_alpha),
clamp(((dest.r * destpercent * srcremainder) + (src.r * srcpercent)) / new_alpha),
clamp(((dest.g * destpercent * srcremainder) + (src.g * srcpercent)) / new_alpha),
clamp(((dest.b * destpercent * srcremainder) + (src.b * srcpercent)) / new_alpha),
clamp(255 * new_alpha)
};
}
@ -121,7 +121,7 @@ extern "C"
clamp(dest.r + (src.r * srcpercent)),
clamp(dest.g + (src.g * srcpercent)),
clamp(dest.b + (src.b * srcpercent)),
dest.a,
clamp(dest.a + (255 * srcpercent)),
};
}