aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2016-11-09 18:14:47 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-10 13:22:50 +0000
commitaa34f7ea58330cb73ea17f01715cb6c7d439fae9 (patch)
tree9e49c0db3c168a432ffd6d1314c7b250245e8b27
parent2087dda1631594819f7290b79392d2e73d7e2742 (diff)
Clamp parametric gamma values to 0-1 range
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4641 Change-Id: I1c6963da956500deea559d5ece31529add89980a Reviewed-on: https://skia-review.googlesource.com/4641 Reviewed-by: Robert Aftias <raftias@google.com> Commit-Queue: Matt Sarett <msarett@google.com>
-rw-r--r--src/core/SkColorSpaceXform.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp
index c92c37f75b..9de8bf7439 100644
--- a/src/core/SkColorSpaceXform.cpp
+++ b/src/core/SkColorSpaceXform.cpp
@@ -111,15 +111,25 @@ static void build_table_linear_from_gamma(float* outTable, const float* inTable,
}
}
+static inline float clamp_0_1(float v) {
+ if (v >= 1.0f) {
+ return 1.0f;
+ } else if (v >= 0.0f) {
+ return v;
+ } else {
+ return 0.0f;
+ }
+}
+
static void build_table_linear_from_gamma(float* outTable, float g, float a, float b, float c,
float d, float e, float f) {
// Y = (aX + b)^g + c for X >= d
// Y = eX + f otherwise
for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) {
if (x >= d) {
- *outTable++ = powf(a * x + b, g) + c;
+ *outTable++ = clamp_0_1(powf(a * x + b, g) + c);
} else {
- *outTable++ = e * x + f;
+ *outTable++ = clamp_0_1(e * x + f);
}
}
}