From aa34f7ea58330cb73ea17f01715cb6c7d439fae9 Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Wed, 9 Nov 2016 18:14:47 -0500 Subject: 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 Commit-Queue: Matt Sarett --- src/core/SkColorSpaceXform.cpp | 14 ++++++++++++-- 1 file 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); } } } -- cgit v1.2.3