diff options
author | JP Cimalando <jpcima@users.noreply.github.com> | 2018-12-26 18:25:16 +0100 |
---|---|---|
committer | Filipe Coelho <falktx@falktx.com> | 2019-01-06 19:10:11 +0100 |
commit | 08c21e563b2f68078655099f47091306d1f135ba (patch) | |
tree | a366af0e9099a0e915d78b9c4e0ee6fc3ab93177 /dgl/src | |
parent | e697fa716e6b734eaaa8b02c5f2e961a4ef03fb7 (diff) |
support C++98 in Color::fromHSL
Diffstat (limited to 'dgl/src')
-rw-r--r-- | dgl/src/Color.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/dgl/src/Color.cpp b/dgl/src/Color.cpp index 4965c902..c725ee06 100644 --- a/dgl/src/Color.cpp +++ b/dgl/src/Color.cpp @@ -105,6 +105,21 @@ Color::Color(const Color& color1, const Color& color2, float u) noexcept interpolate(color2, u); } +#if !defined(HAVE_DGL) +static float computeHue(float h, float m1, float m2) +{ + if (h < 0) h += 1; + if (h > 1) h -= 1; + if (h < 1.0f/6.0f) + return m1 + (m2 - m1) * h * 6.0f; + else if (h < 3.0f/6.0f) + return m2; + else if (h < 4.0f/6.0f) + return m1 + (m2 - m1) * (2.0f/3.0f - h) * 6.0f; + return m1; +} +#endif + Color Color::fromHSL(float hue, float saturation, float lightness, float alpha) { #if defined(HAVE_DGL) @@ -118,21 +133,9 @@ Color Color::fromHSL(float hue, float saturation, float lightness, float alpha) fixRange(lightness); m2 = lightness <= 0.5f ? (lightness * (1 + saturation)) : (lightness + saturation - lightness * saturation); m1 = 2 * lightness - m2; - auto hue_ = [](float h, float m1, float m2) -> float - { - if (h < 0) h += 1; - if (h > 1) h -= 1; - if (h < 1.0f/6.0f) - return m1 + (m2 - m1) * h * 6.0f; - else if (h < 3.0f/6.0f) - return m2; - else if (h < 4.0f/6.0f) - return m1 + (m2 - m1) * (2.0f/3.0f - h) * 6.0f; - return m1; - }; - col.red = hue_(hue + 1.0f/3.0f, m1, m2); - col.green = hue_(hue, m1, m2); - col.blue = hue_(hue - 1.0f/3.0f, m1, m2); + col.red = computeHue(hue + 1.0f/3.0f, m1, m2); + col.green = computeHue(hue, m1, m2); + col.blue = computeHue(hue - 1.0f/3.0f, m1, m2); col.alpha = alpha; col.fixBounds(); return col; |