Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: third_party/WebKit/Source/platform/graphics/filters/FEComponentTransfer.cpp

Issue 1530723004: Use clampTo instead of chaining std::max(std::min(...)) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}
}

Powered by Google App Engine
This is Rietveld 408576698