diff --git a/src/Magnum/Math/Color.h b/src/Magnum/Math/Color.h index 5bb30ab2e..c76181646 100644 --- a/src/Magnum/Math/Color.h +++ b/src/Magnum/Math/Color.h @@ -42,7 +42,7 @@ namespace Magnum { namespace Math { namespace Implementation { /* Convert color from HSV */ -template typename std::enable_if::value, Color3>::type fromHsv(ColorHsv hsv) { +template typename std::enable_if::value, Color3>::type fromHsv(ColorHsv hsv) { /* Remove repeats */ hsv.hue -= floor(T(hsv.hue)/T(360))*Deg(360); if(hsv.hue < Deg(0)) hsv.hue += Deg(360); @@ -64,7 +64,7 @@ template typename std::enable_if::value, Colo default: CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ } } -template inline typename std::enable_if::value, Color3>::type fromHsv(const ColorHsv::FloatingPointType>& hsv) { +template inline typename std::enable_if::value, Color3>::type fromHsv(const ColorHsv::FloatingPointType>& hsv) { return pack>(fromHsv::FloatingPointType>(hsv)); } @@ -86,90 +86,90 @@ template Deg hue(const Color3& color, T max, T delta) { } /* Hue, saturation, value for floating-point types */ -template inline Deg hue(typename std::enable_if::value, const Color3&>::type color) { +template inline Deg hue(typename std::enable_if::value, const Color3&>::type color) { T max = color.max(); T delta = max - color.min(); return hue(color, max, delta); } -template inline T saturation(typename std::enable_if::value, const Color3&>::type color) { +template inline T saturation(typename std::enable_if::value, const Color3&>::type color) { T max = color.max(); T delta = max - color.min(); return max != T(0) ? delta/max : T(0); } -template inline T value(typename std::enable_if::value, const Color3&>::type color) { +template inline T value(typename std::enable_if::value, const Color3&>::type color) { return color.max(); } /* Hue, saturation, value for integral types */ -template inline Deg::FloatingPointType> hue(typename std::enable_if::value, const Color3&>::type color) { +template inline Deg::FloatingPointType> hue(typename std::enable_if::value, const Color3&>::type color) { return hue::FloatingPointType>(unpack::FloatingPointType>>(color)); } -template inline typename Color3::FloatingPointType saturation(typename std::enable_if::value, const Color3&>::type& color) { +template inline typename Color3::FloatingPointType saturation(typename std::enable_if::value, const Color3&>::type& color) { return saturation::FloatingPointType>(unpack::FloatingPointType>>(color)); } -template inline typename Color3::FloatingPointType value(typename std::enable_if::value, const Color3&>::type color) { +template inline typename Color3::FloatingPointType value(typename std::enable_if::value, const Color3&>::type color) { return unpack::FloatingPointType>(color.max()); } /* Convert color to HSV */ -template inline ColorHsv toHsv(typename std::enable_if::value, const Color3&>::type color) { +template inline ColorHsv toHsv(typename std::enable_if::value, const Color3&>::type color) { T max = color.max(); T delta = max - color.min(); return ColorHsv{hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max}; } -template inline ColorHsv::FloatingPointType> toHsv(typename std::enable_if::value, const Color3&>::type color) { +template inline ColorHsv::FloatingPointType> toHsv(typename std::enable_if::value, const Color3&>::type color) { return toHsv::FloatingPointType>(unpack::FloatingPointType>>(color)); } /* sRGB -> RGB conversion */ -template typename std::enable_if::value, Color3>::type fromSrgb(const Vector3& srgb) { +template typename std::enable_if::value, Color3>::type fromSrgb(const Vector3& srgb) { constexpr const T a(T(0.055)); return lerp(srgb/T(12.92), pow((srgb + Vector3{a})/(T(1.0) + a), T(2.4)), srgb > Vector3(T(0.04045))); } -template typename std::enable_if::value, Color4>::type fromSrgbAlpha(const Vector4& srgbAlpha) { +template typename std::enable_if::value, Color4>::type fromSrgbAlpha(const Vector4& srgbAlpha) { return {fromSrgb(srgbAlpha.rgb()), srgbAlpha.a()}; } -template inline typename std::enable_if::value, Color3>::type fromSrgb(const Vector3::FloatingPointType>& srgb) { +template inline typename std::enable_if::value, Color3>::type fromSrgb(const Vector3::FloatingPointType>& srgb) { return pack>(fromSrgb::FloatingPointType>(srgb)); } -template inline typename std::enable_if::value, Color4>::type fromSrgbAlpha(const Vector4::FloatingPointType>& srgbAlpha) { +template inline typename std::enable_if::value, Color4>::type fromSrgbAlpha(const Vector4::FloatingPointType>& srgbAlpha) { return {fromSrgb(srgbAlpha.rgb()), pack(srgbAlpha.a())}; } template inline Color3 fromSrgbIntegral(const Vector3& srgb) { - static_assert(std::is_integral::value, "only conversion from different integral type is supported"); + static_assert(IsIntegral::value, "only conversion from different integral type is supported"); return fromSrgb(unpack::FloatingPointType>>(srgb)); } template inline Color4 fromSrgbAlphaIntegral(const Vector4& srgbAlpha) { - static_assert(std::is_integral::value, "only conversion from different integral type is supported"); + static_assert(IsIntegral::value, "only conversion from different integral type is supported"); return fromSrgbAlpha(unpack::FloatingPointType>>(srgbAlpha)); } /* RGB -> sRGB conversion */ -template Vector3::FloatingPointType> toSrgb(typename std::enable_if::value, const Color3&>::type rgb) { +template Vector3::FloatingPointType> toSrgb(typename std::enable_if::value, const Color3&>::type rgb) { constexpr const T a = T(0.055); return lerp(rgb*T(12.92), (T(1.0) + a)*pow(rgb, T(1.0)/T(2.4)) - Vector3{a}, rgb > Vector3(T(0.0031308))); } -template Vector4::FloatingPointType> toSrgbAlpha(typename std::enable_if::value, const Color4&>::type rgba) { +template Vector4::FloatingPointType> toSrgbAlpha(typename std::enable_if::value, const Color4&>::type rgba) { return {toSrgb(rgba.rgb()), rgba.a()}; } -template inline Vector3::FloatingPointType> toSrgb(typename std::enable_if::value, const Color3&>::type rgb) { +template inline Vector3::FloatingPointType> toSrgb(typename std::enable_if::value, const Color3&>::type rgb) { return toSrgb::FloatingPointType>(unpack::FloatingPointType>>(rgb)); } -template inline Vector4::FloatingPointType> toSrgbAlpha(typename std::enable_if::value, const Color4&>::type rgba) { +template inline Vector4::FloatingPointType> toSrgbAlpha(typename std::enable_if::value, const Color4&>::type rgba) { return {toSrgb(rgba.rgb()), unpack::FloatingPointType>(rgba.a())}; } template inline Vector3 toSrgbIntegral(const Color3& rgb) { - static_assert(std::is_integral::value, "only conversion from different integral type is supported"); + static_assert(IsIntegral::value, "only conversion from different integral type is supported"); return pack>(toSrgb(rgb)); } template inline Vector4 toSrgbAlphaIntegral(const Color4& rgba) { - static_assert(std::is_integral::value, "only conversion from different integral type is supported"); + static_assert(IsIntegral::value, "only conversion from different integral type is supported"); return pack>(toSrgbAlpha(rgba)); } /* CIE XYZ -> RGB conversion */ -template typename std::enable_if::value, Color3>::type fromXyz(const Vector3& xyz) { +template typename std::enable_if::value, Color3>::type fromXyz(const Vector3& xyz) { /* Taken from https://en.wikipedia.org/wiki/Talk:SRGB#Rounded_vs._Exact, the rounded matrices from the main article don't round-trip perfectly */ return Matrix3x3{ @@ -177,12 +177,12 @@ template typename std::enable_if::value, Colo Vector3{T(-329)/T(214), T(1648619)/T(878810), T(-2585)/T(12673)}, Vector3{T(-1974)/T(3959), T(36519)/T(878810), T(705)/T(667)}}*xyz; } -template inline typename std::enable_if::value, Color3>::type fromXyz(const Vector3::FloatingPointType>& xyz) { +template inline typename std::enable_if::value, Color3>::type fromXyz(const Vector3::FloatingPointType>& xyz) { return pack>(fromXyz::FloatingPointType>(xyz)); } /* RGB -> CIE XYZ conversion */ -template Vector3::FloatingPointType> toXyz(typename std::enable_if::value, const Color3&>::type rgb) { +template Vector3::FloatingPointType> toXyz(typename std::enable_if::value, const Color3&>::type rgb) { /* Taken from https://en.wikipedia.org/wiki/Talk:SRGB#Rounded_vs._Exact, the rounded matrices from the main article don't round-trip perfectly */ return (Matrix3x3{ @@ -190,7 +190,7 @@ template Vector3::FloatingPointType> toXyz(typename Vector3{T(87881)/T(245763), T(175762)/T(245763), T(87881)/T(737289)}, Vector3{T(12673)/T(70218), T(12673)/T(175545), T(1001167)/T(1053270)}})*rgb; } -template inline Vector3::FloatingPointType> toXyz(typename std::enable_if::value, const Color3&>::type rgb) { +template inline Vector3::FloatingPointType> toXyz(typename std::enable_if::value, const Color3&>::type rgb) { return toXyz::FloatingPointType>(unpack::FloatingPointType>>(rgb)); } @@ -202,10 +202,10 @@ template inline Vector3::FloatingPointType> toXyz(ty projects created directly using VS (enabled by default since 15.5) but not projects using CMake. Not using SFINAE in this case makes it work. Minimal repro case here: https://twitter.com/czmosra/status/1039446378248896513 */ -template constexpr typename std::enable_if::value, T>::type fullChannel() { +template constexpr typename std::enable_if::value, T>::type fullChannel() { return T(1); } -template constexpr typename std::enable_if::value, T>::type fullChannel() { +template constexpr typename std::enable_if::value, T>::type fullChannel() { return Implementation::bitMax(); } #else