From b13d8644b4fd5861403f9d56a762889b80a6515f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 17 Jan 2013 00:58:28 +0100 Subject: [PATCH] Replaced scalar normalization code in Color with Math::[de]normalize(). --- src/Color.h | 55 +++--------------------------------------- src/Test/ColorTest.cpp | 14 ----------- 2 files changed, 4 insertions(+), 65 deletions(-) diff --git a/src/Color.h b/src/Color.h index 5a230794a..27e651984 100644 --- a/src/Color.h +++ b/src/Color.h @@ -58,7 +58,7 @@ template inline typename std::enable_if::valu } } template inline typename std::enable_if::value, Color3>::type fromHSV(typename Color3::HSV hsv) { - return Color3::fromNormalized(fromHSV::FloatingPointType>(hsv)); + return Math::denormalize>(fromHSV::FloatingPointType>(hsv)); } /* Internal hue computing function */ @@ -95,10 +95,10 @@ template inline T value(typename std::enable_if inline typename Color3::FloatingPointType hue(typename std::enable_if::value, const Color3&>::type color) { - return hue::FloatingPointType>(Color3::FloatingPointType>::fromDenormalized(color)); + return hue::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } template inline typename Color3::FloatingPointType saturation(typename std::enable_if::value, const Color3&>::type& color) { - return saturation::FloatingPointType>(Color3::FloatingPointType>::fromDenormalized(color)); + return saturation::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } template inline typename Color3::FloatingPointType value(typename std::enable_if::value, const Color3&>::type color) { return Math::normalize::FloatingPointType>(color.max()); @@ -112,7 +112,7 @@ template inline typename Color3::HSV toHSV(typename std::enable_if::HSV(hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); } template inline typename Color3::HSV toHSV(typename std::enable_if::value, const Color3&>::type color) { - return toHSV::FloatingPointType>(Color3::FloatingPointType>::fromDenormalized(color)); + return toHSV::FloatingPointType>(Math::normalize::FloatingPointType>>(color)); } /* Default alpha value */ @@ -140,7 +140,6 @@ range @f$ [0.0, 1.0] @f$. @see Color4 @todo Hue in degrees so users can use deg() -@todo Signed normalization to [-1.0, 1.0] like in OpenGL? */ /* Not using template specialization because some internal functions are impossible to explicitly instantiate */ @@ -162,36 +161,6 @@ class Color3: public Math::Vector3 { */ typedef std::tuple HSV; - /** - * @brief Create integral color from floating-point color - * - * E.g. `{0.294118, 0.45098, 0.878431}` is converted to - * `{75, 115, 224}`, if resulting type is `std::uint8_t`. - * - * @note This function is enabled only if source type is floating-point - * and destination type is integral. - */ - template inline constexpr static typename std::enable_if::value && std::is_floating_point::value, Color3>::type fromNormalized(const Color3& color) { - return Color3(Math::denormalize(color.r()), - Math::denormalize(color.g()), - Math::denormalize(color.b())); - } - - /** - * @brief Create floating-point color from integral color - * - * E.g. `{75, 115, 224}` is converted to - * `{0.294118, 0.45098, 0.878431}`, if source type is `std::uint8_t`. - * - * @note This function is enabled only if source type is integral - * and destination type is floating-point. - */ - template inline constexpr static typename std::enable_if::value && std::is_integral::value, Color3>::type fromDenormalized(const Color3& color) { - return Color3(Math::normalize(color.r()), - Math::normalize(color.g()), - Math::normalize(color.b())); - } - /** * @brief Create RGB color from HSV representation * @param hsv Hue, saturation and value @@ -308,22 +277,6 @@ class Color4: public Math::Vector4 { /** @copydoc Color3::HSV */ typedef typename Color3::HSV HSV; - /** @copydoc Color3::fromNormalized() */ - template inline constexpr static typename std::enable_if::value && std::is_floating_point::value, Color4>::type fromNormalized(const Color4& color) { - return Color4(Math::denormalize(color.r()), - Math::denormalize(color.g()), - Math::denormalize(color.b()), - Math::denormalize(color.a())); - } - - /** @copydoc Color3::fromDenormalized() */ - template inline constexpr static typename std::enable_if::value && std::is_integral::value, Color4>::type fromDenormalized(const Color4& color) { - return Color4(Math::normalize(color.r()), - Math::normalize(color.g()), - Math::normalize(color.b()), - Math::normalize(color.a())); - } - /** * @copydoc Color3::fromHSV() * @param a Alpha value, defaults to 1.0 for floating-point types diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index fd6aca832..959bc7144 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -29,9 +29,6 @@ class ColorTest: public Corrade::TestSuite::Tester { void access(); - void fromDenormalized(); - void fromNormalized(); - void fromHue(); void fromSaturation(); void fromValue(); @@ -56,9 +53,6 @@ typedef Magnum::Color4 Color4f; ColorTest::ColorTest() { addTests(&ColorTest::access, - &ColorTest::fromDenormalized, - &ColorTest::fromNormalized, - &ColorTest::fromHue, &ColorTest::fromSaturation, &ColorTest::fromValue, @@ -99,14 +93,6 @@ void ColorTest::access() { CORRADE_COMPARE(cc4.a(), 22); } -void ColorTest::fromDenormalized() { - CORRADE_COMPARE(Color3f::fromDenormalized(Color3(75, 115, 224)), Color3f(0.294118, 0.45098, 0.878431)); -} - -void ColorTest::fromNormalized() { - CORRADE_COMPARE(Color3::fromNormalized(Color3f(0.294118, 0.45098, 0.878431)), Color3(75, 114, 223)); -} - void ColorTest::fromHue() { CORRADE_COMPARE(Color3::fromHSV(27.0f, 1.0f, 1.0f), Color3(255, 114, 0)); CORRADE_COMPARE(Color3::fromHSV(86.0f, 1.0f, 1.0f), Color3(144, 255, 0));