Diff
Modified: trunk/Source/WTF/ChangeLog (287480 => 287481)
--- trunk/Source/WTF/ChangeLog 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WTF/ChangeLog 2021-12-29 20:20:09 UTC (rev 287481)
@@ -1,3 +1,13 @@
+2021-12-29 Sam Weinig <wei...@apple.com>
+
+ Add additional named color spaces for extended rgb color types and HSL/HWB in preparation for out of gamut and missing component support
+ https://bugs.webkit.org/show_bug.cgi?id=234741
+
+ Reviewed by Dean Jackson.
+
+ * wtf/PlatformHave.h:
+ Add new HAVE macros for additional CoreGraphics named color spaces and the CGColorSpaceCreateExtended function.
+
2021-12-28 Sam Weinig <wei...@apple.com>
Support color interpolation methods for CSS Gradients
Modified: trunk/Source/WTF/wtf/PlatformHave.h (287480 => 287481)
--- trunk/Source/WTF/wtf/PlatformHave.h 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WTF/wtf/PlatformHave.h 2021-12-29 20:20:09 UTC (rev 287481)
@@ -885,9 +885,22 @@
#define HAVE_PUIC_BUTTON_TYPE_PILL 1
#endif
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000 \
+ || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) \
+ || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 70000) \
+ || (PLATFORM(APPLETV) && __TV_OS_VERSION_MIN_REQUIRED >= 140000) \
+ || (PLATFORM(MACCATALYST) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000))
+#define HAVE_CORE_GRAPHICS_CREATE_EXTENDED_COLOR_SPACE 1
+#define HAVE_CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE 1
+#define HAVE_CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE 1
+#define HAVE_CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE 1
+#define HAVE_CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE 1
+#endif
+
#if PLATFORM(COCOA)
#define HAVE_CORE_GRAPHICS_ADOBE_RGB_1998_COLOR_SPACE 1
#define HAVE_CORE_GRAPHICS_DISPLAY_P3_COLOR_SPACE 1
+#define HAVE_CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE 1
#define HAVE_CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE 1
#define HAVE_CORE_GRAPHICS_ITUR_2020_COLOR_SPACE 1
#define HAVE_CORE_GRAPHICS_LINEAR_SRGB_COLOR_SPACE 1
Modified: trunk/Source/WebCore/ChangeLog (287480 => 287481)
--- trunk/Source/WebCore/ChangeLog 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/ChangeLog 2021-12-29 20:20:09 UTC (rev 287481)
@@ -1,3 +1,53 @@
+2021-12-29 Sam Weinig <wei...@apple.com>
+
+ Add additional named color spaces for extended rgb color types and HSL/HWB in preparation for out of gamut and missing component support
+ https://bugs.webkit.org/show_bug.cgi?id=234741
+
+ Reviewed by Dean Jackson.
+
+ Adds named color space support, which provides the ability for a color type to live
+ in a Color, for the following color spaces:
+
+ ExtendedA98RGB
+ ExtendedDisplayP3
+ ExtendedLinearSRGB
+ ExtendedProPhotoRGB
+ ExtendedRec2020
+ ExtendedSRGB
+ HSL
+ HWB
+
+ This is going to be needed to add support for out of gamut color() function support
+ and support for the new missing component syntax.
+
+ The extended variants serialize identically to their bounded counterparts, HSL/HWB
+ serialize as they do today, by converting to 8-bit sRGB and serializing as it.
+
+ * platform/graphics/ColorConversion.cpp:
+ (WebCore::convertColorComponents):
+ * platform/graphics/ColorSerialization.cpp:
+ (WebCore::serialization):
+ (WebCore::serializationForRenderTreeAsText):
+ (WebCore::serializationForCSS):
+ (WebCore::serializationForHTML):
+ * platform/graphics/ColorSpace.cpp:
+ (WebCore::operator<<):
+ * platform/graphics/ColorSpace.h:
+ (WebCore::callWithColorType):
+ * platform/graphics/ColorTypes.h:
+ * platform/graphics/ColorUtilities.h:
+ * platform/graphics/cg/ColorSpaceCG.cpp:
+ (WebCore::extendedNamedColorSpace):
+ (WebCore::extendedAdobeRGB1998ColorSpaceRef):
+ (WebCore::extendedDisplayP3ColorSpaceRef):
+ (WebCore::extendedITUR_2020ColorSpaceRef):
+ (WebCore::extendedLinearSRGBColorSpaceRef):
+ (WebCore::extendedROMMRGBColorSpaceRef):
+ (WebCore::colorSpaceForCGColorSpace):
+ (WebCore::labColorSpaceRef): Deleted.
+ * platform/graphics/cg/ColorSpaceCG.h:
+ (WebCore::cachedNullableCGColorSpace):
+
2021-12-29 Commit Queue <commit-qu...@webkit.org>
Unreviewed, reverting r287478.
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.cpp (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-12-29 20:20:09 UTC (rev 287481)
@@ -379,6 +379,22 @@
return asColorComponents(convertColor<A98RGB<float>>(inputColor));
case ColorSpace::DisplayP3:
return asColorComponents(convertColor<DisplayP3<float>>(inputColor));
+ case ColorSpace::ExtendedA98RGB:
+ return asColorComponents(convertColor<ExtendedA98RGB<float>>(inputColor));
+ case ColorSpace::ExtendedDisplayP3:
+ return asColorComponents(convertColor<ExtendedDisplayP3<float>>(inputColor));
+ case ColorSpace::ExtendedLinearSRGB:
+ return asColorComponents(convertColor<ExtendedLinearSRGBA<float>>(inputColor));
+ case ColorSpace::ExtendedProPhotoRGB:
+ return asColorComponents(convertColor<ExtendedProPhotoRGB<float>>(inputColor));
+ case ColorSpace::ExtendedRec2020:
+ return asColorComponents(convertColor<ExtendedRec2020<float>>(inputColor));
+ case ColorSpace::ExtendedSRGB:
+ return asColorComponents(convertColor<ExtendedSRGBA<float>>(inputColor));
+ case ColorSpace::HSL:
+ return asColorComponents(convertColor<HSLA<float>>(inputColor));
+ case ColorSpace::HWB:
+ return asColorComponents(convertColor<HWBA<float>>(inputColor));
case ColorSpace::LCH:
return asColorComponents(convertColor<LCHA<float>>(inputColor));
case ColorSpace::Lab:
Modified: trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp 2021-12-29 20:20:09 UTC (rev 287481)
@@ -43,6 +43,38 @@
static String serializationForHTML(const DisplayP3<float>&, bool useColorFunctionSerialization);
static String serializationForRenderTreeAsText(const DisplayP3<float>&, bool useColorFunctionSerialization);
+static String serializationForCSS(const ExtendedA98RGB<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const ExtendedA98RGB<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const ExtendedA98RGB<float>&, bool useColorFunctionSerialization);
+
+static String serializationForCSS(const ExtendedDisplayP3<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const ExtendedDisplayP3<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const ExtendedDisplayP3<float>&, bool useColorFunctionSerialization);
+
+static String serializationForCSS(const ExtendedLinearSRGBA<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const ExtendedLinearSRGBA<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const ExtendedLinearSRGBA<float>&, bool useColorFunctionSerialization);
+
+static String serializationForCSS(const ExtendedProPhotoRGB<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const ExtendedProPhotoRGB<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const ExtendedProPhotoRGB<float>&, bool useColorFunctionSerialization);
+
+static String serializationForCSS(const ExtendedRec2020<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const ExtendedRec2020<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const ExtendedRec2020<float>&, bool useColorFunctionSerialization);
+
+static String serializationForCSS(const ExtendedSRGBA<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const ExtendedSRGBA<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const ExtendedSRGBA<float>&, bool useColorFunctionSerialization);
+
+static String serializationForCSS(const HSLA<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const HSLA<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const HSLA<float>&, bool useColorFunctionSerialization);
+
+static String serializationForCSS(const HWBA<float>&, bool useColorFunctionSerialization);
+static String serializationForHTML(const HWBA<float>&, bool useColorFunctionSerialization);
+static String serializationForRenderTreeAsText(const HWBA<float>&, bool useColorFunctionSerialization);
+
static String serializationForCSS(const LCHA<float>&, bool useColorFunctionSerialization);
static String serializationForHTML(const LCHA<float>&, bool useColorFunctionSerialization);
static String serializationForRenderTreeAsText(const LCHA<float>&, bool useColorFunctionSerialization);
@@ -113,14 +145,21 @@
{
switch (colorSpace) {
case ColorSpace::A98RGB:
+ case ColorSpace::ExtendedA98RGB:
return "a98-rgb"_s;
case ColorSpace::DisplayP3:
+ case ColorSpace::ExtendedDisplayP3:
return "display-p3"_s;
+ case ColorSpace::HSL:
+ return "hsl"_s;
+ case ColorSpace::HWB:
+ return "hwb"_s;
case ColorSpace::LCH:
return "lch"_s;
case ColorSpace::Lab:
return "lab"_s;
case ColorSpace::LinearSRGB:
+ case ColorSpace::ExtendedLinearSRGB:
return "srgb-linear"_s;
case ColorSpace::OKLCH:
return "oklch"_s;
@@ -127,10 +166,13 @@
case ColorSpace::OKLab:
return "oklab"_s;
case ColorSpace::ProPhotoRGB:
+ case ColorSpace::ExtendedProPhotoRGB:
return "prophoto-rgb"_s;
case ColorSpace::Rec2020:
+ case ColorSpace::ExtendedRec2020:
return "rec2020"_s;
case ColorSpace::SRGB:
+ case ColorSpace::ExtendedSRGB:
return "srgb"_s;
case ColorSpace::XYZ_D50:
return "xyz-d50"_s;
@@ -191,6 +233,142 @@
return serializationUsingColorFunction(color);
}
+// MARK: ExtendedA98RGB<float> overloads
+
+String serializationForCSS(const ExtendedA98RGB<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForHTML(const ExtendedA98RGB<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForRenderTreeAsText(const ExtendedA98RGB<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+// MARK: ExtendedDisplayP3<float> overloads
+
+String serializationForCSS(const ExtendedDisplayP3<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForHTML(const ExtendedDisplayP3<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForRenderTreeAsText(const ExtendedDisplayP3<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+// MARK: ExtendedLinearSRGBA<float> overloads
+
+String serializationForCSS(const ExtendedLinearSRGBA<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForHTML(const ExtendedLinearSRGBA<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForRenderTreeAsText(const ExtendedLinearSRGBA<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+// MARK: ExtendedProPhotoRGB<float> overloads
+
+String serializationForCSS(const ExtendedProPhotoRGB<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForHTML(const ExtendedProPhotoRGB<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForRenderTreeAsText(const ExtendedProPhotoRGB<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+// MARK: ExtendedRec2020<float> overloads
+
+String serializationForCSS(const ExtendedRec2020<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForHTML(const ExtendedRec2020<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForRenderTreeAsText(const ExtendedRec2020<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+// MARK: ExtendedSRGBA<float> overloads
+
+String serializationForCSS(const ExtendedSRGBA<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForHTML(const ExtendedSRGBA<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+String serializationForRenderTreeAsText(const ExtendedSRGBA<float>& color, bool)
+{
+ return serializationUsingColorFunction(color);
+}
+
+// MARK: HSLA<float> overloads
+
+String serializationForCSS(const HSLA<float>& color, bool useColorFunctionSerialization)
+{
+ return serializationForCSS(convertColor<SRGBA<uint8_t>>(color), useColorFunctionSerialization);
+}
+
+String serializationForHTML(const HSLA<float>& color, bool useColorFunctionSerialization)
+{
+ return serializationForHTML(convertColor<SRGBA<uint8_t>>(color), useColorFunctionSerialization);
+}
+
+String serializationForRenderTreeAsText(const HSLA<float>& color, bool useColorFunctionSerialization)
+{
+ return serializationForRenderTreeAsText(convertColor<SRGBA<uint8_t>>(color), useColorFunctionSerialization);
+}
+
+// MARK: HWBA<float> overloads
+
+String serializationForCSS(const HWBA<float>& color, bool useColorFunctionSerialization)
+{
+ return serializationForCSS(convertColor<SRGBA<uint8_t>>(color), useColorFunctionSerialization);
+}
+
+String serializationForHTML(const HWBA<float>& color, bool useColorFunctionSerialization)
+{
+ return serializationForHTML(convertColor<SRGBA<uint8_t>>(color), useColorFunctionSerialization);
+}
+
+String serializationForRenderTreeAsText(const HWBA<float>& color, bool useColorFunctionSerialization)
+{
+ return serializationForRenderTreeAsText(convertColor<SRGBA<uint8_t>>(color), useColorFunctionSerialization);
+}
+
// MARK: LCHA<float> overloads
String serializationForCSS(const LCHA<float>& color, bool)
Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.cpp (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.cpp 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.cpp 2021-12-29 20:20:09 UTC (rev 287481)
@@ -39,6 +39,30 @@
case ColorSpace::DisplayP3:
ts << "DisplayP3";
break;
+ case ColorSpace::ExtendedA98RGB:
+ ts << "Extended A98-RGB";
+ break;
+ case ColorSpace::ExtendedDisplayP3:
+ ts << "Extended DisplayP3";
+ break;
+ case ColorSpace::ExtendedLinearSRGB:
+ ts << "Extended Linear sRGB";
+ break;
+ case ColorSpace::ExtendedProPhotoRGB:
+ ts << "Extended ProPhotoRGB";
+ break;
+ case ColorSpace::ExtendedRec2020:
+ ts << "Extended Rec2020";
+ break;
+ case ColorSpace::ExtendedSRGB:
+ ts << "Extended sRGB";
+ break;
+ case ColorSpace::HSL:
+ ts << "HSL";
+ break;
+ case ColorSpace::HWB:
+ ts << "HWB";
+ break;
case ColorSpace::LCH:
ts << "LCH";
break;
@@ -46,7 +70,7 @@
ts << "Lab";
break;
case ColorSpace::LinearSRGB:
- ts << "LinearSRGB";
+ ts << "Linear sRGB";
break;
case ColorSpace::OKLCH:
ts << "OKLCH";
Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.h (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.h 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.h 2021-12-29 20:20:09 UTC (rev 287481)
@@ -35,6 +35,14 @@
enum class ColorSpace : uint8_t {
A98RGB,
DisplayP3,
+ ExtendedA98RGB,
+ ExtendedDisplayP3,
+ ExtendedLinearSRGB,
+ ExtendedProPhotoRGB,
+ ExtendedRec2020,
+ ExtendedSRGB,
+ HSL,
+ HWB,
LCH,
Lab,
LinearSRGB,
@@ -53,6 +61,14 @@
template<typename> struct ColorSpaceMapping;
template<typename T> struct ColorSpaceMapping<A98RGB<T>> { static constexpr auto colorSpace { ColorSpace::A98RGB }; };
template<typename T> struct ColorSpaceMapping<DisplayP3<T>> { static constexpr auto colorSpace { ColorSpace::DisplayP3 }; };
+template<typename T> struct ColorSpaceMapping<ExtendedA98RGB<T>> { static constexpr auto colorSpace { ColorSpace::ExtendedA98RGB }; };
+template<typename T> struct ColorSpaceMapping<ExtendedDisplayP3<T>> { static constexpr auto colorSpace { ColorSpace::ExtendedDisplayP3 }; };
+template<typename T> struct ColorSpaceMapping<ExtendedLinearSRGBA<T>> { static constexpr auto colorSpace { ColorSpace::ExtendedLinearSRGB }; };
+template<typename T> struct ColorSpaceMapping<ExtendedProPhotoRGB<T>> { static constexpr auto colorSpace { ColorSpace::ExtendedProPhotoRGB }; };
+template<typename T> struct ColorSpaceMapping<ExtendedRec2020<T>> { static constexpr auto colorSpace { ColorSpace::ExtendedRec2020 }; };
+template<typename T> struct ColorSpaceMapping<ExtendedSRGBA<T>> { static constexpr auto colorSpace { ColorSpace::ExtendedSRGB }; };
+template<typename T> struct ColorSpaceMapping<HSLA<T>> { static constexpr auto colorSpace { ColorSpace::HSL }; };
+template<typename T> struct ColorSpaceMapping<HWBA<T>> { static constexpr auto colorSpace { ColorSpace::HWB }; };
template<typename T> struct ColorSpaceMapping<LCHA<T>> { static constexpr auto colorSpace { ColorSpace::LCH }; };
template<typename T> struct ColorSpaceMapping<Lab<T>> { static constexpr auto colorSpace { ColorSpace::Lab }; };
template<typename T> struct ColorSpaceMapping<LinearSRGBA<T>> { static constexpr auto colorSpace { ColorSpace::LinearSRGB }; };
@@ -74,6 +90,22 @@
return std::invoke(std::forward<Functor>(functor), makeFromComponents<A98RGB<T>>(components));
case ColorSpace::DisplayP3:
return std::invoke(std::forward<Functor>(functor), makeFromComponents<DisplayP3<T>>(components));
+ case ColorSpace::ExtendedA98RGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<ExtendedA98RGB<T>>(components));
+ case ColorSpace::ExtendedDisplayP3:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<ExtendedDisplayP3<T>>(components));
+ case ColorSpace::ExtendedLinearSRGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<ExtendedLinearSRGBA<T>>(components));
+ case ColorSpace::ExtendedProPhotoRGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<ExtendedProPhotoRGB<T>>(components));
+ case ColorSpace::ExtendedRec2020:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<ExtendedRec2020<T>>(components));
+ case ColorSpace::ExtendedSRGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<ExtendedSRGBA<T>>(components));
+ case ColorSpace::HSL:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<HSLA<T>>(components));
+ case ColorSpace::HWB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<HWBA<T>>(components));
case ColorSpace::LCH:
return std::invoke(std::forward<Functor>(functor), makeFromComponents<LCHA<T>>(components));
case ColorSpace::Lab:
@@ -110,6 +142,14 @@
WebCore::ColorSpace,
WebCore::ColorSpace::A98RGB,
WebCore::ColorSpace::DisplayP3,
+ WebCore::ColorSpace::ExtendedA98RGB,
+ WebCore::ColorSpace::ExtendedDisplayP3,
+ WebCore::ColorSpace::ExtendedLinearSRGB,
+ WebCore::ColorSpace::ExtendedProPhotoRGB,
+ WebCore::ColorSpace::ExtendedRec2020,
+ WebCore::ColorSpace::ExtendedSRGB,
+ WebCore::ColorSpace::HSL,
+ WebCore::ColorSpace::HWB,
WebCore::ColorSpace::LCH,
WebCore::ColorSpace::Lab,
WebCore::ColorSpace::LinearSRGB,
Modified: trunk/Source/WebCore/platform/graphics/ColorTypes.h (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/ColorTypes.h 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/ColorTypes.h 2021-12-29 20:20:09 UTC (rev 287481)
@@ -317,7 +317,7 @@
template<typename T> using SRGBA = BoundedGammaEncoded<T, SRGBADescriptor>;
template<typename T> using LinearSRGBA = BoundedLinearEncoded<T, SRGBADescriptor>;
template<typename T> using ExtendedSRGBA = ExtendedGammaEncoded<T, SRGBADescriptor>;
-template<typename T> using LinearExtendedSRGBA = ExtendedLinearEncoded<T, SRGBADescriptor>;
+template<typename T> using ExtendedLinearSRGBA = ExtendedLinearEncoded<T, SRGBADescriptor>;
struct A98RGBDescriptor {
@@ -339,6 +339,8 @@
template<typename T> using A98RGB = BoundedGammaEncoded<T, A98RGBDescriptor>;
template<typename T> using LinearA98RGB = BoundedLinearEncoded<T, A98RGBDescriptor>;
+template<typename T> using ExtendedA98RGB = ExtendedGammaEncoded<T, A98RGBDescriptor>;
+template<typename T> using ExtendedLinearA98RGB = ExtendedLinearEncoded<T, A98RGBDescriptor>;
struct DisplayP3Descriptor {
@@ -360,6 +362,8 @@
template<typename T> using DisplayP3 = BoundedGammaEncoded<T, DisplayP3Descriptor>;
template<typename T> using LinearDisplayP3 = BoundedLinearEncoded<T, DisplayP3Descriptor>;
+template<typename T> using ExtendedDisplayP3 = ExtendedGammaEncoded<T, DisplayP3Descriptor>;
+template<typename T> using ExtendedLinearDisplayP3 = ExtendedLinearEncoded<T, DisplayP3Descriptor>;
struct ProPhotoRGBDescriptor {
@@ -381,6 +385,8 @@
template<typename T> using ProPhotoRGB = BoundedGammaEncoded<T, ProPhotoRGBDescriptor>;
template<typename T> using LinearProPhotoRGB = BoundedLinearEncoded<T, ProPhotoRGBDescriptor>;
+template<typename T> using ExtendedProPhotoRGB = ExtendedGammaEncoded<T, ProPhotoRGBDescriptor>;
+template<typename T> using ExtendedLinearProPhotoRGB = ExtendedLinearEncoded<T, ProPhotoRGBDescriptor>;
struct Rec2020Descriptor {
@@ -402,6 +408,8 @@
template<typename T> using Rec2020 = BoundedGammaEncoded<T, Rec2020Descriptor>;
template<typename T> using LinearRec2020 = BoundedLinearEncoded<T, Rec2020Descriptor>;
+template<typename T> using ExtendedRec2020 = ExtendedGammaEncoded<T, Rec2020Descriptor>;
+template<typename T> using ExtendedLinearRec2020 = ExtendedLinearEncoded<T, Rec2020Descriptor>;
// MARK: - Lab Color Type.
Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2021-12-29 20:20:09 UTC (rev 287481)
@@ -54,12 +54,14 @@
template<typename ColorType> constexpr ColorType invertedColorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha);
template<typename ColorType> ColorType invertedColorWithOverriddenAlpha(const ColorType&, float overrideAlpha);
-template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType>>* = nullptr> constexpr bool isBlack(const ColorType&);
-template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType>>* = nullptr> constexpr bool isBlack(const ColorType&);
+template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType> || UsesHSLModel<ColorType>>* = nullptr> constexpr bool isBlack(const ColorType&);
+template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType> || UsesExtendedRGBModel<ColorType>>* = nullptr> constexpr bool isBlack(const ColorType&);
+template<typename ColorType, typename std::enable_if_t<UsesHWBModel<ColorType>>* = nullptr> constexpr bool isBlack(const ColorType&);
template<WhitePoint W> constexpr bool isBlack(const XYZA<float, W>&);
-template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType>>* = nullptr> constexpr bool isWhite(const ColorType&);
-template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType>>* = nullptr> constexpr bool isWhite(const ColorType&);
+template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType> || UsesHSLModel<ColorType>>* = nullptr> constexpr bool isWhite(const ColorType&);
+template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType> || UsesExtendedRGBModel<ColorType>>* = nullptr> constexpr bool isWhite(const ColorType&);
+template<typename ColorType, typename std::enable_if_t<UsesHWBModel<ColorType>>* = nullptr> constexpr bool isWhite(const ColorType&);
template<WhitePoint W> constexpr bool isWhite(const XYZA<float, W>&);
constexpr uint16_t fastMultiplyBy255(uint16_t);
@@ -148,13 +150,13 @@
return color.y == 0 && color.alpha == AlphaTraits<float>::opaque;
}
-template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType>>*>
+template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType> || UsesHSLModel<ColorType>>*>
constexpr bool isBlack(const ColorType& color)
{
return color.lightness == 0 && color.alpha == AlphaTraits<float>::opaque;
}
-template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType>>*>
+template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType>|| UsesExtendedRGBModel<ColorType>>*>
constexpr bool isBlack(const ColorType& color)
{
auto [c1, c2, c3, alpha] = color;
@@ -162,18 +164,24 @@
return c1 == componentInfo[0].min && c2 == componentInfo[1].min && c3 == componentInfo[2].min && alpha == AlphaTraits<typename ColorType::ComponentType>::opaque;
}
+template<typename ColorType, typename std::enable_if_t<UsesHWBModel<ColorType>>*>
+constexpr bool isBlack(const ColorType& color)
+{
+ return color.blackness == 100 && color.alpha == AlphaTraits<float>::opaque;
+}
+
template<WhitePoint W> constexpr bool isWhite(const XYZA<float, W>& color)
{
return color.y == 1 && color.alpha == AlphaTraits<float>::opaque;
}
-template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType>>*>
+template<typename ColorType, typename std::enable_if_t<UsesLabModel<ColorType> || UsesLCHModel<ColorType> || UsesHSLModel<ColorType>>*>
constexpr bool isWhite(const ColorType& color)
{
return color.lightness == 100 && color.alpha == AlphaTraits<float>::opaque;
}
-template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType>>*>
+template<typename ColorType, typename std::enable_if_t<UsesRGBModel<ColorType> || UsesExtendedRGBModel<ColorType>>*>
constexpr bool isWhite(const ColorType& color)
{
auto [c1, c2, c3, alpha] = color;
@@ -181,6 +189,12 @@
return c1 == componentInfo[0].max && c2 == componentInfo[1].max && c3 == componentInfo[2].max && alpha == AlphaTraits<typename ColorType::ComponentType>::opaque;
}
+template<typename ColorType, typename std::enable_if_t<UsesHWBModel<ColorType>>*>
+constexpr bool isWhite(const ColorType& color)
+{
+ return color.whiteness == 100 && color.alpha == AlphaTraits<float>::opaque;
+}
+
constexpr uint16_t fastMultiplyBy255(uint16_t value)
{
return (value << 8) - value;
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp 2021-12-29 20:20:09 UTC (rev 287481)
@@ -46,6 +46,19 @@
return colorSpace.get().get();
}
+#if HAVE(CORE_GRAPHICS_CREATE_EXTENDED_COLOR_SPACE)
+template<const CFStringRef& colorSpaceNameGlobalConstant> static CGColorSpaceRef extendedNamedColorSpace()
+{
+ static NeverDestroyed<RetainPtr<CGColorSpaceRef>> colorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+ colorSpace.get() = adoptCF(CGColorSpaceCreateExtended(namedColorSpace<colorSpaceNameGlobalConstant>()));
+ ASSERT(colorSpace.get());
+ });
+ return colorSpace.get().get();
+}
+#endif
+
CGColorSpaceRef sRGBColorSpaceRef()
{
return namedColorSpace<kCGColorSpaceSRGB>();
@@ -65,6 +78,41 @@
}
#endif
+#if HAVE(CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE)
+CGColorSpaceRef extendedAdobeRGB1998ColorSpaceRef()
+{
+ return extendedNamedColorSpace<kCGColorSpaceAdobeRGB1998>();
+}
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE)
+CGColorSpaceRef extendedDisplayP3ColorSpaceRef()
+{
+ return namedColorSpace<kCGColorSpaceExtendedDisplayP3>();
+}
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE)
+CGColorSpaceRef extendedITUR_2020ColorSpaceRef()
+{
+ return namedColorSpace<kCGColorSpaceExtendedITUR_2020>();
+}
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE)
+CGColorSpaceRef extendedLinearSRGBColorSpaceRef()
+{
+ return namedColorSpace<kCGColorSpaceExtendedLinearSRGB>();
+}
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE)
+CGColorSpaceRef extendedROMMRGBColorSpaceRef()
+{
+ return extendedNamedColorSpace<kCGColorSpaceROMMRGB>();
+}
+#endif
+
#if HAVE(CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE)
CGColorSpaceRef extendedSRGBColorSpaceRef()
{
@@ -79,14 +127,6 @@
}
#endif
-#if HAVE(CORE_GRAPHICS_LAB_COLOR_SPACE)
-CGColorSpaceRef labColorSpaceRef()
-{
- // FIXME: Add support for conversion to Lab on supported platforms.
- return nullptr;
-}
-#endif
-
#if HAVE(CORE_GRAPHICS_LINEAR_SRGB_COLOR_SPACE)
CGColorSpaceRef linearSRGBColorSpaceRef()
{
@@ -107,18 +147,22 @@
return namedColorSpace<kCGColorSpaceGenericXYZ>();
}
-// FIXME: Figure out how to create a CoreGraphics XYZ-D65 color space and add a xyzD65ColorSpaceRef().
+// FIXME: Figure out how to create a CoreGraphics XYZ-D65 color space and add a xyzD65ColorSpaceRef(). Perhaps CGColorSpaceCreateCalibratedRGB() with identify black point, D65 white point, and identity matrix.
#endif
std::optional<ColorSpace> colorSpaceForCGColorSpace(CGColorSpaceRef colorSpace)
{
+ // First test for the four most common spaces, sRGB, Extended sRGB, DisplayP3 and Linear sRGB, and then test
+ // the reset in alphabetical order.
+ // FIXME: Consider using a HashMap (with CFHash based keys) rather than the linear set of tests.
+
if (CGColorSpaceEqualToColorSpace(colorSpace, sRGBColorSpaceRef()))
return ColorSpace::SRGB;
-#if HAVE(CORE_GRAPHICS_ADOBE_RGB_1998_COLOR_SPACE)
- if (CGColorSpaceEqualToColorSpace(colorSpace, adobeRGB1998ColorSpaceRef()))
- return ColorSpace::A98RGB;
+#if HAVE(CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, extendedSRGBColorSpaceRef()))
+ return ColorSpace::ExtendedSRGB;
#endif
#if HAVE(CORE_GRAPHICS_DISPLAY_P3_COLOR_SPACE)
@@ -131,22 +175,53 @@
return ColorSpace::LinearSRGB;
#endif
-#if HAVE(CORE_GRAPHICS_ROMMRGB_COLOR_SPACE)
- if (CGColorSpaceEqualToColorSpace(colorSpace, ROMMRGBColorSpaceRef()))
- return ColorSpace::ProPhotoRGB;
+
+#if HAVE(CORE_GRAPHICS_ADOBE_RGB_1998_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, adobeRGB1998ColorSpaceRef()))
+ return ColorSpace::A98RGB;
#endif
+#if HAVE(CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, extendedAdobeRGB1998ColorSpaceRef()))
+ return ColorSpace::ExtendedA98RGB;
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, extendedDisplayP3ColorSpaceRef()))
+ return ColorSpace::ExtendedDisplayP3;
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, extendedLinearSRGBColorSpaceRef()))
+ return ColorSpace::ExtendedLinearSRGB;
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, extendedITUR_2020ColorSpaceRef()))
+ return ColorSpace::ExtendedRec2020;
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, extendedROMMRGBColorSpaceRef()))
+ return ColorSpace::ExtendedProPhotoRGB;
+#endif
+
#if HAVE(CORE_GRAPHICS_ITUR_2020_COLOR_SPACE)
if (CGColorSpaceEqualToColorSpace(colorSpace, ITUR_2020ColorSpaceRef()))
return ColorSpace::Rec2020;
#endif
+#if HAVE(CORE_GRAPHICS_ROMMRGB_COLOR_SPACE)
+ if (CGColorSpaceEqualToColorSpace(colorSpace, ROMMRGBColorSpaceRef()))
+ return ColorSpace::ProPhotoRGB;
+#endif
+
#if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE)
if (CGColorSpaceEqualToColorSpace(colorSpace, xyzD50ColorSpaceRef()))
return ColorSpace::XYZ_D50;
#endif
- // FIXME: Add support for ColorSpace::Lab ColorSpace::XYZ_D65 to support more direct conversions.
+ // FIXME: Add support for remaining color spaces to support more direct conversions.
return std::nullopt;
}
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h (287480 => 287481)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h 2021-12-29 17:47:05 UTC (rev 287480)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h 2021-12-29 20:20:09 UTC (rev 287481)
@@ -44,6 +44,26 @@
WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef();
#endif
+#if HAVE(CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE)
+WEBCORE_EXPORT CGColorSpaceRef extendedAdobeRGB1998ColorSpaceRef();
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE)
+WEBCORE_EXPORT CGColorSpaceRef extendedDisplayP3ColorSpaceRef();
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE)
+WEBCORE_EXPORT CGColorSpaceRef extendedITUR_2020ColorSpaceRef();
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE)
+WEBCORE_EXPORT CGColorSpaceRef extendedLinearSRGBColorSpaceRef();
+#endif
+
+#if HAVE(CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE)
+WEBCORE_EXPORT CGColorSpaceRef extendedROMMRGBColorSpaceRef();
+#endif
+
#if HAVE(CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE)
WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
#endif
@@ -52,10 +72,6 @@
WEBCORE_EXPORT CGColorSpaceRef ITUR_2020ColorSpaceRef();
#endif
-#if HAVE(CORE_GRAPHICS_LAB_COLOR_SPACE)
-WEBCORE_EXPORT CGColorSpaceRef labColorSpaceRef();
-#endif
-
#if HAVE(CORE_GRAPHICS_LINEAR_SRGB_COLOR_SPACE)
WEBCORE_EXPORT CGColorSpaceRef linearSRGBColorSpaceRef();
#endif
@@ -73,6 +89,9 @@
static inline CGColorSpaceRef cachedNullableCGColorSpace(ColorSpace colorSpace)
{
switch (colorSpace) {
+ case ColorSpace::SRGB:
+ return sRGBColorSpaceRef();
+
case ColorSpace::A98RGB:
#if HAVE(CORE_GRAPHICS_ADOBE_RGB_1998_COLOR_SPACE)
return adobeRGB1998ColorSpaceRef();
@@ -79,6 +98,7 @@
#else
return nullptr;
#endif
+
case ColorSpace::DisplayP3:
#if HAVE(CORE_GRAPHICS_DISPLAY_P3_COLOR_SPACE)
return displayP3ColorSpaceRef();
@@ -85,12 +105,49 @@
#else
return nullptr;
#endif
- case ColorSpace::Lab:
-#if HAVE(CORE_GRAPHICS_LAB_COLOR_SPACE)
- return labColorSpaceRef();
+
+ case ColorSpace::ExtendedA98RGB:
+#if HAVE(CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE)
+ return extendedAdobeRGB1998ColorSpaceRef();
#else
return nullptr;
#endif
+
+ case ColorSpace::ExtendedDisplayP3:
+#if HAVE(CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE)
+ return extendedDisplayP3ColorSpaceRef();
+#else
+ return nullptr;
+#endif
+
+ case ColorSpace::ExtendedLinearSRGB:
+#if HAVE(CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE)
+ return extendedLinearSRGBColorSpaceRef();
+#else
+ return nullptr;
+#endif
+
+ case ColorSpace::ExtendedProPhotoRGB:
+#if HAVE(CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE)
+ return extendedROMMRGBColorSpaceRef();
+#else
+ return nullptr;
+#endif
+
+ case ColorSpace::ExtendedRec2020:
+#if HAVE(CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE)
+ return extendedITUR_2020ColorSpaceRef();
+#else
+ return nullptr;
+#endif
+
+ case ColorSpace::ExtendedSRGB:
+#if HAVE(CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE)
+ return extendedSRGBColorSpaceRef();
+#else
+ return nullptr;
+#endif
+
case ColorSpace::LinearSRGB:
#if HAVE(CORE_GRAPHICS_LINEAR_SRGB_COLOR_SPACE)
return linearSRGBColorSpaceRef();
@@ -97,6 +154,7 @@
#else
return nullptr;
#endif
+
case ColorSpace::ProPhotoRGB:
#if HAVE(CORE_GRAPHICS_ROMMRGB_COLOR_SPACE)
return ROMMRGBColorSpaceRef();
@@ -103,6 +161,7 @@
#else
return nullptr;
#endif
+
case ColorSpace::Rec2020:
#if HAVE(CORE_GRAPHICS_ITUR_2020_COLOR_SPACE)
return ITUR_2020ColorSpaceRef();
@@ -109,8 +168,7 @@
#else
return nullptr;
#endif
- case ColorSpace::SRGB:
- return sRGBColorSpaceRef();
+
case ColorSpace::XYZ_D50:
#if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE)
return xyzD50ColorSpaceRef();
@@ -118,8 +176,11 @@
return nullptr;
#endif
- // FIXME: Add support for these once CoreGraphics supports it.
+ // FIXME: Add support for these once/if CoreGraphics adds support for it.
+ case ColorSpace::HSL:
+ case ColorSpace::HWB:
case ColorSpace::LCH:
+ case ColorSpace::Lab:
case ColorSpace::OKLCH:
case ColorSpace::OKLab:
case ColorSpace::XYZ_D65: