Fix additive blending on semi-transparent backgrounds.
This commit is contained in:
parent
2d69d1dc99
commit
2aa37c2e40
@ -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(
|
||||
|
@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user