From 394d414452a5d654731b0b5a3669f8e2420048b3 Mon Sep 17 00:00:00 2001 From: Dominic Mazzoni Date: Tue, 14 Feb 2017 11:15:31 -0800 Subject: 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 Reviewed-by: Mike Reed Reviewed-by: Mike Klein --- src/opts/SkRasterPipeline_opts.h | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/opts') 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; -- cgit v1.2.3