Index: third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp b/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp |
index 2b372e3a14b5360d917b299c6a71d3dd82605538..a921035f66c541ae0bac019a4f240d4421477baa 100644 |
--- a/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp |
@@ -28,6 +28,8 @@ |
#include "SkTableColorFilter.h" |
#include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
#include "platform/text/TextStream.h" |
+#include "wtf/MathExtras.h" |
+#include <algorithm> |
namespace blink { |
@@ -65,7 +67,7 @@ static void table(unsigned char* values, const ComponentTransferFunction& transf |
double v1 = tableValues[k]; |
double v2 = tableValues[std::min((k + 1), (n - 1))]; |
double val = 255.0 * (v1 + (c * (n - 1) - k) * (v2 - v1)); |
- val = std::max(0.0, std::min(255.0, val)); |
+ val = clampTo(val, 0.0, 255.0); |
values[i] = static_cast<unsigned char>(val); |
} |
} |
@@ -80,7 +82,7 @@ static void discrete(unsigned char* values, const ComponentTransferFunction& tra |
unsigned k = static_cast<unsigned>((i * n) / 255.0); |
k = std::min(k, n - 1); |
double val = 255 * tableValues[k]; |
- val = std::max(0.0, std::min(255.0, val)); |
+ val = clampTo(val, 0.0, 255.0); |
values[i] = static_cast<unsigned char>(val); |
} |
} |
@@ -89,7 +91,7 @@ static void linear(unsigned char* values, const ComponentTransferFunction& trans |
{ |
for (unsigned i = 0; i < 256; ++i) { |
double val = transferFunction.slope * i + 255 * transferFunction.intercept; |
- val = std::max(0.0, std::min(255.0, val)); |
+ val = clampTo(val, 0.0, 255.0); |
values[i] = static_cast<unsigned char>(val); |
} |
} |
@@ -99,7 +101,7 @@ static void gamma(unsigned char* values, const ComponentTransferFunction& transf |
for (unsigned i = 0; i < 256; ++i) { |
double exponent = transferFunction.exponent; // RCVT doesn't like passing a double and a float to pow, so promote this to double |
double val = 255.0 * (transferFunction.amplitude * pow((i / 255.0), exponent) + transferFunction.offset); |
- val = std::max(0.0, std::min(255.0, val)); |
+ val = clampTo(val, 0.0, 255.0); |
values[i] = static_cast<unsigned char>(val); |
} |
} |