diff options
author | 2017-10-05 13:21:31 -0400 | |
---|---|---|
committer | 2017-10-05 18:16:44 +0000 | |
commit | a3b889514f4f7e83ece709f4ba11156ab1711cee (patch) | |
tree | 65ca1eeb7ae4c6ecd822f60a787d4a7942ff5bc9 /src/jumper/SkJumper_stages.cpp | |
parent | eccda1cecaa688848b0e99d03bd0e165f0a9404f (diff) |
clamp to [0,1] in all gradient tilers
Today gradient mirror and repeat don't explicitly clamp. They work fine for
normal float values, but blow up with inputs like infinity and NaN, and
those aren't hard to construct with a combination of a funky matrix and
some squaring for xy -> radius.
So explicitly clamp in each of the three matrix tilers.
This should fix the fuzz at the associated bug.
Bug: skia:7093
Change-Id: Idd44e3c7a1ed95e2b1ace8eb953b62eddeb4e00e
Reviewed-on: https://skia-review.googlesource.com/55702
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/jumper/SkJumper_stages.cpp')
-rw-r--r-- | src/jumper/SkJumper_stages.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/jumper/SkJumper_stages.cpp b/src/jumper/SkJumper_stages.cpp index f70a353283..12cbdee2ed 100644 --- a/src/jumper/SkJumper_stages.cpp +++ b/src/jumper/SkJumper_stages.cpp @@ -1073,10 +1073,13 @@ STAGE(repeat_y, const SkJumper_TileCtx* ctx) { g = exclusive_repeat(g, ctx); } STAGE(mirror_x, const SkJumper_TileCtx* ctx) { r = exclusive_mirror(r, ctx); } STAGE(mirror_y, const SkJumper_TileCtx* ctx) { g = exclusive_mirror(g, ctx); } -// Clamp x to [0,1], both sides exclusive (think, gradients). -STAGE( clamp_x_1, Ctx::None) { r = min(max(0, r), 1.0f); } -STAGE(repeat_x_1, Ctx::None) { r = r - floor_(r); } -STAGE(mirror_x_1, Ctx::None) { r = abs_( (r-1.0f) - two(floor_((r-1.0f)*0.5f)) - 1.0f ); } +// Clamp x to [0,1], both sides inclusive (think, gradients). +// Even repeat and mirror funnel through a clamp to handle bad inputs like +Inf, NaN. +SI F clamp_01(F v) { return min(max(0, v), 1); } + +STAGE( clamp_x_1, Ctx::None) { r = clamp_01(r); } +STAGE(repeat_x_1, Ctx::None) { r = clamp_01(r - floor_(r)); } +STAGE(mirror_x_1, Ctx::None) { r = clamp_01(abs_( (r-1.0f) - two(floor_((r-1.0f)*0.5f)) - 1.0f )); } STAGE(luminance_to_alpha, Ctx::None) { a = r*0.2126f + g*0.7152f + b*0.0722f; |