Changeset 273078 in webkit


Ignore:
Timestamp:
Feb 18, 2021 9:02:08 AM (17 months ago)
Author:
weinig@apple.com
Message:

lch() colors should serialize as lch(), not lab()
https://bugs.webkit.org/show_bug.cgi?id=222085

Reviewed by Darin Adler.

Source/WebCore:

Updates fast/css/parsing-lab-colors.html

The spec was updated to require lch() to serialize to itself.

Store LCHA colors in Color to allow serialization. This just moves
the conversion to Lab from parse time to CGColor creation time (it
happens implicitly in the conversion to extended sRGB).

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::parseLCHParameters):

  • platform/graphics/ColorSerialization.cpp:

(WebCore::serialization):
(WebCore::serializationForCSS):
(WebCore::serializationForHTML):
(WebCore::serializationForRenderTreeAsText):

  • platform/graphics/ColorSpace.cpp:

(WebCore::operator<<):

  • platform/graphics/ColorSpace.h:

(WebCore::callWithColorType):

  • platform/graphics/ColorUtilities.h:

(WebCore::isBlack):
(WebCore::isWhite):

  • platform/graphics/cg/ColorSpaceCG.h:

(WebCore::cachedNullableCGColorSpace):

LayoutTests:

The spec was updated to require lch() to serialize to itself.

  • fast/css/parsing-lab-colors-expected.txt:
  • fast/css/parsing-lab-colors.html:

Update test to reflect new serialization of lch().

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r273073 r273078  
     12021-02-17  Sam Weinig  <weinig@apple.com>
     2
     3        lch() colors should serialize as lch(), not lab()
     4        https://bugs.webkit.org/show_bug.cgi?id=222085
     5
     6        Reviewed by Darin Adler.
     7
     8        The spec was updated to require lch() to serialize to itself.
     9
     10        * fast/css/parsing-lab-colors-expected.txt:
     11        * fast/css/parsing-lab-colors.html:
     12        Update test to reflect new serialization of lch().
     13
    1142021-02-18  Martin Robinson  <mrobinson@igalia.com>
    215
  • trunk/LayoutTests/fast/css/parsing-lab-colors-expected.txt

    r272909 r273078  
    2121
    2222lch()
    23 PASS computedStyle("background-color", "lch(0% 0 0deg)") is "lab(0% 0 0)"
    24 PASS computedStyle("background-color", "lch(0% 0 0deg / 1)") is "lab(0% 0 0)"
    25 PASS computedStyle("background-color", "lch(0% 0 0deg / 0.5)") is "lab(0% 0 0 / 0.5)"
    26 PASS computedStyle("background-color", "lch(100% 230 0deg / 0.5)") is "lab(100% 230 0 / 0.5)"
    27 PASS computedStyle("background-color", "lch(20% 50 20deg/0.5)") is "lab(20% 46.98463 17.101006 / 0.5)"
    28 PASS computedStyle("background-color", "lch(20% 50 20deg/50%)") is "lab(20% 46.98463 17.101006 / 0.5)"
    29 PASS computedStyle("background-color", "lch(10% 20 20deg / -10%)") is "lab(10% 18.793852 6.8404026 / 0)"
    30 PASS computedStyle("background-color", "lch(10% 20 20deg / 110%)") is "lab(10% 18.793852 6.8404026)"
    31 PASS computedStyle("background-color", "lch(10% 20 1.28rad)") is "lab(10% 5.7343025 19.160316)"
    32 PASS computedStyle("background-color", "lch(10% 20 380deg)") is "lab(10% 18.793852 6.8404026)"
    33 PASS computedStyle("background-color", "lch(10% 20 -340deg)") is "lab(10% 18.793852 6.8404026)"
    34 PASS computedStyle("background-color", "lch(10% 20 740deg)") is "lab(10% 18.793852 6.8404026)"
    35 PASS computedStyle("background-color", "lch(10% 20 -700deg)") is "lab(10% 18.793852 6.8404026)"
    36 PASS computedStyle("background-color", "lch(-40% 0 0)") is "lab(0% 0 0)"
    37 PASS computedStyle("background-color", "lch(20% -20 0)") is "lab(20% 0 0)"
    38 PASS computedStyle("background-color", "lch(0% 0 0 / 0.5)") is "lab(0% 0 0 / 0.5)"
    39 PASS computedStyle("background-color", "lch(10% 20 20 / 110%)") is "lab(10% 18.793852 6.8404026)"
    40 PASS computedStyle("background-color", "lch(10% 20 -700)") is "lab(10% 18.793852 6.8404026)"
     23PASS computedStyle("background-color", "lch(0% 0 0deg)") is "lch(0% 0 0)"
     24PASS computedStyle("background-color", "lch(0% 0 0deg / 1)") is "lch(0% 0 0)"
     25PASS computedStyle("background-color", "lch(0% 0 0deg / 0.5)") is "lch(0% 0 0 / 0.5)"
     26PASS computedStyle("background-color", "lch(100% 230 0deg / 0.5)") is "lch(100% 230 0 / 0.5)"
     27PASS computedStyle("background-color", "lch(20% 50 20deg/0.5)") is "lch(20% 50 20 / 0.5)"
     28PASS computedStyle("background-color", "lch(20% 50 20deg/50%)") is "lch(20% 50 20 / 0.5)"
     29PASS computedStyle("background-color", "lch(10% 20 20deg / -10%)") is "lch(10% 20 20 / 0)"
     30PASS computedStyle("background-color", "lch(10% 20 20deg / 110%)") is "lch(10% 20 20)"
     31PASS computedStyle("background-color", "lch(10% 20 1.28rad)") is "lch(10% 20 73.3386)"
     32PASS computedStyle("background-color", "lch(10% 20 380deg)") is "lch(10% 20 20)"
     33PASS computedStyle("background-color", "lch(10% 20 -340deg)") is "lch(10% 20 20)"
     34PASS computedStyle("background-color", "lch(10% 20 740deg)") is "lch(10% 20 20)"
     35PASS computedStyle("background-color", "lch(10% 20 -700deg)") is "lch(10% 20 20)"
     36PASS computedStyle("background-color", "lch(-40% 0 0)") is "lch(0% 0 0)"
     37PASS computedStyle("background-color", "lch(20% -20 0)") is "lch(20% 0 0)"
     38PASS computedStyle("background-color", "lch(0% 0 0 / 0.5)") is "lch(0% 0 0 / 0.5)"
     39PASS computedStyle("background-color", "lch(10% 20 20 / 110%)") is "lch(10% 20 20)"
     40PASS computedStyle("background-color", "lch(10% 20 -700)") is "lch(10% 20 20)"
    4141
    4242color(lab )
  • trunk/LayoutTests/fast/css/parsing-lab-colors.html

    r272909 r273078  
    5353    debug('');
    5454    debug('lch()');
    55     testComputed("background-color", "lch(0% 0 0deg)", "lab(0% 0 0)");
    56     testComputed("background-color", "lch(0% 0 0deg / 1)", "lab(0% 0 0)");
    57     testComputed("background-color", "lch(0% 0 0deg / 0.5)", "lab(0% 0 0 / 0.5)");
    58     testComputed("background-color", "lch(100% 230 0deg / 0.5)", "lab(100% 230 0 / 0.5)");
    59     testComputed("background-color", "lch(20% 50 20deg/0.5)", "lab(20% 46.98463 17.101006 / 0.5)");
    60     testComputed("background-color", "lch(20% 50 20deg/50%)", "lab(20% 46.98463 17.101006 / 0.5)");
    61     testComputed("background-color", "lch(10% 20 20deg / -10%)", "lab(10% 18.793852 6.8404026 / 0)");
    62     testComputed("background-color", "lch(10% 20 20deg / 110%)", "lab(10% 18.793852 6.8404026)");
    63     testComputed("background-color", "lch(10% 20 1.28rad)", "lab(10% 5.7343025 19.160316)");
    64     testComputed("background-color", "lch(10% 20 380deg)", "lab(10% 18.793852 6.8404026)");
    65     testComputed("background-color", "lch(10% 20 -340deg)", "lab(10% 18.793852 6.8404026)");
    66     testComputed("background-color", "lch(10% 20 740deg)", "lab(10% 18.793852 6.8404026)");
    67     testComputed("background-color", "lch(10% 20 -700deg)", "lab(10% 18.793852 6.8404026)");
    68     testComputed("background-color", "lch(-40% 0 0)", "lab(0% 0 0)");
    69     testComputed("background-color", "lch(20% -20 0)", "lab(20% 0 0)");
     55    testComputed("background-color", "lch(0% 0 0deg)", "lch(0% 0 0)");
     56    testComputed("background-color", "lch(0% 0 0deg / 1)", "lch(0% 0 0)");
     57    testComputed("background-color", "lch(0% 0 0deg / 0.5)", "lch(0% 0 0 / 0.5)");
     58    testComputed("background-color", "lch(100% 230 0deg / 0.5)", "lch(100% 230 0 / 0.5)");
     59    testComputed("background-color", "lch(20% 50 20deg/0.5)", "lch(20% 50 20 / 0.5)");
     60    testComputed("background-color", "lch(20% 50 20deg/50%)", "lch(20% 50 20 / 0.5)");
     61    testComputed("background-color", "lch(10% 20 20deg / -10%)", "lch(10% 20 20 / 0)");
     62    testComputed("background-color", "lch(10% 20 20deg / 110%)", "lch(10% 20 20)");
     63    testComputed("background-color", "lch(10% 20 1.28rad)", "lch(10% 20 73.3386)");
     64    testComputed("background-color", "lch(10% 20 380deg)", "lch(10% 20 20)");
     65    testComputed("background-color", "lch(10% 20 -340deg)", "lch(10% 20 20)");
     66    testComputed("background-color", "lch(10% 20 740deg)", "lch(10% 20 20)");
     67    testComputed("background-color", "lch(10% 20 -700deg)", "lch(10% 20 20)");
     68    testComputed("background-color", "lch(-40% 0 0)", "lch(0% 0 0)");
     69    testComputed("background-color", "lch(20% -20 0)", "lch(20% 0 0)");
    7070    // hue (the third argument) can be either an angle or number, with number interpreted as degrees.
    71     testComputed("background-color", "lch(0% 0 0 / 0.5)", "lab(0% 0 0 / 0.5)");
    72     testComputed("background-color", "lch(10% 20 20 / 110%)", "lab(10% 18.793852 6.8404026)");
    73     testComputed("background-color", "lch(10% 20 -700)", "lab(10% 18.793852 6.8404026)");
     71    testComputed("background-color", "lch(0% 0 0 / 0.5)", "lch(0% 0 0 / 0.5)");
     72    testComputed("background-color", "lch(10% 20 20 / 110%)", "lch(10% 20 20)");
     73    testComputed("background-color", "lch(10% 20 -700)", "lch(10% 20 20)");
    7474
    7575    debug('');
  • trunk/Source/WebCore/ChangeLog

    r273077 r273078  
     12021-02-17  Sam Weinig  <weinig@apple.com>
     2
     3        lch() colors should serialize as lch(), not lab()
     4        https://bugs.webkit.org/show_bug.cgi?id=222085
     5
     6        Reviewed by Darin Adler.
     7
     8        Updates fast/css/parsing-lab-colors.html
     9
     10        The spec was updated to require lch() to serialize to itself.
     11
     12        Store LCHA colors in Color to allow serialization. This just moves
     13        the conversion to Lab from parse time to CGColor creation time (it
     14        happens implicitly in the conversion to extended sRGB).
     15
     16        * css/parser/CSSPropertyParserHelpers.cpp:
     17        (WebCore::CSSPropertyParserHelpers::parseLCHParameters):
     18        * platform/graphics/ColorSerialization.cpp:
     19        (WebCore::serialization):
     20        (WebCore::serializationForCSS):
     21        (WebCore::serializationForHTML):
     22        (WebCore::serializationForRenderTreeAsText):
     23        * platform/graphics/ColorSpace.cpp:
     24        (WebCore::operator<<):
     25        * platform/graphics/ColorSpace.h:
     26        (WebCore::callWithColorType):
     27        * platform/graphics/ColorUtilities.h:
     28        (WebCore::isBlack):
     29        (WebCore::isWhite):
     30        * platform/graphics/cg/ColorSpaceCG.h:
     31        (WebCore::cachedNullableCGColorSpace):
     32
    1332021-02-17  Wenson Hsieh  <wenson_hsieh@apple.com>
    234
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r272909 r273078  
    960960    auto normalizedHue = normalizeHue(*hue);
    961961
    962     return convertColor<Lab<float>>(LCHA<float> { static_cast<float>(normalizedLightness), static_cast<float>(normalizedChroma), static_cast<float>(normalizedHue), static_cast<float>(*alpha) });
     962    return LCHA<float> { static_cast<float>(normalizedLightness), static_cast<float>(normalizedChroma), static_cast<float>(normalizedHue), static_cast<float>(*alpha) };
    963963}
    964964
  • trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp

    r272475 r273078  
    4545static String serializationForRenderTreeAsText(const DisplayP3<float>&);
    4646
     47static String serializationForCSS(const LCHA<float>&);
     48static String serializationForHTML(const LCHA<float>&);
     49static String serializationForRenderTreeAsText(const LCHA<float>&);
     50
    4751static String serializationForCSS(const Lab<float>&);
    4852static String serializationForHTML(const Lab<float>&);
     
    102106    case ColorSpace::DisplayP3:
    103107        return "display-p3"_s;
     108    case ColorSpace::LCH:
     109        return "lch"_s;
    104110    case ColorSpace::Lab:
    105111        return "lab"_s;
     
    162168}
    163169
     170// MARK: LCHA<float> overloads
     171
     172String serializationForCSS(const LCHA<float>& color)
     173{
     174    // https://www.w3.org/TR/css-color-4/#serializing-lab-lch
     175
     176    auto [c1, c2, c3, alpha] = color;
     177    if (WTF::areEssentiallyEqual(alpha, 1.0f))
     178        return makeString("lch(", c1, "% ", c2, ' ', c3, ')');
     179    return makeString("lch(", c1, "% ", c2, ' ', c3, " / ", alpha, ')');
     180}
     181
     182String serializationForHTML(const LCHA<float>& color)
     183{
     184    return serializationForCSS(color);
     185}
     186
     187String serializationForRenderTreeAsText(const LCHA<float>& color)
     188{
     189    return serializationForCSS(color);
     190}
     191
    164192// MARK: Lab<float> overloads
    165193
  • trunk/Source/WebCore/platform/graphics/ColorSpace.cpp

    r272475 r273078  
    4040        ts << "DisplayP3";
    4141        break;
     42    case ColorSpace::LCH:
     43        ts << "LCH";
     44        break;
    4245    case ColorSpace::Lab:
    4346        ts << "L*a*b";
  • trunk/Source/WebCore/platform/graphics/ColorSpace.h

    r272475 r273078  
    3939    A98RGB,
    4040    DisplayP3,
     41    LCH,
    4142    Lab,
    4243    LinearSRGB,
     
    5960template<typename T> struct ColorSpaceMapping<A98RGB<T>> { static constexpr auto colorSpace { ColorSpace::A98RGB }; };
    6061template<typename T> struct ColorSpaceMapping<DisplayP3<T>> { static constexpr auto colorSpace { ColorSpace::DisplayP3 }; };
     62template<typename T> struct ColorSpaceMapping<LCHA<T>> { static constexpr auto colorSpace { ColorSpace::LCH }; };
    6163template<typename T> struct ColorSpaceMapping<Lab<T>> { static constexpr auto colorSpace { ColorSpace::Lab }; };
    6264template<typename T> struct ColorSpaceMapping<LinearSRGBA<T>> { static constexpr auto colorSpace { ColorSpace::LinearSRGB }; };
     
    7678    case ColorSpace::DisplayP3:
    7779        return std::invoke(std::forward<Functor>(functor), makeFromComponents<DisplayP3<T>>(components));
     80    case ColorSpace::LCH:
     81        return std::invoke(std::forward<Functor>(functor), makeFromComponents<LCHA<T>>(components));
    7882    case ColorSpace::Lab:
    7983        return std::invoke(std::forward<Functor>(functor), makeFromComponents<Lab<T>>(components));
     
    103107        WebCore::ColorSpace::A98RGB,
    104108        WebCore::ColorSpace::DisplayP3,
     109        WebCore::ColorSpace::LCH,
    105110        WebCore::ColorSpace::Lab,
    106111        WebCore::ColorSpace::LinearSRGB,
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.h

    r272474 r273078  
    6161template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr> constexpr bool isBlack(const ColorType&);
    6262template<WhitePoint W> constexpr bool isBlack(const XYZA<float, W>&);
     63constexpr bool isBlack(const LCHA<float>&);
    6364constexpr bool isBlack(const Lab<float>&);
    6465
    6566template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr> constexpr bool isWhite(const ColorType&);
    6667template<WhitePoint W> constexpr bool isWhite(const XYZA<float, W>&);
     68constexpr bool isWhite(const LCHA<float>&);
    6769constexpr bool isWhite(const Lab<float>&);
    6870
     
    153155}
    154156
     157constexpr bool isBlack(const LCHA<float>& color)
     158{
     159    return color.lightness == 0 && color.alpha == AlphaTraits<float>::opaque;
     160}
     161
    155162constexpr bool isBlack(const Lab<float>& color)
    156163{
     
    169176{
    170177    return color.y == 1 && color.alpha == AlphaTraits<float>::opaque;
     178}
     179
     180constexpr bool isWhite(const LCHA<float>& color)
     181{
     182    return color.lightness == 100 && color.alpha == AlphaTraits<float>::opaque;
    171183}
    172184
  • trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h

    r272736 r273078  
    8181        return nullptr;
    8282#endif
     83    case ColorSpace::LCH:
     84        return nullptr;
    8385    case ColorSpace::Lab:
    8486#if HAVE(CORE_GRAPHICS_LAB_COLOR_SPACE)
Note: See TracChangeset for help on using the changeset viewer.