Bug 1359248 - Use an evenly distributed quantization for float RGBA values; r?heycam
MozReview-Commit-ID: JN4px3cIyha
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -3181,20 +3181,20 @@ nsCSSValueFloatColor::GetColorValue(nsCS
MOZ_ASSERT(nsCSSValue::IsFloatColorUnit(aUnit), "unexpected unit");
// We should clamp each component value since eCSSUnit_PercentageRGBColor
// and eCSSUnit_PercentageRGBAColor may store values greater than 1.0.
if (aUnit == eCSSUnit_PercentageRGBColor ||
aUnit == eCSSUnit_PercentageRGBAColor) {
return NS_RGBA(
// We need to clamp before multiplying by 255.0f to avoid overflow.
- NSToIntRound(mozilla::clamped(mComponent1, 0.0f, 1.0f) * 255.0f),
- NSToIntRound(mozilla::clamped(mComponent2, 0.0f, 1.0f) * 255.0f),
- NSToIntRound(mozilla::clamped(mComponent3, 0.0f, 1.0f) * 255.0f),
- NSToIntRound(mozilla::clamped(mAlpha, 0.0f, 1.0f) * 255.0f));
+ mozilla::clamped(NSToIntFloor(mComponent1 * 256.0f), 0, 255),
+ mozilla::clamped(NSToIntFloor(mComponent2 * 256.0f), 0, 255),
+ mozilla::clamped(NSToIntFloor(mComponent3 * 256.0f), 0, 255),
+ mozilla::clamped(NSToIntFloor(mAlpha * 256.0f), 0, 255));
}
// HSL color
MOZ_ASSERT(aUnit == eCSSUnit_HSLColor ||
aUnit == eCSSUnit_HSLAColor);
nscolor hsl = NS_HSL2RGB(mComponent1, mComponent2, mComponent3);
return NS_RGBA(NS_GET_R(hsl),
NS_GET_G(hsl),