aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/jumper/SkJumper_stages.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-04-12 08:35:41 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-12 15:31:03 +0000
commitdb1cbcb4b5e5da04571e3f8c0008b6675fb93cb3 (patch)
tree193e7ff4d61e40d4422e357134df535676ab07a7 /src/jumper/SkJumper_stages.cpp
parente132e7be5f9108692254c37db592ea7611abbc15 (diff)
jumper, rgb<->hsl
I've rearranged while porting, I hope making the logic clearer. Exactly one gm is affected, highcontrastfilter. The most interesting line is this, from hsl_to_rgb: F t2 = if_then_else(t < 0.0_f, t + 1.0_f, I had to write 0.0_f (instead of the usual 0) to force Clang to compare against a zero register instead of a 16-byte zero constant in memory. Register pressure is high in hsl_to_rgb, so something must have kicked in to prefer memory over zeroing a register. No big deal. It makes the code read more symmetrically anyway. Change-Id: I1a5ced72216234587760c6f803fb69315d18fae0 Reviewed-on: https://skia-review.googlesource.com/13242 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Herb Derby <herb@google.com>
Diffstat (limited to 'src/jumper/SkJumper_stages.cpp')
-rw-r--r--src/jumper/SkJumper_stages.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/jumper/SkJumper_stages.cpp b/src/jumper/SkJumper_stages.cpp
index a97a7ed13f..a4f3242ecd 100644
--- a/src/jumper/SkJumper_stages.cpp
+++ b/src/jumper/SkJumper_stages.cpp
@@ -512,6 +512,50 @@ STAGE(to_2dot2) {
b = fn(b);
}
+STAGE(rgb_to_hsl) {
+ F mx = max(max(r,g), b),
+ mn = min(min(r,g), b),
+ d = mx - mn,
+ d_rcp = 1.0_f / d;
+
+ F h = C(1/6.0f) *
+ if_then_else(mx == mn, 0,
+ if_then_else(mx == r, (g-b)*d_rcp + if_then_else(g < b, 6.0_f, 0),
+ if_then_else(mx == g, (b-r)*d_rcp + 2.0_f,
+ (r-g)*d_rcp + 4.0_f)));
+
+ F l = (mx + mn) * 0.5_f;
+ F s = if_then_else(mx == mn, 0,
+ d / if_then_else(l > 0.5_f, 2.0_f-mx-mn, mx+mn));
+
+ r = h;
+ g = s;
+ b = l;
+}
+STAGE(hsl_to_rgb) {
+ F h = r,
+ s = g,
+ l = b;
+
+ F q = if_then_else(l < 0.5_f, l*(1.0_f + s), l + s - l*s),
+ p = 2.0_f*l - q;
+
+ auto hue_to_rgb = [&](F t) {
+ F t2 = if_then_else(t < 0.0_f, t + 1.0_f,
+ if_then_else(t > 1.0_f, t - 1.0_f,
+ t));
+
+ return if_then_else(t2 < C(1/6.0f), p + (q-p)*6.0_f*t,
+ if_then_else(t2 < C(3/6.0f), q,
+ if_then_else(t2 < C(4/6.0f), p + (q-p)*6.0_f*(C(4/6.0f) - t2),
+ p)));
+ };
+
+ r = if_then_else(s == 0, l, hue_to_rgb(h + C(1/3.0f)));
+ g = if_then_else(s == 0, l, hue_to_rgb(h ));
+ b = if_then_else(s == 0, l, hue_to_rgb(h - C(1/3.0f)));
+}
+
STAGE(scale_1_float) {
auto c = *(const float*)ctx;