diff options
author | Dominic Mazzoni <dmazzoni@chromium.org> | 2017-02-14 11:15:31 -0800 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-16 02:34:44 +0000 |
commit | 394d414452a5d654731b0b5a3669f8e2420048b3 (patch) | |
tree | 78dca199a9b3fb2abb5b62e0dcc537cb7c257348 /src/opts | |
parent | e1caee1ad884def91b8afb50e5672f1f0ee278f1 (diff) |
Implement SkHighContrastFilter
This is a color filter to apply several contrast adjustments for users
with low vision, including inverting the colors (in either RGB or HSL
space), applying gamma correction, converting to grayscale, and increasing
the contrast.
BUG=skia:6235
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD
Change-Id: Icb8f3e290932d8bcd9387fb1f39dd20767e15cf6
Reviewed-on: https://skia-review.googlesource.com/7460
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/opts')
-rw-r--r-- | src/opts/SkRasterPipeline_opts.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/opts/SkRasterPipeline_opts.h b/src/opts/SkRasterPipeline_opts.h index a81516877a..fb0271b822 100644 --- a/src/opts/SkRasterPipeline_opts.h +++ b/src/opts/SkRasterPipeline_opts.h @@ -776,6 +776,48 @@ STAGE(luminance_to_alpha) { r = g = b = 0; } +STAGE(rgb_to_hsl) { + auto max = SkNf::Max(SkNf::Max(r, g), b); + auto min = SkNf::Min(SkNf::Min(r, g), b); + auto l = 0.5f * (max + min); + + auto d = max - min; + auto d_inv = 1.0f/d; + auto s = (max == min).thenElse(0.0f, + d/(l > 0.5f).thenElse(2.0f - max - min, max + min)); + SkNf h = (max != r).thenElse(0.0f, + (g - b)*d_inv + (g < b).thenElse(6.0f, 0.0f)); + h = (max == g).thenElse((b - r)*d_inv + 2.0f, h); + h = (max == b).thenElse((r - g)*d_inv + 4.0f, h); + h *= (1/6.0f); + + h = (max == min).thenElse(0.0f, h); + + r = h; + g = s; + b = l; +} + +STAGE(hsl_to_rgb) { + auto h = r; + auto s = g; + auto l = b; + auto q = (l < 0.5f).thenElse(l*(1.0f + s), l + s - l*s); + auto p = 2.0f*l - q; + + auto hue_to_rgb = [](const SkNf& p, const SkNf& q, const SkNf& t) { + auto t2 = (t < 0.0f).thenElse(t + 1.0f, (t > 1.0f).thenElse(t - 1.0f, t)); + return (t2 < (1/6.0f)).thenElse( + p + (q - p)*6.0f*t, (t2 < (3/6.0f)).thenElse( + q, (t2 < (4/6.0f)).thenElse( + p + (q - p)*((4/6.0f) - t2)*6.0f, p))); + }; + + r = (s == 0.f).thenElse(l, hue_to_rgb(p, q, h + (1/3.0f))); + g = (s == 0.f).thenElse(l, hue_to_rgb(p, q, h)); + b = (s == 0.f).thenElse(l, hue_to_rgb(p, q, h - (1/3.0f))); +} + STAGE_CTX(matrix_2x3, const float*) { auto m = ctx; |