Bug 1359248 - Use an evenly distributed quantization for float RGBA values; r?heycam draft
authorManish Goregaokar <manishearth@gmail.com>
Mon, 24 Apr 2017 14:27:10 -0700
changeset 567367 b1cb8794b596bdb1a2ba9a4716b15b7695e7dfd9
parent 566710 9550eedc0bd80d404dab4e42660c629cc705c16c
child 625627 76374f3c1acbd2566add85e475b237e99ad07506
push id55551
push userbmo:manishearth@gmail.com
push dateMon, 24 Apr 2017 22:41:29 +0000
reviewersheycam
bugs1359248
milestone55.0a1
Bug 1359248 - Use an evenly distributed quantization for float RGBA values; r?heycam MozReview-Commit-ID: JN4px3cIyha
layout/style/nsCSSValue.cpp
--- 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),