Diff
Modified: trunk/Source/WebCore/ChangeLog (272473 => 272474)
--- trunk/Source/WebCore/ChangeLog 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/ChangeLog 2021-02-07 19:22:59 UTC (rev 272474)
@@ -1,3 +1,92 @@
+2021-02-07 Sam Weinig <[email protected]>
+
+ Remove more special cases from color conversion
+ https://bugs.webkit.org/show_bug.cgi?id=221519
+
+ Reviewed by Antti Koivisto.
+
+ - Remove specialized convertTo<> function which only did component
+ type conversion with the fully general convertColor<> function.
+
+ - Make ColorComponents a bit more ready for non-4 component colors by
+ reworking member functionality based on a new mapColorComponents function
+ which maps a function F over all the components of a set of ColorComponents.
+ e.g.
+
+ auto colorComponentsC = mapColorComponents([] (auto a, auto b) { return a + b; }, colorComponentsA, colorComponentsB);
+
+ will create a new ColorComponents where each component is the sum of the
+ corresponding components in colorComponentsA and colorComponentsB. It's
+ variadic so it can take any number of ColorComponents. This allows rewriting
+ all of the members to be size invariant and a little less verbose.
+
+ - Replace special case for the identity conversion in the fallback color conversion
+ code path, and move it into it's own partial specialization of ColorConversion.
+
+ - Replace special case for chromatic adaptation conversions and have them just
+ use specializations of ColorConversion like all other conversions.
+
+ * platform/graphics/ColorComponents.h:
+ (WebCore::mapColorComponents):
+ (WebCore::ColorComponents<T>::map const):
+ (WebCore::ColorComponents<T>::operator const):
+ (WebCore::ColorComponents<T>::abs const):
+ (WebCore::perComponentMax):
+ (WebCore::perComponentMin):
+ Add map and mapColorComponents and re-implement existing
+ functionality in terms of them.
+
+ * platform/graphics/ColorConversion.cpp:
+ (WebCore::WhitePoint::D50>>::convert):
+ (WebCore::WhitePoint::D65>>::convert):
+ (WebCore::SRGBA<uint8_t>>::convert):
+ (WebCore::SRGBA<float>>::convert):
+ (WebCore::SRGBA<uint8_t>::ReferenceXYZ>::convert):
+ (WebCore::convertFromD50WhitePointToD65WhitePoint): Deleted.
+ (WebCore::convertFromD65WhitePointToD50WhitePoint): Deleted.
+ * platform/graphics/ColorConversion.h:
+ (WebCore::ColorConversion::convert):
+ (WebCore::performChomaticAdapatation): Deleted.
+ Use ColorConversion specializations for the identity conversion, chomatic
+ adapatation, and component type conversions, rather than hard coding them
+ in the fallback conversion.
+
+ * platform/graphics/ColorUtilities.h:
+ (WebCore::convertTo): Deleted.
+ Remove convertTo<>, which is now superseded by the general convertColor<>.
+
+ * accessibility/atk/WebKitAccessibleInterfaceText.cpp:
+ (webkitAccessibleTextGetText):
+ * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+ (-[WebAccessibilityObjectWrapper accessibilityColorStringValue]):
+ * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
+ (-[WebAccessibilityObjectWrapper accessibilityAttributeValue:]):
+ * html/canvas/CanvasRenderingContext2DBase.cpp:
+ (WebCore::CanvasRenderingContext2DBase::setShadow):
+ * html/canvas/CanvasStyle.cpp:
+ (WebCore::CanvasStyle::CanvasStyle):
+ (WebCore::CanvasStyle::isEquivalent const):
+ * platform/graphics/Color.cpp:
+ (WebCore::Color::lightened const):
+ (WebCore::Color::darkened const):
+ (WebCore::Color::colorSpaceAndComponents const):
+ * platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
+ (WebCore::makeSimpleColorFromARGBCFArray):
+ * platform/graphics/filters/FilterOperations.cpp:
+ (WebCore::FilterOperations::transformColor const):
+ (WebCore::FilterOperations::inverseTransformColor const):
+ * platform/graphics/gtk/ColorGtk.cpp:
+ (WebCore::Color::Color):
+ * platform/graphics/mac/ColorMac.mm:
+ (WebCore::makeSimpleColorFromNSColor):
+ * platform/graphics/win/ColorDirect2D.cpp:
+ (WebCore::Color::Color):
+ * platform/graphics/win/PlatformContextDirect2D.cpp:
+ (WebCore::PlatformContextDirect2D::brushWithColor):
+ * platform/ios/ColorIOS.mm:
+ (WebCore::colorFromUIColor):
+ Adopt convertColor<> to replace convertTo<>.
+
2021-02-07 Antti Koivisto <[email protected]>
[LFC][Integration] Fix http/wpt/css/css-highlight-api/ tests with inlines enabled
Modified: trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp (272473 => 272474)
--- trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -443,7 +443,7 @@
#if ENABLE(INPUT_TYPE_COLOR)
if (coreObject->roleValue() == AccessibilityRole::ColorWell) {
- auto color = convertTo<SRGBA<float>>(coreObject->colorValue());
+ auto color = convertColor<SRGBA<float>>(coreObject->colorValue());
return g_strdup_printf("rgb %7.5f %7.5f %7.5f 1", color.red, color.green, color.blue);
}
#endif
Modified: trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm (272473 => 272474)
--- trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm 2021-02-07 19:22:59 UTC (rev 272474)
@@ -1453,7 +1453,7 @@
return nil;
if (self.axBackingObject->isColorWell()) {
- auto color = convertTo<SRGBA<float>>(self.axBackingObject->colorValue());
+ auto color = convertColor<SRGBA<float>>(self.axBackingObject->colorValue());
return [NSString stringWithFormat:@"rgb %7.5f %7.5f %7.5f 1", color.red, color.green, color.blue];
}
Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm (272473 => 272474)
--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm 2021-02-07 19:22:59 UTC (rev 272474)
@@ -2385,7 +2385,7 @@
return @(backingObject->isSelected());
if (backingObject->isColorWell()) {
- auto color = convertTo<SRGBA<float>>(backingObject->colorValue());
+ auto color = convertColor<SRGBA<float>>(backingObject->colorValue());
return [NSString stringWithFormat:@"rgb %7.5f %7.5f %7.5f 1", color.red, color.green, color.blue];
}
Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (272473 => 272474)
--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -1324,7 +1324,7 @@
if (std::isnan(grayLevel) || std::isnan(alpha))
return;
- setShadow(FloatSize(width, height), blur, convertTo<SRGBA<uint8_t>>(makeFromComponentsClamping<SRGBA<float>>(grayLevel, grayLevel, grayLevel, alpha)));
+ setShadow(FloatSize(width, height), blur, convertColor<SRGBA<uint8_t>>(makeFromComponentsClamping<SRGBA<float>>(grayLevel, grayLevel, grayLevel, alpha)));
}
void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, float r, float g, float b, float a)
@@ -1332,7 +1332,7 @@
if (std::isnan(r) || std::isnan(g) || std::isnan(b) || std::isnan(a))
return;
- setShadow(FloatSize(width, height), blur, convertTo<SRGBA<uint8_t>>(makeFromComponentsClamping<SRGBA<float>>(r, g, b, a)));
+ setShadow(FloatSize(width, height), blur, convertColor<SRGBA<uint8_t>>(makeFromComponentsClamping<SRGBA<float>>(r, g, b, a)));
}
void CanvasRenderingContext2DBase::clearShadow()
Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.cpp (272473 => 272474)
--- trunk/Source/WebCore/html/canvas/CanvasStyle.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -95,7 +95,7 @@
}
CanvasStyle::CanvasStyle(const SRGBA<float>& colorComponents)
- : m_style(convertTo<SRGBA<uint8_t>>(colorComponents))
+ : m_style(convertColor<SRGBA<uint8_t>>(colorComponents))
{
}
@@ -148,7 +148,7 @@
bool CanvasStyle::isEquivalent(const SRGBA<float>& components) const
{
- return WTF::holds_alternative<Color>(m_style) && WTF::get<Color>(m_style) == convertTo<SRGBA<uint8_t>>(components);
+ return WTF::holds_alternative<Color>(m_style) && WTF::get<Color>(m_style) == convertColor<SRGBA<uint8_t>>(components);
}
void CanvasStyle::applyStrokeColor(GraphicsContext& context) const
Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/Color.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -91,7 +91,7 @@
float multiplier = std::min(1.0f, v + 0.33f) / v;
- return convertTo<SRGBA<uint8_t>>(SRGBA { multiplier * r, multiplier * g, multiplier * b, a });
+ return convertColor<SRGBA<uint8_t>>(SRGBA { multiplier * r, multiplier * g, multiplier * b, a });
}
Color Color::darkened() const
@@ -105,7 +105,7 @@
float v = std::max({ r, g, b });
float multiplier = std::max(0.0f, (v - 0.33f) / v);
- return convertTo<SRGBA<uint8_t>>(SRGBA { multiplier * r, multiplier * g, multiplier * b, a });
+ return convertColor<SRGBA<uint8_t>>(SRGBA { multiplier * r, multiplier * g, multiplier * b, a });
}
float Color::lightness() const
@@ -165,7 +165,7 @@
{
if (isExtended())
return { asExtended().colorSpace(), asExtended().components() };
- return { ColorSpace::SRGB, asColorComponents(convertTo<SRGBA<float>>(asInline())) };
+ return { ColorSpace::SRGB, asColorComponents(convertColor<SRGBA<float>>(asInline())) };
}
TextStream& operator<<(TextStream& ts, const Color& color)
Modified: trunk/Source/WebCore/platform/graphics/ColorComponents.h (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/ColorComponents.h 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/ColorComponents.h 2021-02-07 19:22:59 UTC (rev 272474)
@@ -41,6 +41,9 @@
{
}
+ template<typename F>
+ constexpr auto map(F&& function) const -> ColorComponents<decltype(function(std::declval<T>()))>;
+
constexpr ColorComponents& operator+=(const ColorComponents&);
constexpr ColorComponents operator+(T) const;
@@ -58,13 +61,28 @@
std::array<T, Size> components;
};
+template<typename F, typename T, typename... Ts>
+constexpr auto mapColorComponents(F&& function, T component, Ts... components) -> ColorComponents<decltype(function(component[0], components[0]...))>
+{
+ 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;
+ for (size_t i = 0; i < T::Size; ++i)
+ result[i] = function(component[i], components[i]...);
+ return result;
+}
+
template<typename T>
+template<typename F>
+constexpr auto ColorComponents<T>::map(F&& function) const -> ColorComponents<decltype(function(std::declval<T>()))>
+{
+ return mapColorComponents(std::forward<F>(function), *this);
+}
+
+template<typename T>
constexpr ColorComponents<T>& ColorComponents<T>::operator+=(const ColorComponents& rhs)
{
- components[0] += rhs[0];
- components[1] += rhs[1];
- components[2] += rhs[2];
- components[3] += rhs[3];
+ *this = mapColorComponents([](T c1, T c2) { return c1 + c2; }, *this, rhs);
return *this;
}
@@ -71,45 +89,25 @@
template<typename T>
constexpr ColorComponents<T> ColorComponents<T>::operator+(T rhs) const
{
- return {
- components[0] + rhs,
- components[1] + rhs,
- components[2] + rhs,
- components[3] + rhs
- };
+ return map([rhs](T c) { return c + rhs; });
}
template<typename T>
constexpr ColorComponents<T> ColorComponents<T>::operator/(T denominator) const
{
- return {
- components[0] / denominator,
- components[1] / denominator,
- components[2] / denominator,
- components[3] / denominator
- };
+ return map([denominator](T c) { return c / denominator; });
}
template<typename T>
constexpr ColorComponents<T> ColorComponents<T>::operator*(T factor) const
{
- return {
- components[0] * factor,
- components[1] * factor,
- components[2] * factor,
- components[3] * factor
- };
+ return map([factor](T c) { return c * factor; });
}
template<typename T>
constexpr ColorComponents<T> ColorComponents<T>::abs() const
{
- return {
- std::abs(components[0]),
- std::abs(components[1]),
- std::abs(components[2]),
- std::abs(components[3])
- };
+ return map([](T c) { return std::abs(c); });
}
template<typename T>
@@ -122,23 +120,13 @@
template<typename T>
constexpr ColorComponents<T> perComponentMax(const ColorComponents<T>& a, const ColorComponents<T>& b)
{
- return {
- std::max(a[0], b[0]),
- std::max(a[1], b[1]),
- std::max(a[2], b[2]),
- std::max(a[3], b[3])
- };
+ 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)
{
- return {
- std::min(a[0], b[0]),
- std::min(a[1], b[1]),
- std::min(a[2], b[2]),
- std::min(a[3], b[3])
- };
+ return mapColorComponents([](T c1, T c2) { return std::min(c1, c2); }, a, b);
}
template<typename T>
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.cpp (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -133,12 +133,12 @@
// MARK: Chromatic Adaptation conversions.
-XYZA<float, WhitePoint::D65> convertFromD50WhitePointToD65WhitePoint(const XYZA<float, WhitePoint::D50>& color)
+XYZA<float, WhitePoint::D65> ColorConversion<XYZA<float, WhitePoint::D65>, XYZA<float, WhitePoint::D50>>::convert(const XYZA<float, WhitePoint::D50>& color)
{
return makeFromComponentsClampingExceptAlpha<XYZA<float, WhitePoint::D65>>(D50ToD65Matrix.transformedColorComponents(asColorComponents(color)));
}
-XYZA<float, WhitePoint::D50> convertFromD65WhitePointToD50WhitePoint(const XYZA<float, WhitePoint::D65>& color)
+XYZA<float, WhitePoint::D50> ColorConversion<XYZA<float, WhitePoint::D50>, XYZA<float, WhitePoint::D65>>::convert(const XYZA<float, WhitePoint::D65>& color)
{
return makeFromComponentsClampingExceptAlpha<XYZA<float, WhitePoint::D50>>(D65ToD50Matrix.transformedColorComponents(asColorComponents(color)));
}
@@ -646,4 +646,20 @@
return convertColor<SRGBA<float>>(convertColor<LinearSRGBA<float>>(color));
}
+// MARK: SRGBA<uint8_t> component type conversions.
+
+SRGBA<float> ColorConversion<SRGBA<float>, SRGBA<uint8_t>>::convert(const SRGBA<uint8_t>& color)
+{
+ return makeFromComponents<SRGBA<float>>(asColorComponents(color).map([](uint8_t value) -> float {
+ return value / 255.0f;
+ }));
+}
+
+SRGBA<uint8_t> ColorConversion<SRGBA<uint8_t>, SRGBA<float>>::convert(const SRGBA<float>& color)
+{
+ return makeFromComponents<SRGBA<uint8_t>>(asColorComponents(color).map([](float value) -> uint8_t {
+ return std::lround(value * 255.0f);
+ }));
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.h (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.h 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.h 2021-02-07 19:22:59 UTC (rev 272474)
@@ -299,25 +299,36 @@
WEBCORE_EXPORT static HWBA<float> convert(const SRGBA<float>&);
};
+// Special cases for SRGBA<uint8_t>. Only sRGB supports non-floating point component types.
+template<> struct ColorConversion<SRGBA<float>, SRGBA<uint8_t>> {
+ WEBCORE_EXPORT static SRGBA<float> convert(const SRGBA<uint8_t>&);
+};
+template<> struct ColorConversion<SRGBA<uint8_t>, SRGBA<float>> {
+ WEBCORE_EXPORT static SRGBA<uint8_t> convert(const SRGBA<float>&);
+};
-// Chromatic Adaptation conversions.
-WEBCORE_EXPORT XYZA<float, WhitePoint::D65> convertFromD50WhitePointToD65WhitePoint(const XYZA<float, WhitePoint::D50>&);
-WEBCORE_EXPORT XYZA<float, WhitePoint::D50> convertFromD65WhitePointToD50WhitePoint(const XYZA<float, WhitePoint::D65>&);
-template<typename T, WhitePoint inputWhitePoint> constexpr typename T::ReferenceXYZ performChomaticAdapatation(const XYZA<float, inputWhitePoint>& color)
-{
- constexpr WhitePoint outputWhitePoint = T::ReferenceXYZ::whitePoint;
+// XYZA Chromatic Adaptation conversions.
+template<> struct ColorConversion<XYZA<float, WhitePoint::D65>, XYZA<float, WhitePoint::D50>> {
+ WEBCORE_EXPORT static XYZA<float, WhitePoint::D65> convert(const XYZA<float, WhitePoint::D50>&);
+};
- if constexpr (outputWhitePoint == inputWhitePoint)
+template<> struct ColorConversion<XYZA<float, WhitePoint::D50>, XYZA<float, WhitePoint::D65>> {
+ WEBCORE_EXPORT static XYZA<float, WhitePoint::D50> convert(const XYZA<float, WhitePoint::D65>&);
+};
+
+
+// Identity conversion.
+
+template<typename ColorType> struct ColorConversion<ColorType, ColorType> {
+ static ColorType convert(const ColorType& color)
+ {
return color;
- else if constexpr (outputWhitePoint == WhitePoint::D50)
- return convertFromD65WhitePointToD50WhitePoint(color);
- else if constexpr (outputWhitePoint == WhitePoint::D65)
- return convertFromD50WhitePointToD65WhitePoint(color);
-}
+ }
+};
-// Fallback conversions.
+// Fallback conversion.
// All types are required to have a conversion to their reference XYZ space, so this is guaranteed
// to work if another specialization is not already provided.
@@ -357,15 +368,13 @@
template<typename Output, typename Input> struct ColorConversion {
static Output convert(const Input& color)
{
- if constexpr(std::is_same_v<Output, Input>)
- return color;
- else if constexpr (std::is_same_v<typename Input::ComponentType, uint8_t>)
- return convertColor<Output>(convertTo<SRGBA<float>>(color));
- else if constexpr (std::is_same_v<typename Output::ComponentType, uint8_t>)
- return convertTo<SRGBA<uint8_t>>(convertColor<SRGBA<float>>(color));
+ if constexpr (std::is_same_v<Input, SRGBA<uint8_t>>)
+ return convertColor<Output>(convertColor<SRGBA<float>>(color));
+ else if constexpr (std::is_same_v<Output, SRGBA<uint8_t>>)
+ return convertColor<SRGBA<uint8_t>>(convertColor<SRGBA<float>>(color));
else {
auto xyz1 = convertColor<typename Input::ReferenceXYZ>(color);
- auto xyz2 = performChomaticAdapatation<Output>(xyz1);
+ auto xyz2 = convertColor<typename Output::ReferenceXYZ>(xyz1);
return convertColor<Output>(xyz2);
}
}
Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2021-02-07 19:22:59 UTC (rev 272474)
@@ -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
@@ -50,10 +50,6 @@
template<typename T> T convertByteAlphaTo(uint8_t);
template<typename T> T convertFloatAlphaTo(float);
-template<typename T, typename U> T convertTo(const U&);
-template<> SRGBA<float> convertTo(const SRGBA<uint8_t>&);
-template<> SRGBA<uint8_t> convertTo(const SRGBA<float>&);
-
template<typename ColorType, typename Functor> ColorType colorByModifingEachNonAlphaComponent(const ColorType&, Functor&&);
template<typename ColorType> constexpr ColorType colorWithOverridenAlpha(const ColorType&, uint8_t overrideAlpha);
@@ -62,13 +58,13 @@
template<typename ColorType> constexpr ColorType invertedColorWithOverridenAlpha(const ColorType&, uint8_t overrideAlpha);
template<typename ColorType> ColorType invertedColorWithOverridenAlpha(const ColorType&, float overrideAlpha);
+template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr> constexpr bool isBlack(const ColorType&);
+template<WhitePoint W> constexpr bool isBlack(const XYZA<float, W>&);
constexpr bool isBlack(const Lab<float>&);
-template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr>
-constexpr bool isBlack(const ColorType&);
+template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr> constexpr bool isWhite(const ColorType&);
+template<WhitePoint W> constexpr bool isWhite(const XYZA<float, W>&);
constexpr bool isWhite(const Lab<float>&);
-template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr>
-constexpr bool isWhite(const ColorType&);
constexpr uint16_t fastMultiplyBy255(uint16_t);
constexpr uint16_t fastDivideBy255(uint16_t);
@@ -99,26 +95,6 @@
return clampedAlpha(value);
}
-template<> inline SRGBA<float> convertTo(const SRGBA<uint8_t>& color)
-{
- auto convertToSRGBAFloat = [](uint8_t value) -> float {
- return value / 255.0f;
- };
-
- auto components = asColorComponents(color);
- return { convertToSRGBAFloat(components[0]), convertToSRGBAFloat(components[1]), convertToSRGBAFloat(components[2]), convertToSRGBAFloat(components[3]) };
-}
-
-template<> inline SRGBA<uint8_t> convertTo(const SRGBA<float>& color)
-{
- auto convertToSRGBAByte = [](float value) -> uint8_t {
- return std::clamp(std::lround(value * 255.0f), 0l, 255l);
- };
-
- auto components = asColorComponents(color);
- return { convertToSRGBAByte(components[0]), convertToSRGBAByte(components[1]), convertToSRGBAByte(components[2]), convertToSRGBAByte(components[3]) };
-}
-
template<typename ColorType, typename Functor> ColorType colorByModifingEachNonAlphaComponent(const ColorType& color, Functor&& functor)
{
auto components = asColorComponents(color);
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -80,7 +80,7 @@
componentArray[i] = component;
}
- return convertTo<SRGBA<uint8_t>>(SRGBA { componentArray[1], componentArray[2], componentArray[3], componentArray[0] });
+ return convertColor<SRGBA<uint8_t>>(SRGBA { componentArray[1], componentArray[2], componentArray[3], componentArray[0] });
}
Ref<InbandGenericCue> InbandTextTrackPrivateAVF::processCueAttributes(CFAttributedStringRef attributedString)
Modified: trunk/Source/WebCore/platform/graphics/filters/FilterOperations.cpp (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/filters/FilterOperations.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterOperations.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -117,7 +117,7 @@
return false;
}
- color = convertTo<SRGBA<uint8_t>>(sRGBAColor);
+ color = convertColor<SRGBA<uint8_t>>(sRGBAColor);
return true;
}
@@ -136,7 +136,7 @@
return false;
}
- color = convertTo<SRGBA<uint8_t>>(sRGBAColor);
+ color = convertColor<SRGBA<uint8_t>>(sRGBAColor);
return true;
}
Modified: trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -26,7 +26,7 @@
namespace WebCore {
Color::Color(const GdkRGBA& color)
- : Color(convertTo<SRGBA<uint8_t>>(SRGBA { static_cast<float>(color.red), static_cast<float>(color.green), static_cast<float>(color.blue), static_cast<float>(color.alpha) }))
+ : Color(convertColor<SRGBA<uint8_t>>(SRGBA { static_cast<float>(color.red), static_cast<float>(color.green), static_cast<float>(color.blue), static_cast<float>(color.alpha) }))
{
}
Modified: trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm 2021-02-07 19:22:59 UTC (rev 272474)
@@ -98,7 +98,7 @@
[rgbColor getRed:&redComponent green:&greenComponent blue:&blueComponent alpha:&alpha];
END_BLOCK_OBJC_EXCEPTIONS
- return convertTo<SRGBA<uint8_t>>(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) });
+ return convertColor<SRGBA<uint8_t>>(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) });
}
Color colorFromNSColor(NSColor *color)
Modified: trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-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
@@ -34,7 +34,7 @@
namespace WebCore {
Color::Color(D2D1_COLOR_F color)
- : Color(convertTo<SRGBA<uint8_t>>(SRGBA { color.r, color.g, color.b, color.a }))
+ : Color(convertColor<SRGBA<uint8_t>>(SRGBA { color.r, color.g, color.b, color.a }))
{
}
Modified: trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.cpp (272473 => 272474)
--- trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-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
@@ -132,7 +132,7 @@
COMPtr<ID2D1SolidColorBrush> PlatformContextDirect2D::brushWithColor(const D2D1_COLOR_F& color)
{
- auto colorKey = convertTo<SRGBA<uint8_t>>(SRGBA { color.r, color.g, color.b, color.a });
+ auto colorKey = colorConvert<SRGBA<uint8_t>>(SRGBA { color.r, color.g, color.b, color.a });
if (!colorKey) {
if (!m_zeroBrush)
Modified: trunk/Source/WebCore/platform/ios/ColorIOS.mm (272473 => 272474)
--- trunk/Source/WebCore/platform/ios/ColorIOS.mm 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebCore/platform/ios/ColorIOS.mm 2021-02-07 19:22:59 UTC (rev 272474)
@@ -47,7 +47,7 @@
[color getRed:&redComponent green:&greenComponent blue:&blueComponent alpha:&alpha];
- return convertTo<SRGBA<uint8_t>>(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) });
+ return convertColor<SRGBA<uint8_t>>(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) });
}
} // namespace WebCore
Modified: trunk/Source/WebKit/ChangeLog (272473 => 272474)
--- trunk/Source/WebKit/ChangeLog 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebKit/ChangeLog 2021-02-07 19:22:59 UTC (rev 272474)
@@ -1,3 +1,14 @@
+2021-02-07 Sam Weinig <[email protected]>
+
+ Remove more special cases from color conversion
+ https://bugs.webkit.org/show_bug.cgi?id=221519
+
+ Reviewed by Antti Koivisto.
+
+ * UIProcess/API/wpe/WebKitColor.cpp:
+ (webkitColorToWebCoreColor):
+ Replace convertTo<> component type conversion to general convertColor<>.
+
2021-02-06 Wenson Hsieh <[email protected]>
[macOS] Add support for accessibility image extraction
Modified: trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp (272473 => 272474)
--- trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -75,7 +75,7 @@
const WebCore::Color webkitColorToWebCoreColor(WebKitColor* color)
{
- return WebCore::convertTo<WebCore::SRGBA<uint8_t>>(WebCore::SRGBA { static_cast<float>(color->red), static_cast<float>(color->green), static_cast<float>(color->blue), static_cast<float>(color->alpha) });
+ return WebCore::convertColor<WebCore::SRGBA<uint8_t>>(WebCore::SRGBA { static_cast<float>(color->red), static_cast<float>(color->green), static_cast<float>(color->blue), static_cast<float>(color->alpha) });
}
void webkitColorFillFromWebCoreColor(const WebCore::Color& webCoreColor, WebKitColor* color)
Modified: trunk/Tools/ChangeLog (272473 => 272474)
--- trunk/Tools/ChangeLog 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Tools/ChangeLog 2021-02-07 19:22:59 UTC (rev 272474)
@@ -1,3 +1,14 @@
+2021-02-07 Sam Weinig <[email protected]>
+
+ Remove more special cases from color conversion
+ https://bugs.webkit.org/show_bug.cgi?id=221519
+
+ Reviewed by Antti Koivisto.
+
+ * TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp:
+ (TestWebKitAPI::TEST):
+ Replace convertTo<> component type conversion to general convertColor<>.
+
2021-02-06 Alex Christensen <[email protected]>
Non-special URLs should have an opaque origin
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp (272473 => 272474)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp 2021-02-07 19:22:59 UTC (rev 272474)
@@ -109,7 +109,7 @@
}
auto componentBytes = SRGBA<uint8_t> { 255, 128, 63, 127 };
- Color rgb1 { convertTo<SRGBA<float>>(componentBytes) };
+ Color rgb1 { convertColor<SRGBA<float>>(componentBytes) };
Color rgb2 { componentBytes };
EXPECT_NE(rgb1, rgb2);
EXPECT_NE(rgb2, rgb1);
@@ -138,7 +138,7 @@
}
auto componentBytes = SRGBA<uint8_t> { 255, 128, 63, 127 };
- Color rgb1 { convertTo<SRGBA<float>>(componentBytes) };
+ Color rgb1 { convertColor<SRGBA<float>>(componentBytes) };
Color rgb2 { componentBytes };
EXPECT_NE(rgb1.hash(), rgb2.hash());
}
Modified: trunk/Tools/lldb/lldb_webkit.py (272473 => 272474)
--- trunk/Tools/lldb/lldb_webkit.py 2021-02-07 19:03:41 UTC (rev 272473)
+++ trunk/Tools/lldb/lldb_webkit.py 2021-02-07 19:22:59 UTC (rev 272474)
@@ -467,12 +467,22 @@
def _to_string_extended(self):
extended_color = self.valobj.GetChildMemberWithName('m_colorData').GetChildMemberWithName('extendedColor').Dereference()
profile = ""
- if profile == 'SRGB':
- profile = ''
- elif profile == 'LinearRGB':
- profile = ''
+ if profile == 'A98RGB':
+ profile = ''
elif profile == 'DisplayP3':
profile = ''
+ elif profile == 'Lab':
+ profile = ''
+ elif profile == 'LinearSRGB':
+ profile = ''
+ elif profile == 'ProPhotoRGB':
+ profile = ''
+ elif profile == 'Rec2020':
+ profile = ''
+ elif profile == 'SRGB':
+ profile = ''
+ elif profile == 'XYZ_D50':
+ profile = ''
else:
profile = ''