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>
This commit is contained in:
Mike Klein 2017-04-12 08:35:41 -04:00 committed by Skia Commit-Bot
parent e132e7be5f
commit db1cbcb4b5
4 changed files with 2468 additions and 437 deletions

View File

@ -80,6 +80,8 @@ static K kConstants = {
M(to_srgb) \
M(from_2dot2) \
M(to_2dot2) \
M(rgb_to_hsl) \
M(hsl_to_rgb) \
M(scale_1_float) \
M(scale_u8) \
M(lerp_1_float) \

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -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;