Title: [275206] trunk/Source/WebCore
Revision
275206
Author
wei...@apple.com
Date
2021-03-30 09:31:21 -0700 (Tue, 30 Mar 2021)

Log Message

Generalize ColorComponents to support an arbritrary number of components (though really we will only ever want 3, 4, or 5)
https://bugs.webkit.org/show_bug.cgi?id=223901

Reviewed by Darin Adler.

Add a length to ColorComponents to allow an arbitrary number of components. This
will be used to support cases where we only want to carry the three color components
(not alpha) and will be useful if we ever need to add back CMYKA support.

A new dedecution guide added allows for cases that currently deduce to remain.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::makeColorTypeByNormalizingComponentsAfterMix):
(WebCore::CSSPropertyParserHelpers::makeColorTypeByNormalizingComponentsAfterMix<HWBA<float>>):
(WebCore::CSSPropertyParserHelpers::makeColorTypeByNormalizingComponentsAfterMix<HSLA<float>>):
(WebCore::CSSPropertyParserHelpers::fixupHueComponentsPriorToMix):
* platform/graphics/Color.cpp:
(WebCore::Color::colorSpaceAndComponents const):
* platform/graphics/Color.h:
(WebCore::Color::OutOfLineComponents::create):
(WebCore::Color::OutOfLineComponents::components const):
(WebCore::Color::OutOfLineComponents::OutOfLineComponents):
* platform/graphics/ColorComponents.h:
(WebCore::ColorComponents::ColorComponents):
(WebCore::mapColorComponents):
(WebCore::N>::map const):
(WebCore::=):
(WebCore::N>::operator const):
(WebCore::N>::abs const):
(WebCore::N>::get const):
(WebCore::N>::subset const):
(WebCore::perComponentMax):
(WebCore::perComponentMin):
(WebCore::operator==):
(WebCore::operator!=):
(WebCore::ColorComponents<T>::map const): Deleted.
(WebCore::ColorComponents<T>::operator const): Deleted.
(WebCore::ColorComponents<T>::abs const): Deleted.
(WebCore::ColorComponents<T>::get const): Deleted.
* platform/graphics/ColorMatrix.h:
(WebCore::RowCount>::transformedColorComponents const):
(WebCore::applyMatricesToColorComponents):
* platform/graphics/ColorSpace.h:
(WebCore::callWithColorType):
* platform/graphics/ColorTypes.h:
(WebCore::makeFromComponents):
(WebCore::clampedComponent):
(WebCore::clampedComponents):
(WebCore::clampedComponentsExceptAlpha):
(WebCore::makeFromComponentsClamping):
(WebCore::makeFromComponentsClampingExceptAlpha):
(WebCore::asColorComponents):
* platform/graphics/filters/FEColorMatrix.cpp:
* platform/graphics/filters/FEMorphology.cpp:
(WebCore::makeColorComponentsfromPixelValue):
(WebCore::makePixelValueFromColorComponents):
(WebCore::minOrMax):
(WebCore::columnExtremum):
(WebCore::kernelExtremum):
(WebCore::FEMorphology::platformApplyGeneric):
* platform/graphics/filters/FETurbulence.cpp:
(WebCore::FETurbulence::noise2D const):
(WebCore::toIntBasedColorComponents):
(WebCore::FETurbulence::calculateTurbulenceValueForPoint const):
* platform/graphics/filters/FETurbulence.h:
* platform/graphics/filters/FilterOperation.cpp:
(WebCore::hueRotate):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275205 => 275206)


--- trunk/Source/WebCore/ChangeLog	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/ChangeLog	2021-03-30 16:31:21 UTC (rev 275206)
@@ -1,3 +1,73 @@
+2021-03-30  Sam Weinig  <wei...@apple.com>
+
+        Generalize ColorComponents to support an arbritrary number of components (though really we will only ever want 3, 4, or 5)
+        https://bugs.webkit.org/show_bug.cgi?id=223901
+
+        Reviewed by Darin Adler.
+
+        Add a length to ColorComponents to allow an arbitrary number of components. This
+        will be used to support cases where we only want to carry the three color components
+        (not alpha) and will be useful if we ever need to add back CMYKA support.
+
+        A new dedecution guide added allows for cases that currently deduce to remain.
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::makeColorTypeByNormalizingComponentsAfterMix):
+        (WebCore::CSSPropertyParserHelpers::makeColorTypeByNormalizingComponentsAfterMix<HWBA<float>>):
+        (WebCore::CSSPropertyParserHelpers::makeColorTypeByNormalizingComponentsAfterMix<HSLA<float>>):
+        (WebCore::CSSPropertyParserHelpers::fixupHueComponentsPriorToMix):
+        * platform/graphics/Color.cpp:
+        (WebCore::Color::colorSpaceAndComponents const):
+        * platform/graphics/Color.h:
+        (WebCore::Color::OutOfLineComponents::create):
+        (WebCore::Color::OutOfLineComponents::components const):
+        (WebCore::Color::OutOfLineComponents::OutOfLineComponents):
+        * platform/graphics/ColorComponents.h:
+        (WebCore::ColorComponents::ColorComponents):
+        (WebCore::mapColorComponents):
+        (WebCore::N>::map const):
+        (WebCore::=):
+        (WebCore::N>::operator const):
+        (WebCore::N>::abs const):
+        (WebCore::N>::get const):
+        (WebCore::N>::subset const):
+        (WebCore::perComponentMax):
+        (WebCore::perComponentMin):
+        (WebCore::operator==):
+        (WebCore::operator!=):
+        (WebCore::ColorComponents<T>::map const): Deleted.
+        (WebCore::ColorComponents<T>::operator const): Deleted.
+        (WebCore::ColorComponents<T>::abs const): Deleted.
+        (WebCore::ColorComponents<T>::get const): Deleted.
+        * platform/graphics/ColorMatrix.h:
+        (WebCore::RowCount>::transformedColorComponents const):
+        (WebCore::applyMatricesToColorComponents):
+        * platform/graphics/ColorSpace.h:
+        (WebCore::callWithColorType):
+        * platform/graphics/ColorTypes.h:
+        (WebCore::makeFromComponents):
+        (WebCore::clampedComponent):
+        (WebCore::clampedComponents):
+        (WebCore::clampedComponentsExceptAlpha):
+        (WebCore::makeFromComponentsClamping):
+        (WebCore::makeFromComponentsClampingExceptAlpha):
+        (WebCore::asColorComponents):
+        * platform/graphics/filters/FEColorMatrix.cpp:
+        * platform/graphics/filters/FEMorphology.cpp:
+        (WebCore::makeColorComponentsfromPixelValue):
+        (WebCore::makePixelValueFromColorComponents):
+        (WebCore::minOrMax):
+        (WebCore::columnExtremum):
+        (WebCore::kernelExtremum):
+        (WebCore::FEMorphology::platformApplyGeneric):
+        * platform/graphics/filters/FETurbulence.cpp:
+        (WebCore::FETurbulence::noise2D const):
+        (WebCore::toIntBasedColorComponents):
+        (WebCore::FETurbulence::calculateTurbulenceValueForPoint const):
+        * platform/graphics/filters/FETurbulence.h:
+        * platform/graphics/filters/FilterOperation.cpp:
+        (WebCore::hueRotate):
+
 2021-03-30  Zalan Bujtas  <za...@apple.com>
 
         [RenderTreeBuilder] Anonymous table cell collapsing should also cleanup the inline tree

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (275205 => 275206)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2021-03-30 16:31:21 UTC (rev 275206)
@@ -1662,12 +1662,12 @@
 // Normalization is special cased for HWBA, which needs to normalize the whiteness and blackness components and convert to sRGB
 // and HSLA, which just needs to be converted to sRGB. All other color types can go through this non-specialized case.
 
-template<typename ColorType> inline Color makeColorTypeByNormalizingComponentsAfterMix(const ColorComponents<float>& colorComponents)
+template<typename ColorType> inline Color makeColorTypeByNormalizingComponentsAfterMix(const ColorComponents<float, 4>& colorComponents)
 {
     return makeFromComponents<ColorType>(colorComponents);
 }
 
-template<> inline Color makeColorTypeByNormalizingComponentsAfterMix<HWBA<float>>(const ColorComponents<float>& colorComponents)
+template<> inline Color makeColorTypeByNormalizingComponentsAfterMix<HWBA<float>>(const ColorComponents<float, 4>& colorComponents)
 {
     auto [hue, whiteness, blackness, alpha] = colorComponents;
     auto [normalizedWhitness, normalizedBlackness] = normalizeWhitenessBlackness(whiteness, blackness);
@@ -1675,12 +1675,12 @@
     return convertColor<SRGBA<uint8_t>>(HWBA<float> { hue, normalizedWhitness, normalizedBlackness, alpha });
 }
 
-template<> inline Color makeColorTypeByNormalizingComponentsAfterMix<HSLA<float>>(const ColorComponents<float>& colorComponents)
+template<> inline Color makeColorTypeByNormalizingComponentsAfterMix<HSLA<float>>(const ColorComponents<float, 4>& colorComponents)
 {
     return convertColor<SRGBA<uint8_t>>(makeFromComponents<HSLA<float>>(colorComponents));
 }
 
-template<size_t I, typename ComponentType> static void fixupHueComponentsPriorToMix(ColorComponents<ComponentType>& colorComponents1, ColorComponents<ComponentType>& colorComponents2)
+template<size_t I, typename ComponentType> static void fixupHueComponentsPriorToMix(ColorComponents<ComponentType, 4>& colorComponents1, ColorComponents<ComponentType, 4>& colorComponents2)
 {
     auto normalizeAnglesUsingShorterAlgorithm = [] (auto theta1, auto theta2) -> std::pair<ComponentType, ComponentType> {
         // https://drafts.csswg.org/css-color-4/#hue-shorter

Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/Color.cpp	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp	2021-03-30 16:31:21 UTC (rev 275206)
@@ -171,7 +171,7 @@
     return { asInline(), Flags::Semantic };
 }
 
-std::pair<ColorSpace, ColorComponents<float>> Color::colorSpaceAndComponents() const
+std::pair<ColorSpace, ColorComponents<float, 4>> Color::colorSpaceAndComponents() const
 {
     if (isOutOfLine())
         return { colorSpace(), asOutOfLine().components() };

Modified: trunk/Source/WebCore/platform/graphics/Color.h (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/Color.h	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2021-03-30 16:31:21 UTC (rev 275206)
@@ -121,7 +121,7 @@
     // wrapper around toColorTypeLossy<>().
     template<typename T> SRGBA<T> toSRGBALossy() const { return toColorTypeLossy<SRGBA<T>>(); }
 
-    WEBCORE_EXPORT std::pair<ColorSpace, ColorComponents<float>> colorSpaceAndComponents() const;
+    WEBCORE_EXPORT std::pair<ColorSpace, ColorComponents<float, 4>> colorSpaceAndComponents() const;
 
     WEBCORE_EXPORT Color lightened() const;
     WEBCORE_EXPORT Color darkened() const;
@@ -187,21 +187,21 @@
 private:
     class OutOfLineComponents : public ThreadSafeRefCounted<OutOfLineComponents> {
     public:
-        static Ref<OutOfLineComponents> create(ColorComponents<float> components)
+        static Ref<OutOfLineComponents> create(ColorComponents<float, 4> components)
         {
             return adoptRef(*new OutOfLineComponents(components));
         }
 
         float alpha() const { return m_components[3]; }
-        ColorComponents<float> components() const { return m_components; }
+        ColorComponents<float, 4> components() const { return m_components; }
 
     private:
-        OutOfLineComponents(ColorComponents<float> components)
+        OutOfLineComponents(ColorComponents<float, 4> components)
             : m_components(components)
         {
         }
 
-        ColorComponents<float> m_components;
+        ColorComponents<float, 4> m_components;
     };
     Color(Ref<OutOfLineComponents>&&, ColorSpace, OptionSet<Flags> = { });
 

Modified: trunk/Source/WebCore/platform/graphics/ColorComponents.h (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/ColorComponents.h	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/ColorComponents.h	2021-03-30 16:31:21 UTC (rev 275206)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017, 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,17 +32,24 @@
 
 namespace WebCore {
 
-template<typename T>
+template<typename T, size_t N>
 struct ColorComponents {
-    constexpr static size_t Size = 4;
+    constexpr static size_t Size = N;
 
-    constexpr ColorComponents(T a = 0, T b = 0, T c = 0, T d = 0)
-        : components { a, b, c, d }
+    constexpr ColorComponents()
+        : components { }
     {
     }
 
+    template<typename ...Ts>
+    constexpr ColorComponents(Ts ...input)
+        : components {{ input ... }}
+    {
+        static_assert(sizeof...(Ts) == N);
+    }
+
     template<typename F>
-    constexpr auto map(F&& function) const -> ColorComponents<decltype(function(std::declval<T>()))>;
+    constexpr auto map(F&& function) const -> ColorComponents<decltype(function(std::declval<T>())), N>;
 
     constexpr ColorComponents& operator+=(const ColorComponents&);
 
@@ -55,88 +62,104 @@
     constexpr T& operator[](size_t i) { return components[i]; }
     constexpr const T& operator[](size_t i) const { return components[i]; }
 
-    template<std::size_t N>
+    template<size_t I>
     constexpr T get() const;
 
-    std::array<T, Size> components;
+    template<size_t Start, size_t End>
+    constexpr ColorComponents<T, End - Start> subset() const;
+
+    std::array<T, N> components;
 };
 
+template<typename T, typename ...Ts>
+ColorComponents(T, Ts...) -> ColorComponents<T, 1 + sizeof...(Ts)>;
+
 template<typename F, typename T, typename... Ts>
-constexpr auto mapColorComponents(F&& function, T component, Ts... components) -> ColorComponents<decltype(function(component[0], components[0]...))>
+constexpr auto mapColorComponents(F&& function, T component, Ts... components) -> ColorComponents<decltype(function(component[0], components[0]...)), T::Size>
 {
     static_assert(std::conjunction_v<std::bool_constant<Ts::Size == T::Size>...>, "All ColorComponents passed to mapColorComponents must have the same size");
 
-    ColorComponents<decltype(function(component[0], components[0]...))> result;
+    ColorComponents<decltype(function(component[0], components[0]...)), T::Size> result;
     for (std::remove_const_t<decltype(T::Size)> i = 0; i < T::Size; ++i)
         result[i] = function(component[i], components[i]...);
     return result;
 }
 
-template<typename T>
+template<typename T, size_t N>
 template<typename F>
-constexpr auto ColorComponents<T>::map(F&& function) const -> ColorComponents<decltype(function(std::declval<T>()))>
+constexpr auto ColorComponents<T, N>::map(F&& function) const -> ColorComponents<decltype(function(std::declval<T>())), N>
 {
     return mapColorComponents(std::forward<F>(function), *this);
 }
 
-template<typename T>
-constexpr ColorComponents<T>& ColorComponents<T>::operator+=(const ColorComponents& rhs)
+template<typename T, size_t N>
+constexpr ColorComponents<T, N>& ColorComponents<T, N>::operator+=(const ColorComponents& rhs)
 {
     *this = mapColorComponents([](T c1, T c2) { return c1 + c2; }, *this, rhs);
     return *this;
 }
 
-template<typename T>
-constexpr ColorComponents<T> ColorComponents<T>::operator+(T rhs) const
+template<typename T, size_t N>
+constexpr ColorComponents<T, N> ColorComponents<T, N>::operator+(T rhs) const
 {
     return map([rhs](T c) { return c + rhs; });
 }
 
-template<typename T>
-constexpr ColorComponents<T> ColorComponents<T>::operator/(T denominator) const
+template<typename T, size_t N>
+constexpr ColorComponents<T, N> ColorComponents<T, N>::operator/(T denominator) const
 {
     return map([denominator](T c) { return c / denominator; });
 }
 
-template<typename T>
-constexpr ColorComponents<T> ColorComponents<T>::operator*(T factor) const
+template<typename T, size_t N>
+constexpr ColorComponents<T, N> ColorComponents<T, N>::operator*(T factor) const
 {
     return map([factor](T c) { return c * factor; });
 }
 
-template<typename T>
-constexpr ColorComponents<T> ColorComponents<T>::abs() const
+template<typename T, size_t N>
+constexpr ColorComponents<T, N> ColorComponents<T, N>::abs() const
 {
     return map([](T c) { return std::abs(c); });
 }
 
-template<typename T>
-template<std::size_t N>
-constexpr T ColorComponents<T>::get() const
+template<typename T, size_t N>
+template<size_t I>
+constexpr T ColorComponents<T, N>::get() const
 {
-    return components[N];
+    return components[I];
 }
 
-template<typename T>
-constexpr ColorComponents<T> perComponentMax(const ColorComponents<T>& a, const ColorComponents<T>& b)
+template<typename T, size_t N>
+template<size_t Start, size_t End>
+constexpr ColorComponents<T, End - Start> ColorComponents<T, N>::subset() const
 {
+    ColorComponents<T, End - Start> result;
+    for (std::remove_const_t<decltype(T::Size)> i = Start; i < End; ++i)
+        result[i - Start] = components[i];
+    return result;
+}
+
+template<typename T, size_t N>
+constexpr ColorComponents<T, N> perComponentMax(const ColorComponents<T, N>& a, const ColorComponents<T, N>& b)
+{
     return mapColorComponents([](T c1, T c2) { return std::max(c1, c2); }, a, b);
 }
 
-template<typename T>
-constexpr ColorComponents<T> perComponentMin(const ColorComponents<T>& a, const ColorComponents<T>& b)
+template<typename T, size_t N>
+constexpr ColorComponents<T, N> perComponentMin(const ColorComponents<T, N>& a, const ColorComponents<T, N>& b)
 {
     return mapColorComponents([](T c1, T c2) { return std::min(c1, c2); }, a, b);
 }
 
-template<typename T>
-constexpr bool operator==(const ColorComponents<T>& a, const ColorComponents<T>& b)
+template<typename T, size_t N>
+constexpr bool operator==(const ColorComponents<T, N>& a, const ColorComponents<T, N>& b)
 {
     return a.components == b.components;
 }
 
-template<typename T>
-constexpr bool operator!=(const ColorComponents<T>& a, const ColorComponents<T>& b)
+template<typename T, size_t N>
+constexpr bool operator!=(const ColorComponents<T, N>& a, const ColorComponents<T, N>& b)
 {
     return !(a == b);
 }
@@ -145,12 +168,12 @@
 
 namespace std {
 
-template<typename T>
-class tuple_size<WebCore::ColorComponents<T>> : public std::integral_constant<std::size_t, WebCore::ColorComponents<T>::Size> {
+template<typename T, size_t N>
+class tuple_size<WebCore::ColorComponents<T, N>> : public std::integral_constant<size_t, N> {
 };
 
-template<std::size_t N, typename T>
-class tuple_element<N, WebCore::ColorComponents<T>> {
+template<size_t I, typename T, size_t N>
+class tuple_element<I, WebCore::ColorComponents<T, N>> {
 public:
     using type = T;
 };

Modified: trunk/Source/WebCore/platform/graphics/ColorMatrix.h (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/ColorMatrix.h	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/ColorMatrix.h	2021-03-30 16:31:21 UTC (rev 275206)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-template<typename> struct ColorComponents;
+template<typename, size_t> struct ColorComponents;
 
 template<size_t ColumnCount, size_t RowCount>
 class ColorMatrix {
@@ -42,7 +42,7 @@
         static_assert(sizeof...(Ts) == RowCount * ColumnCount);
     }
 
-    constexpr ColorComponents<float> transformedColorComponents(const ColorComponents<float>&) const;
+    constexpr ColorComponents<float, 4> transformedColorComponents(const ColorComponents<float, 4>&) const;
 
     constexpr float at(size_t row, size_t column) const
     {
@@ -120,24 +120,24 @@
 }
 
 template<size_t ColumnCount, size_t RowCount>
-constexpr ColorComponents<float> ColorMatrix<ColumnCount, RowCount>::transformedColorComponents(const ColorComponents<float>& inputVector) const
+constexpr ColorComponents<float, 4> ColorMatrix<ColumnCount, RowCount>::transformedColorComponents(const ColorComponents<float, 4>& inputVector) const
 {
-    static_assert(ColorComponents<float>::Size >= RowCount);
+    static_assert(ColorComponents<float, 4>::Size >= RowCount);
     
-    ColorComponents<float> result;
+    ColorComponents<float, 4> result;
     for (size_t row = 0; row < RowCount; ++row) {
-        if constexpr (ColumnCount <= ColorComponents<float>::Size) {
+        if constexpr (ColumnCount <= ColorComponents<float, 4>::Size) {
             for (size_t column = 0; column < ColumnCount; ++column)
                 result[row] += at(row, column) * inputVector[column];
-        } else if constexpr (ColumnCount > ColorComponents<float>::Size) {
-            for (size_t column = 0; column < ColorComponents<float>::Size; ++column)
+        } else if constexpr (ColumnCount > ColorComponents<float, 4>::Size) {
+            for (size_t column = 0; column < ColorComponents<float, 4>::Size; ++column)
                 result[row] += at(row, column) * inputVector[column];
-            for (size_t additionalColumn = ColorComponents<float>::Size; additionalColumn < ColumnCount; ++additionalColumn)
+            for (size_t additionalColumn = ColorComponents<float, 4>::Size; additionalColumn < ColumnCount; ++additionalColumn)
                 result[row] += at(row, additionalColumn);
         }
     }
-    if constexpr (ColorComponents<float>::Size > RowCount) {
-        for (size_t additionalRow = RowCount; additionalRow < ColorComponents<float>::Size; ++additionalRow)
+    if constexpr (ColorComponents<float, 4>::Size > RowCount) {
+        for (size_t additionalRow = RowCount; additionalRow < ColorComponents<float, 4>::Size; ++additionalRow)
             result[additionalRow] = inputVector[additionalRow];
     }
 
@@ -144,12 +144,12 @@
     return result;
 }
 
-template<typename T, typename M> inline constexpr auto applyMatricesToColorComponents(const ColorComponents<T>& components, M matrix) -> ColorComponents<T>
+template<typename T, typename M> inline constexpr auto applyMatricesToColorComponents(const ColorComponents<T, 4>& components, M matrix) -> ColorComponents<T, 4>
 {
     return matrix.transformedColorComponents(components);
 }
 
-template<typename T, typename M, typename... Matrices> inline constexpr auto applyMatricesToColorComponents(const ColorComponents<T>& components, M matrix, Matrices... matrices) -> ColorComponents<T>
+template<typename T, typename M, typename... Matrices> inline constexpr auto applyMatricesToColorComponents(const ColorComponents<T, 4>& components, M matrix, Matrices... matrices) -> ColorComponents<T, 4>
 {
     return applyMatricesToColorComponents(matrix.transformedColorComponents(components), matrices...);
 }

Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.h (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/ColorSpace.h	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.h	2021-03-30 16:31:21 UTC (rev 275206)
@@ -70,7 +70,7 @@
 template<typename ColorType> constexpr ColorSpace ColorSpaceFor = ColorSpaceMapping<ColorType>::colorSpace;
 
 
-template<typename T, typename Functor> constexpr decltype(auto) callWithColorType(const ColorComponents<T>& components, ColorSpace colorSpace, Functor&& functor)
+template<typename T, typename Functor> constexpr decltype(auto) callWithColorType(const ColorComponents<T, 4>& components, ColorSpace colorSpace, Functor&& functor)
 {
     switch (colorSpace) {
     case ColorSpace::A98RGB:

Modified: trunk/Source/WebCore/platform/graphics/ColorTypes.h (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/ColorTypes.h	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/ColorTypes.h	2021-03-30 16:31:21 UTC (rev 275206)
@@ -42,11 +42,13 @@
 template<typename> struct HWBA;
 template<typename> struct LCHA;
 template<typename> struct Lab;
+template<typename> struct Oklab;
+template<typename> struct Oklch;
 template<typename, WhitePoint> struct XYZA;
 
 // MARK: Make functions.
 
-template<typename ColorType, typename T> constexpr ColorType makeFromComponents(const ColorComponents<T>& c)
+template<typename ColorType, typename T> constexpr ColorType makeFromComponents(const ColorComponents<T, 4>& c)
 {
     return ColorType { c[0], c[1], c[2], c[3] };
 }
@@ -75,7 +77,7 @@
     return std::clamp(c, componentInfo.min, componentInfo.max);
 }
 
-template<typename ColorType, unsigned Index, typename T> constexpr T clampedComponent(const ColorComponents<T>& c)
+template<typename ColorType, unsigned Index, typename T> constexpr T clampedComponent(const ColorComponents<T, 4>& c)
 {
     return clampedComponent<ColorType, Index>(c[Index]);
 }
@@ -85,17 +87,17 @@
     return std::clamp<T>(alpha, AlphaTraits<ComponentType>::transparent, AlphaTraits<ComponentType>::opaque);
 }
 
-template<typename ColorType, typename T> constexpr ColorComponents<T> clampedComponents(const ColorComponents<T>& components)
+template<typename ColorType, typename T> constexpr ColorComponents<T, 4> clampedComponents(const ColorComponents<T, 4>& components)
 {
     return { clampedComponent<ColorType, 0>(components), clampedComponent<ColorType, 1>(components), clampedComponent<ColorType, 2>(components), clampedAlpha(components[3]) };
 }
 
-template<typename ColorType, typename T> constexpr ColorComponents<T> clampedComponentsExceptAlpha(const ColorComponents<T>& components)
+template<typename ColorType, typename T> constexpr ColorComponents<T, 4> clampedComponentsExceptAlpha(const ColorComponents<T, 4>& components)
 {
     return { clampedComponent<ColorType, 0>(components), clampedComponent<ColorType, 1>(components), clampedComponent<ColorType, 2>(components), components[3] };
 }
 
-template<typename ColorType, typename T> constexpr ColorType makeFromComponentsClamping(const ColorComponents<T>& components)
+template<typename ColorType, typename T> constexpr ColorType makeFromComponentsClamping(const ColorComponents<T, 4>& components)
 {
     return makeFromComponents<ColorType>(clampedComponents<ColorType>(components));
 }
@@ -110,7 +112,7 @@
     return makeFromComponents<ColorType>(ColorComponents { clampedComponent<ColorType, 0>(c1), clampedComponent<ColorType, 1>(c2), clampedComponent<ColorType, 2>(c3), clampedAlpha<T, typename ColorType::ComponentType>(alpha) });
 }
 
-template<typename ColorType, typename T> constexpr ColorType makeFromComponentsClampingExceptAlpha(const ColorComponents<T>& components)
+template<typename ColorType, typename T> constexpr ColorType makeFromComponentsClampingExceptAlpha(const ColorComponents<T, 4>& components)
 {
     return makeFromComponents<ColorType>(clampedComponentsExceptAlpha<ColorType>(components));
 }
@@ -212,7 +214,7 @@
     T alpha;
 };
 
-template<typename T, typename D, typename ColorType, typename M, typename TF> constexpr ColorComponents<T> asColorComponents(const RGBAType<T, D, ColorType, M, TF>& c)
+template<typename T, typename D, typename ColorType, typename M, typename TF> constexpr ColorComponents<T, 4> asColorComponents(const RGBAType<T, D, ColorType, M, TF>& c)
 {
     return { c.red, c.green, c.blue, c.alpha };
 }
@@ -418,7 +420,7 @@
     T alpha;
 };
 
-template<typename T> constexpr ColorComponents<T> asColorComponents(const Lab<T>& c)
+template<typename T> constexpr ColorComponents<T, 4> asColorComponents(const Lab<T>& c)
 {
     return { c.lightness, c.a, c.b, c.alpha };
 }
@@ -453,7 +455,7 @@
     T alpha;
 };
 
-template<typename T> constexpr ColorComponents<T> asColorComponents(const LCHA<T>& c)
+template<typename T> constexpr ColorComponents<T, 4> asColorComponents(const LCHA<T>& c)
 {
     return { c.lightness, c.chroma, c.hue, c.alpha };
 }
@@ -489,7 +491,7 @@
     T alpha;
 };
 
-template<typename T> constexpr ColorComponents<T> asColorComponents(const HSLA<T>& c)
+template<typename T> constexpr ColorComponents<T, 4> asColorComponents(const HSLA<T>& c)
 {
     return { c.hue, c.saturation, c.lightness, c.alpha };
 }
@@ -524,7 +526,7 @@
     T alpha;
 };
 
-template<typename T> constexpr ColorComponents<T> asColorComponents(const HWBA<T>& c)
+template<typename T> constexpr ColorComponents<T, 4> asColorComponents(const HWBA<T>& c)
 {
     return { c.hue, c.whiteness, c.blackness, c.alpha };
 }
@@ -559,7 +561,7 @@
     T alpha;
 };
 
-template<typename T, WhitePoint W> constexpr ColorComponents<T> asColorComponents(const XYZA<T, W>& c)
+template<typename T, WhitePoint W> constexpr ColorComponents<T, 4> asColorComponents(const XYZA<T, W>& c)
 {
     return { c.x, c.y, c.z, c.alpha };
 }

Modified: trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2021-03-30 16:31:21 UTC (rev 275206)
@@ -87,7 +87,7 @@
     blue    = r * components[6] + g * components[7] + b * components[8];
 }
 
-// FIXME: this should use luminance(const ColorComponents<float>& sRGBCompontents).
+// FIXME: this should use the luminance(...) function in ColorLuminance.h.
 inline void luminance(float& red, float& green, float& blue, float& alpha)
 {
     alpha = 0.2125 * red + 0.7154 * green + 0.0721 * blue;

Modified: trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp	2021-03-30 16:31:21 UTC (rev 275206)
@@ -88,19 +88,18 @@
     return (y * width + x) * 4;
 }
 
-inline ColorComponents<uint8_t> makeColorComponentsfromPixelValue(unsigned pixel)
+inline ColorComponents<uint8_t, 4> makeColorComponentsfromPixelValue(PackedColor::RGBA pixel)
 {
-    return ColorComponents<uint8_t>((pixel >> 24) & 0xFF, (pixel >> 16) & 0xFF, (pixel >> 8) & 0xFF, pixel & 0xFF);
+    return asColorComponents(asSRGBA(pixel));
 }
 
-inline unsigned makePixelValueFromColorComponents(const ColorComponents<uint8_t>& components)
+inline PackedColor::RGBA makePixelValueFromColorComponents(const ColorComponents<uint8_t, 4>& components)
 {
-    auto [r, g, b, a] = components;
-    return r << 24 | g << 16 | b << 8 | a;
+    return PackedColor::RGBA { makeFromComponents<SRGBA<uint8_t>>(components) };
 }
 
 template<MorphologyOperatorType type>
-ALWAYS_INLINE ColorComponents<uint8_t> minOrMax(const ColorComponents<uint8_t>& a, const ColorComponents<uint8_t>& b)
+ALWAYS_INLINE ColorComponents<uint8_t, 4> minOrMax(const ColorComponents<uint8_t, 4>& a, const ColorComponents<uint8_t, 4>& b)
 {
     if (type == FEMORPHOLOGY_OPERATOR_ERODE)
         return perComponentMin(a, b);
@@ -109,18 +108,18 @@
 }
 
 template<MorphologyOperatorType type>
-ALWAYS_INLINE ColorComponents<uint8_t> columnExtremum(const Uint8ClampedArray& srcPixelArray, int x, int yStart, int yEnd, int width)
+ALWAYS_INLINE ColorComponents<uint8_t, 4> columnExtremum(const Uint8ClampedArray& srcPixelArray, int x, int yStart, int yEnd, int width)
 {
-    auto extremum = makeColorComponentsfromPixelValue(*reinterpret_cast<const unsigned*>(srcPixelArray.data() + pixelArrayIndex(x, yStart, width)));
+    auto extremum = makeColorComponentsfromPixelValue(PackedColor::RGBA { *reinterpret_cast<const unsigned*>(srcPixelArray.data() + pixelArrayIndex(x, yStart, width)) });
 
     for (int y = yStart + 1; y < yEnd; ++y) {
-        auto pixel = makeColorComponentsfromPixelValue(*reinterpret_cast<const unsigned*>(srcPixelArray.data() + pixelArrayIndex(x, y, width)));
+        auto pixel = makeColorComponentsfromPixelValue(PackedColor::RGBA { *reinterpret_cast<const unsigned*>(srcPixelArray.data() + pixelArrayIndex(x, y, width)) });
         extremum = minOrMax<type>(extremum, pixel);
     }
     return extremum;
 }
 
-ALWAYS_INLINE ColorComponents<uint8_t> columnExtremum(const Uint8ClampedArray& srcPixelArray, int x, int yStart, int yEnd, int width, MorphologyOperatorType type)
+ALWAYS_INLINE ColorComponents<uint8_t, 4> columnExtremum(const Uint8ClampedArray& srcPixelArray, int x, int yStart, int yEnd, int width, MorphologyOperatorType type)
 {
     if (type == FEMORPHOLOGY_OPERATOR_ERODE)
         return columnExtremum<FEMORPHOLOGY_OPERATOR_ERODE>(srcPixelArray, x, yStart, yEnd, width);
@@ -128,10 +127,10 @@
     return columnExtremum<FEMORPHOLOGY_OPERATOR_DILATE>(srcPixelArray, x, yStart, yEnd, width);
 }
 
-using ColumnExtrema = Vector<ColorComponents<uint8_t>, 16>;
+using ColumnExtrema = Vector<ColorComponents<uint8_t, 4>, 16>;
 
 template<MorphologyOperatorType type>
-ALWAYS_INLINE ColorComponents<uint8_t> kernelExtremum(const ColumnExtrema& kernel)
+ALWAYS_INLINE ColorComponents<uint8_t, 4> kernelExtremum(const ColumnExtrema& kernel)
 {
     auto extremum = kernel[0];
     for (size_t i = 1; i < kernel.size(); ++i)
@@ -140,7 +139,7 @@
     return extremum;
 }
 
-ALWAYS_INLINE ColorComponents<uint8_t> kernelExtremum(const ColumnExtrema& kernel, MorphologyOperatorType type)
+ALWAYS_INLINE ColorComponents<uint8_t, 4> kernelExtremum(const ColumnExtrema& kernel, MorphologyOperatorType type)
 {
     if (type == FEMORPHOLOGY_OPERATOR_ERODE)
         return kernelExtremum<FEMORPHOLOGY_OPERATOR_ERODE>(kernel);
@@ -185,7 +184,7 @@
                 extrema.remove(0);
 
             unsigned* destPixel = reinterpret_cast<unsigned*>(dstPixelArray.data() + pixelArrayIndex(x, y, width));
-            *destPixel = makePixelValueFromColorComponents(kernelExtremum(extrema, m_type));
+            *destPixel = makePixelValueFromColorComponents(kernelExtremum(extrema, m_type)).value;
         }
     }
 }

Modified: trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp	2021-03-30 16:31:21 UTC (rev 275206)
@@ -217,7 +217,7 @@
 }
 
 // This is taken 1:1 from SVG spec: http://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement.
-ColorComponents<float> FETurbulence::noise2D(const PaintingData& paintingData, const StitchData& stitchData, const FloatPoint& noiseVector) const
+ColorComponents<float, 4> FETurbulence::noise2D(const PaintingData& paintingData, const StitchData& stitchData, const FloatPoint& noiseVector) const
 {
     struct NoisePosition {
         int index; // bx0, by0 in the spec text.
@@ -322,7 +322,8 @@
 }
 
 // https://www.w3.org/TR/SVG/filters.html#feTurbulenceElement describes this conversion to color components.
-static inline ColorComponents<uint8_t> toIntBasedColorComponents(const ColorComponents<float>& floatComponents)
+// FIXME: This should use colorConvert<SRGBA<uint8>>(SRGBA<float>) to get the same behavior.
+static inline ColorComponents<uint8_t, 4> toIntBasedColorComponents(const ColorComponents<float, 4>& floatComponents)
 {
     return {
         std::clamp<uint8_t>(static_cast<int>(floatComponents[0] * 255), 0, 255),
@@ -332,9 +333,9 @@
     };
 }
 
-ColorComponents<uint8_t> FETurbulence::calculateTurbulenceValueForPoint(const PaintingData& paintingData, StitchData stitchData, const FloatPoint& point) const
+ColorComponents<uint8_t, 4> FETurbulence::calculateTurbulenceValueForPoint(const PaintingData& paintingData, StitchData stitchData, const FloatPoint& point) const
 {
-    ColorComponents<float> turbulenceFunctionResult;
+    ColorComponents<float, 4> turbulenceFunctionResult;
     FloatPoint noiseVector(point.x() * paintingData.baseFrequencyX, point.y() * paintingData.baseFrequencyY);
     float ratio = 1;
     for (int octave = 0; octave < m_numOctaves; ++octave) {

Modified: trunk/Source/WebCore/platform/graphics/filters/FETurbulence.h (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/filters/FETurbulence.h	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/filters/FETurbulence.h	2021-03-30 16:31:21 UTC (rev 275206)
@@ -116,8 +116,8 @@
 
     void initPaint(PaintingData&);
     StitchData computeStitching(IntSize tileSize, float& baseFrequencyX, float& baseFrequencyY) const;
-    ColorComponents<float> noise2D(const PaintingData&, const StitchData&, const FloatPoint&) const;
-    ColorComponents<uint8_t> calculateTurbulenceValueForPoint(const PaintingData&, StitchData, const FloatPoint&) const;
+    ColorComponents<float, 4> noise2D(const PaintingData&, const StitchData&, const FloatPoint&) const;
+    ColorComponents<uint8_t, 4> calculateTurbulenceValueForPoint(const PaintingData&, StitchData, const FloatPoint&) const;
     void fillRegion(Uint8ClampedArray&, const PaintingData&, StitchData, int startY, int endY) const;
 
     static void fillRegionWorker(void*);

Modified: trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp (275205 => 275206)


--- trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp	2021-03-30 16:16:15 UTC (rev 275205)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp	2021-03-30 16:31:21 UTC (rev 275206)
@@ -228,7 +228,7 @@
 // on color values outside of the non-extended SRGB value range (0-1) to maintain the behavior of colors
 // prior to clamping being enforced. It should likely just use the existing hueRotateColorMatrix(amount)
 // in ColorMatrix.h
-static ColorComponents<float> hueRotate(const ColorComponents<float>& color, float amount)
+static ColorComponents<float, 4> hueRotate(const ColorComponents<float, 4>& color, float amount)
 {
     auto [r, g, b, alpha] = color;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to