mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-04 07:40:42 +00:00
Bug 1294614 - Part 3: Add DiluteColor(). r=dholbert.
MozReview-Commit-ID: AKfVLgeN9ZO --HG-- extra : rebase_source : a0558b6e25d955956d54acac1d51387a1de76db5
This commit is contained in:
parent
aeeaf198d9
commit
c8b48f39ce
@ -1196,6 +1196,32 @@ AddWeightedColors(double aCoeff1, nscolor aColor1,
|
||||
return NS_RGBA(Rres, Gres, Bres, Ares);
|
||||
}
|
||||
|
||||
// Multiplies |aColor| by |aDilutionRatio| with premultiplication.
|
||||
// (The logic here should pretty closely match AddWeightedColors()' logic.)
|
||||
static nscolor
|
||||
DiluteColor(nscolor aColor, double aDilutionRatio)
|
||||
{
|
||||
MOZ_ASSERT(aDilutionRatio >= 0.0 && aDilutionRatio <= 1.0,
|
||||
"Dilution ratio should be in [0, 1]");
|
||||
|
||||
double A = NS_GET_A(aColor) * (1.0 / 255.0);
|
||||
double Aresf = A * aDilutionRatio;
|
||||
if (Aresf <= 0.0) {
|
||||
return NS_RGBA(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Premultiplication
|
||||
double R = NS_GET_R(aColor) * A;
|
||||
double G = NS_GET_G(aColor) * A;
|
||||
double B = NS_GET_B(aColor) * A;
|
||||
|
||||
double factor = 1.0 / Aresf;
|
||||
return NS_RGBA(ClampColor(R * aDilutionRatio * factor),
|
||||
ClampColor(G * aDilutionRatio * factor),
|
||||
ClampColor(B * aDilutionRatio * factor),
|
||||
NSToIntRound(Aresf * 255.0));
|
||||
}
|
||||
|
||||
static bool
|
||||
AddShadowItems(double aCoeff1, const nsCSSValue &aValue1,
|
||||
double aCoeff2, const nsCSSValue &aValue2,
|
||||
@ -2384,8 +2410,18 @@ StyleAnimationValue::AddWeighted(nsCSSPropertyID aProperty,
|
||||
case eUnit_Color: {
|
||||
nscolor color1 = aValue1.GetColorValue();
|
||||
nscolor color2 = aValue2.GetColorValue();
|
||||
nscolor resultColor =
|
||||
AddWeightedColors(aCoeff1, color1, aCoeff2, color2);
|
||||
nscolor resultColor;
|
||||
|
||||
// We are using AddWeighted() with a zero aCoeff2 for colors to
|
||||
// pretend AddWeighted() against transparent color, i.e. rgba(0, 0, 0, 0).
|
||||
// But unpremultiplication in AddWeightedColors() does not work well
|
||||
// for such cases, so we use another function named DiluteColor() which
|
||||
// has a similar logic to AddWeightedColors().
|
||||
if (aCoeff2 == 0.0) {
|
||||
resultColor = DiluteColor(color1, aCoeff1);
|
||||
} else {
|
||||
resultColor = AddWeightedColors(aCoeff1, color1, aCoeff2, color2);
|
||||
}
|
||||
aResultValue.SetColorValue(resultColor);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user