Changeset 272125 in webkit


Ignore:
Timestamp:
Jan 31, 2021 12:24:46 PM (18 months ago)
Author:
weinig@apple.com
Message:

Add support for color(prophoto-rgb ...) as part of CSS Color 4
https://bugs.webkit.org/show_bug.cgi?id=221116

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Add some new WPT tests for color(prophoto-rgb ) that will be upstreamed shortly.
(see https://github.com/web-platform-tests/wpt/pull/27416).

  • web-platform-tests/css/css-color/prophoto-rgb-001-expected.html: Added.
  • web-platform-tests/css/css-color/prophoto-rgb-001.html: Added.
  • web-platform-tests/css/css-color/prophoto-rgb-002-expected.html: Added.
  • web-platform-tests/css/css-color/prophoto-rgb-002.html: Added.
  • web-platform-tests/css/css-color/prophoto-rgb-003-expected.html: Added.
  • web-platform-tests/css/css-color/prophoto-rgb-003.html: Added.
  • web-platform-tests/css/css-color/prophoto-rgb-004-expected.html: Added.
  • web-platform-tests/css/css-color/prophoto-rgb-004.html: Added.

Source/WebCore:

Tests: imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001.html

imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002.html
imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003.html
imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004.html

  • css/CSSValueKeywords.in:

Add prophoto-rgb keyword.

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypes):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
Parse color(prophoto-rgb ) using the existing generic rgb type color function
parsing function.

  • platform/graphics/ColorConversion.cpp:

(WebCore::convertFromD50WhitePointToD65WhitePoint):
(WebCore::convertFromD65WhitePointToD50WhitePoint):
Move these chromatic adaptation conversions up in the file so they can be reused by
toLinearProPhotoRGB(copnst XYZA&) and toXYZA(const LinearProPhotoRGB).

(WebCore::toLinearProPhotoRGB):
(WebCore::toProPhotoRGB):
(WebCore::toXYZA):

  • platform/graphics/ColorConversion.h:

(WebCore::toLinearRec2020):
(WebCore::toProPhotoRGB):
(WebCore::toLinearProPhotoRGB):
(WebCore::callWithColorType):
Add conversion support for ProPhotoRGB, utilizing the ProPhotoRGBTransferFunction
for gamma correction.

  • platform/graphics/ColorSerialization.cpp:

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

  • platform/graphics/ColorSerialization.h:

Add serialization support, matching other rgb color() function
types.

  • platform/graphics/ColorSpace.cpp:

(WebCore::operator<<):

  • platform/graphics/ColorSpace.h:

Add ProPhotoRGB as a new ColorSpace.

  • platform/graphics/ColorTransferFunctions.h:

(WebCore::mode>::toGammaEncoded):
(WebCore::mode>::toLinear):
Add transfer function for ProPhotoRGB. Both clamped and unclamped
are implemented, though for now, only the clamped variant is
being used. Also fix small bug in unclamped Rec2020TransferFunction
that I meant to land before where the sign wasn't getting applied
to the whole computation.

  • platform/graphics/ColorTypes.h:

Add ProPhotoRGB and LinearProPhotoRGB types. Fix typo in forward
declaration of the XYZA type.

  • platform/graphics/cg/ColorSpaceCG.cpp:

(WebCore::proPhotoRGBColorSpaceRef):

  • platform/graphics/cg/ColorSpaceCG.h:

(WebCore::cachedCGColorSpace):
Add support for the ProPhotoRGB as a CoreGraphics color space, where
it is known as kCGColorSpaceROMMRGB (ROMM stands for Reference Output
Medium Metric, another name for ProPhoto).

LayoutTests:

Remove now passing prophoto-rgb tests.

  • fast/css/parsing-color-function-expected.txt:
  • fast/css/parsing-color-function.html:

Add prophoto-rgb as an rgb type so it gets tested with the
others.

Location:
trunk
Files:
8 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r272123 r272125  
     12021-01-31  Sam Weinig  <weinig@apple.com>
     2
     3        Add support for color(prophoto-rgb ...) as part of CSS Color 4
     4        https://bugs.webkit.org/show_bug.cgi?id=221116
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * TestExpectations:
     9        Remove now passing prophoto-rgb tests.
     10
     11        * fast/css/parsing-color-function-expected.txt:
     12        * fast/css/parsing-color-function.html:
     13        Add prophoto-rgb as an rgb type so it gets tested with the
     14        others.
     15
    1162021-01-30  Sam Weinig  <weinig@apple.com>
    217
  • trunk/LayoutTests/TestExpectations

    r272123 r272125  
    46054605webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-003.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
    46064606webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-004.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
    4607 webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-009.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
    4608 webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-010.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
    46094607webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-014.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support
    46104608webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-015.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support (unclear if this makes sense)
  • trunk/LayoutTests/fast/css/parsing-color-function-expected.txt

    r272123 r272125  
    9494PASS computedStyle("background-color", "color(rec2020 0% 0% 0deg)") is "rgba(0, 0, 0, 0)"
    9595PASS computedStyle("background-color", "color(rec2020 40% 0 0deg)") is "rgba(0, 0, 0, 0)"
     96
     97Testing color(prophoto-rgb ...)
     98PASS computedStyle("background-color", "color(prophoto-rgb 0% 0% 0%)") is "color(prophoto-rgb 0 0 0)"
     99PASS computedStyle("background-color", "color(prophoto-rgb 10% 10% 10%)") is "color(prophoto-rgb 0.1 0.1 0.1)"
     100PASS computedStyle("background-color", "color(prophoto-rgb .2 .2 25%)") is "color(prophoto-rgb 0.2 0.2 0.25)"
     101PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / 1)") is "color(prophoto-rgb 0 0 0)"
     102PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0 / 0.5)") is "color(prophoto-rgb 0 0 0 / 0.5)"
     103PASS computedStyle("background-color", "color(prophoto-rgb 20% 0 10/0.5)") is "color(prophoto-rgb 0.2 0 1 / 0.5)"
     104PASS computedStyle("background-color", "color(prophoto-rgb 20% 0 10/50%)") is "color(prophoto-rgb 0.2 0 1 / 0.5)"
     105PASS computedStyle("background-color", "color(prophoto-rgb 400% 0 10/50%)") is "color(prophoto-rgb 1 0 1 / 0.5)"
     106PASS computedStyle("background-color", "color(prophoto-rgb 50% -160 160)") is "color(prophoto-rgb 0.5 0 1)"
     107PASS computedStyle("background-color", "color(prophoto-rgb 50% -200 200)") is "color(prophoto-rgb 0.5 0 1)"
     108PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / -10%)") is "color(prophoto-rgb 0 0 0 / 0)"
     109PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / 110%)") is "color(prophoto-rgb 0 0 0)"
     110PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 / 300%)") is "color(prophoto-rgb 0 0 0)"
     111PASS computedStyle("background-color", "color(prophoto-rgb 50% -200)") is "color(prophoto-rgb 0.5 0 0)"
     112PASS computedStyle("background-color", "color(prophoto-rgb 50%)") is "color(prophoto-rgb 0.5 0 0)"
     113PASS computedStyle("background-color", "color(prophoto-rgb)") is "color(prophoto-rgb 0 0 0)"
     114PASS computedStyle("background-color", "color(prophoto-rgb 50% -200 / 0.5)") is "color(prophoto-rgb 0.5 0 0 / 0.5)"
     115PASS computedStyle("background-color", "color(prophoto-rgb 50% / 0.5)") is "color(prophoto-rgb 0.5 0 0 / 0.5)"
     116PASS computedStyle("background-color", "color(prophoto-rgb / 0.5)") is "color(prophoto-rgb 0 0 0 / 0.5)"
     117
     118Test invalid values
     119PASS computedStyle("background-color", "color(prophoto-rgb 0 0 0 0)") is "rgba(0, 0, 0, 0)"
     120PASS computedStyle("background-color", "color(prophoto-rgb 0deg 0% 0)") is "rgba(0, 0, 0, 0)"
     121PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0 1)") is "rgba(0, 0, 0, 0)"
     122PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0 10%)") is "rgba(0, 0, 0, 0)"
     123PASS computedStyle("background-color", "color(prophoto-rgb 0% 0 0deg)") is "rgba(0, 0, 0, 0)"
     124PASS computedStyle("background-color", "color(prophoto-rgb 0% 0% 0deg)") is "rgba(0, 0, 0, 0)"
     125PASS computedStyle("background-color", "color(prophoto-rgb 40% 0 0deg)") is "rgba(0, 0, 0, 0)"
    96126PASS successfullyParsed is true
    97127
  • trunk/LayoutTests/fast/css/parsing-color-function.html

    r272123 r272125  
    3535    }
    3636
    37     for (const color of [ "srgb", "a98-rgb", "rec2020" ]) {
     37    for (const color of [ "srgb", "a98-rgb", "rec2020", "prophoto-rgb" ]) {
    3838        debug('');
    3939        debug(`Testing color(${color} ...)`);
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r272123 r272125  
     12021-01-31  Sam Weinig  <weinig@apple.com>
     2
     3        Add support for color(prophoto-rgb ...) as part of CSS Color 4
     4        https://bugs.webkit.org/show_bug.cgi?id=221116
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Add some new WPT tests for color(prophoto-rgb ) that will be upstreamed shortly.
     9        (see https://github.com/web-platform-tests/wpt/pull/27416).
     10
     11        * web-platform-tests/css/css-color/prophoto-rgb-001-expected.html: Added.
     12        * web-platform-tests/css/css-color/prophoto-rgb-001.html: Added.
     13        * web-platform-tests/css/css-color/prophoto-rgb-002-expected.html: Added.
     14        * web-platform-tests/css/css-color/prophoto-rgb-002.html: Added.
     15        * web-platform-tests/css/css-color/prophoto-rgb-003-expected.html: Added.
     16        * web-platform-tests/css/css-color/prophoto-rgb-003.html: Added.
     17        * web-platform-tests/css/css-color/prophoto-rgb-004-expected.html: Added.
     18        * web-platform-tests/css/css-color/prophoto-rgb-004.html: Added.
     19
    1202021-01-30  Sam Weinig  <weinig@apple.com>
    221
  • trunk/Source/WebCore/ChangeLog

    r272124 r272125  
     12021-01-31  Sam Weinig  <weinig@apple.com>
     2
     3        Add support for color(prophoto-rgb ...) as part of CSS Color 4
     4        https://bugs.webkit.org/show_bug.cgi?id=221116
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Tests: imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-001.html
     9               imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-002.html
     10               imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-003.html
     11               imported/w3c/web-platform-tests/css/css-color/prophoto-rgb-004.html
     12
     13        * css/CSSValueKeywords.in:
     14        Add prophoto-rgb keyword.
     15
     16        * css/parser/CSSPropertyParserHelpers.cpp:
     17        (WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypes):
     18        (WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
     19        Parse color(prophoto-rgb ) using the existing generic rgb type color function
     20        parsing function.
     21
     22        * platform/graphics/ColorConversion.cpp:
     23        (WebCore::convertFromD50WhitePointToD65WhitePoint):
     24        (WebCore::convertFromD65WhitePointToD50WhitePoint):
     25        Move these chromatic adaptation conversions up in the file so they can be reused by
     26        toLinearProPhotoRGB(copnst XYZA&) and toXYZA(const LinearProPhotoRGB).
     27
     28        (WebCore::toLinearProPhotoRGB):
     29        (WebCore::toProPhotoRGB):
     30        (WebCore::toXYZA):
     31        * platform/graphics/ColorConversion.h:
     32        (WebCore::toLinearRec2020):
     33        (WebCore::toProPhotoRGB):
     34        (WebCore::toLinearProPhotoRGB):
     35        (WebCore::callWithColorType):
     36        Add conversion support for ProPhotoRGB, utilizing the ProPhotoRGBTransferFunction
     37        for gamma correction.
     38
     39        * platform/graphics/ColorSerialization.cpp:
     40        (WebCore::serialization):
     41        (WebCore::serializationForCSS):
     42        (WebCore::serializationForHTML):
     43        (WebCore::serializationForRenderTreeAsText):
     44        * platform/graphics/ColorSerialization.h:
     45        Add serialization support, matching other rgb color() function
     46        types.
     47
     48        * platform/graphics/ColorSpace.cpp:
     49        (WebCore::operator<<):
     50        * platform/graphics/ColorSpace.h:
     51        Add ProPhotoRGB as a new ColorSpace.
     52
     53        * platform/graphics/ColorTransferFunctions.h:
     54        (WebCore::mode>::toGammaEncoded):
     55        (WebCore::mode>::toLinear):
     56        Add transfer function for ProPhotoRGB. Both clamped and unclamped
     57        are implemented, though for now, only the clamped variant is
     58        being used. Also fix small bug in unclamped Rec2020TransferFunction
     59        that I meant to land before where the sign wasn't getting applied
     60        to the whole computation.
     61
     62        * platform/graphics/ColorTypes.h:
     63        Add ProPhotoRGB and LinearProPhotoRGB types. Fix typo in forward
     64        declaration of the XYZA type.
     65
     66        * platform/graphics/cg/ColorSpaceCG.cpp:
     67        (WebCore::proPhotoRGBColorSpaceRef):
     68        * platform/graphics/cg/ColorSpaceCG.h:
     69        (WebCore::cachedCGColorSpace):
     70        Add support for the ProPhotoRGB as a CoreGraphics color space, where
     71        it is known as kCGColorSpaceROMMRGB (ROMM stands for Reference Output
     72        Medium Metric, another name for ProPhoto).
     73
    1742021-01-31  Zalan Bujtas  <zalan@apple.com>
    275
  • trunk/Source/WebCore/css/CSSValueKeywords.in

    r272123 r272125  
    14071407display-p3
    14081408// lab
     1409prophoto-rgb
    14091410// rec2020
    14101411// sRGB
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r272123 r272125  
    895895static Color parseColorFunctionForRGBTypes(CSSParserTokenRange& args)
    896896{
    897     ASSERT(args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSRGB);
     897    ASSERT(args.peek().id() == CSSValueA98Rgb || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueProphotoRgb || args.peek().id() == CSSValueRec2020 || args.peek().id() == CSSValueSRGB);
    898898    consumeIdentRaw(args);
    899899
     
    958958    case CSSValueLab:
    959959        color = parseColorFunctionForLabParameters(args);
     960        break;
     961    case CSSValueProphotoRgb:
     962        color = parseColorFunctionForRGBTypes<ProPhotoRGB<float>>(args);
    960963        break;
    961964    case CSSValueRec2020:
  • trunk/Source/WebCore/platform/graphics/ColorConversion.cpp

    r272123 r272125  
    11/*
    2  * Copyright (C) 2017, 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6666};
    6767
     68// ProPhotoRGB Matrices.
     69
     70// https://drafts.csswg.org/css-color/#color-conversion-code
     71static constexpr ColorMatrix<3, 3> xyzToLinearProPhotoRGBMatrix {
     72     1.3457989731028281f,  -0.25558010007997534f,  -0.05110628506753401f,
     73    -0.5446224939028347f,   1.5082327413132781f,    0.02053603239147973f,
     74     0.0f,                  0.0f,                   1.2119675456389454f
     75};
     76
     77// https://drafts.csswg.org/css-color/#color-conversion-code
     78static constexpr ColorMatrix<3, 3> linearProPhotoRGBToXYZMatrix {
     79    0.7977604896723027f,  0.13518583717574031f,  0.0313493495815248f,
     80    0.2880711282292934f,  0.7118432178101014f,   0.00008565396060525902f,
     81    0.0f,                 0.0f,                  0.8251046025104601f
     82};
     83
    6884// Rec2020 Matrices.
    6985
     
    116132};
    117133
     134// MARK: Chromatic Adaptation conversions.
     135
     136static XYZA<float> convertFromD50WhitePointToD65WhitePoint(const XYZA<float>& color)
     137{
     138    return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D50ToD65Matrix.transformedColorComponents(asColorComponents(color)));
     139}
     140
     141static XYZA<float> convertFromD65WhitePointToD50WhitePoint(const XYZA<float>& color)
     142{
     143    return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D65ToD50Matrix.transformedColorComponents(asColorComponents(color)));
     144}
     145
    118146// MARK: Gamma conversions.
    119147
     
    166194}
    167195
     196// ProPhotoRGB <-> LinearProPhotoRGB conversions.
     197
     198LinearProPhotoRGB<float> toLinearProPhotoRGB(const ProPhotoRGB<float>& color)
     199{
     200    return toLinear<ProPhotoRGBTransferFunction<float, TransferFunctionMode::Clamped>>(color);
     201}
     202
     203ProPhotoRGB<float> toProPhotoRGB(const LinearProPhotoRGB<float>& color)
     204{
     205    return toGammaEncoded<ProPhotoRGBTransferFunction<float, TransferFunctionMode::Clamped>>(color);
     206}
     207
    168208// Rec2020 <-> LinearRec2020 conversions.
    169209
     
    228268}
    229269
     270// - LinearProPhotoRGB matrix conversions.
     271
     272LinearProPhotoRGB<float> toLinearProPhotoRGB(const XYZA<float>& color)
     273{
     274    // We expect XYZA colors to be using the D65 white point, unlike ProPhotoRGB, which
     275    // uses a D50 white point, so as a first step, use the Bradford transform to convert
     276    // the incoming XYZA color to D50 white point.
     277    auto xyzWithD50WhitePoint = convertFromD65WhitePointToD50WhitePoint(color);
     278    return makeFromComponentsClampingExceptAlpha<LinearProPhotoRGB<float>>(xyzToLinearProPhotoRGBMatrix.transformedColorComponents(asColorComponents(xyzWithD50WhitePoint)));
     279}
     280
     281XYZA<float> toXYZA(const LinearProPhotoRGB<float>& color)
     282{
     283    auto xyzWithD50WhitePoint = makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearProPhotoRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
     284
     285    // We expect XYZA colors to be using the D65 white point, unlike ProPhotoRGB, which
     286    // uses a D50 white point, so as a final step, use the Bradford transform to convert
     287    // the resulting XYZA color to a D65 white point.
     288    return convertFromD50WhitePointToD65WhitePoint(xyzWithD50WhitePoint);
     289}
     290
    230291// - LinearRec2020 matrix conversions.
    231292
     
    250311{
    251312    return makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearSRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
    252 }
    253 
    254 // MARK: Chromatic Adaptation conversions.
    255 
    256 static XYZA<float> convertFromD50WhitePointToD65WhitePoint(const XYZA<float>& color)
    257 {
    258     return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D50ToD65Matrix.transformedColorComponents(asColorComponents(color)));
    259 }
    260 
    261 static XYZA<float> convertFromD65WhitePointToD50WhitePoint(const XYZA<float>& color)
    262 {
    263     return makeFromComponentsClampingExceptAlpha<XYZA<float>>(D65ToD50Matrix.transformedColorComponents(asColorComponents(color)));
    264313}
    265314
     
    509558}
    510559
     560// - ProPhotoRGB combination functions.
     561
     562XYZA<float> toXYZA(const ProPhotoRGB<float>& color)
     563{
     564    return toXYZA(toLinearProPhotoRGB(color));
     565}
     566
     567ProPhotoRGB<float> toProPhotoRGB(const XYZA<float>& color)
     568{
     569    return toProPhotoRGB(toLinearProPhotoRGB(color));
     570}
     571
    511572// - Rec2020 combination functions.
    512573
  • trunk/Source/WebCore/platform/graphics/ColorConversion.h

    r272123 r272125  
    11/*
    2  * Copyright (C) 2017, 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030namespace WebCore {
    3131
    32 // All color types must at least implement the following conversions to and from the XYZA color space:
    33 //    XYZA<float> toXYZA(const ColorType<float>&);
    34 //    ColorType<float> toColorType(const XYZA<float>&);
     32// All color types must at least implement the following conversions to and from the XYZA color space
     33//
     34//    XYZA<float> toXYZA(const `ColorType`<float>&);
     35//    `ColorType`<float> to`ColorType`(const XYZA<float>&);
     36//
     37// as well as an identity conversion
     38//
     39//    constexpr `ColorType`<float> to`ColorType`(const `ColorType`<float>& color) { return color; }
     40//
     41// and a generic conversion utilizing a conversion the XYZ color space
     42//
     43//    template<typename T> `ColorType`<float> to`ColorType`(const T& color)
    3544//
    3645// Any additional conversions can be thought of as optimizations, shortcutting unnecessary steps, though
     
    92101WEBCORE_EXPORT ExtendedSRGBA<float> toExtendedSRGBA(const LinearExtendedSRGBA<float>&);
    93102
     103// LinearProPhotoRGB
     104WEBCORE_EXPORT XYZA<float> toXYZA(const LinearProPhotoRGB<float>&);
     105WEBCORE_EXPORT LinearProPhotoRGB<float> toLinearProPhotoRGB(const XYZA<float>&);
     106// Additions
     107WEBCORE_EXPORT ProPhotoRGB<float> toProPhotoRGB(const LinearProPhotoRGB<float>&);
     108
    94109// LinearRec2020
    95110WEBCORE_EXPORT XYZA<float> toXYZA(const LinearRec2020<float>&);
     
    103118// Additions
    104119WEBCORE_EXPORT SRGBA<float> toSRGBA(const LinearSRGBA<float>&);
     120
     121// ProPhotoRGB
     122WEBCORE_EXPORT XYZA<float> toXYZA(const ProPhotoRGB<float>&);
     123WEBCORE_EXPORT ProPhotoRGB<float> toProPhotoRGB(const XYZA<float>&);
     124// Additions
     125WEBCORE_EXPORT LinearProPhotoRGB<float> toLinearProPhotoRGB(const ProPhotoRGB<float>&);
    105126
    106127// Rec2020
     
    129150constexpr LinearDisplayP3<float> toLinearDisplayP3(const LinearDisplayP3<float>& color) { return color; }
    130151constexpr LinearExtendedSRGBA<float> toLinearExtendedSRGBA(const LinearExtendedSRGBA<float>& color) { return color; }
     152constexpr LinearProPhotoRGB<float> toLinearRec2020(const LinearProPhotoRGB<float>& color) { return color; }
    131153constexpr LinearRec2020<float> toLinearRec2020(const LinearRec2020<float>& color) { return color; }
    132154constexpr LinearSRGBA<float> toLinearSRGBA(const LinearSRGBA<float>& color) { return color; }
     155constexpr ProPhotoRGB<float> toProPhotoRGB(const ProPhotoRGB<float>& color) { return color; }
    133156constexpr Rec2020<float> toRec2020(const Rec2020<float>& color) { return color; }
    134157constexpr SRGBA<float> toSRGBA(const SRGBA<float>& color) { return color; }
     
    186209}
    187210
     211template<typename T> LinearProPhotoRGB<float> toLinearProPhotoRGB(const T& color)
     212{
     213    return toLinearProPhotoRGB(toXYZA(color));
     214}
     215
    188216template<typename T> LinearRec2020<float> toLinearRec2020(const T& color)
    189217{
     
    194222{
    195223    return toLinearSRGBA(toXYZA(color));
     224}
     225
     226template<typename T> ProPhotoRGB<float> toProPhotoRGB(const T& color)
     227{
     228    return toProPhotoRGB(toXYZA(color));
    196229}
    197230
     
    218251    case ColorSpace::LinearRGB:
    219252        return std::invoke(std::forward<Functor>(functor), makeFromComponents<LinearSRGBA<T>>(components));
     253    case ColorSpace::ProPhotoRGB:
     254        return std::invoke(std::forward<Functor>(functor), makeFromComponents<ProPhotoRGB<T>>(components));
    220255    case ColorSpace::Rec2020:
    221256        return std::invoke(std::forward<Functor>(functor), makeFromComponents<Rec2020<T>>(components));
  • trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp

    r272123 r272125  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6969    case ColorSpace::LinearRGB:
    7070        return "linear-srgb"_s;
     71    case ColorSpace::ProPhotoRGB:
     72        return "prophoto-rgb"_s;
    7173    case ColorSpace::Rec2020:
    7274        return "rec2020"_s;
     
    156158
    157159String serializationForRenderTreeAsText(const LinearSRGBA<float>& color)
     160{
     161    return serialization(color);
     162}
     163
     164// MARK: ProPhotoRGB<float> overloads
     165
     166String serializationForCSS(const ProPhotoRGB<float>& color)
     167{
     168    return serialization(color);
     169}
     170
     171String serializationForHTML(const ProPhotoRGB<float>& color)
     172{
     173    return serialization(color);
     174}
     175
     176String serializationForRenderTreeAsText(const ProPhotoRGB<float>& color)
    158177{
    159178    return serialization(color);
  • trunk/Source/WebCore/platform/graphics/ColorSerialization.h

    r272123 r272125  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3636template<typename> struct Lab;
    3737template<typename> struct LinearSRGBA;
     38template<typename> struct ProPhotoRGB;
    3839template<typename> struct Rec2020;
    3940template<typename> struct SRGBA;
     
    6566WEBCORE_EXPORT String serializationForRenderTreeAsText(const LinearSRGBA<float>&);
    6667
     68WEBCORE_EXPORT String serializationForCSS(const ProPhotoRGB<float>&);
     69WEBCORE_EXPORT String serializationForHTML(const ProPhotoRGB<float>&);
     70WEBCORE_EXPORT String serializationForRenderTreeAsText(const ProPhotoRGB<float>&);
     71
    6772WEBCORE_EXPORT String serializationForCSS(const Rec2020<float>&);
    6873WEBCORE_EXPORT String serializationForHTML(const Rec2020<float>&);
  • trunk/Source/WebCore/platform/graphics/ColorSpace.cpp

    r272123 r272125  
    4646        ts << "LinearRGB";
    4747        break;
     48    case ColorSpace::ProPhotoRGB:
     49        ts << "ProPhotoRGB";
     50        break;
    4851    case ColorSpace::Rec2020:
    4952        ts << "Rec2020";
  • trunk/Source/WebCore/platform/graphics/ColorSpace.h

    r272123 r272125  
    3737    Lab,
    3838    LinearRGB,
     39    ProPhotoRGB,
    3940    Rec2020,
    4041    SRGB,
  • trunk/Source/WebCore/platform/graphics/ColorTransferFunctions.h

    r272123 r272125  
    4444
    4545template<typename T, TransferFunctionMode mode>
     46struct ProPhotoRGBTransferFunction {
     47    static constexpr T gamma = 1.8;
     48
     49    static T toGammaEncoded(T);
     50    static T toLinear(T);
     51};
     52
     53template<typename T, TransferFunctionMode mode>
    4654struct Rec2020TransferFunction {
    4755    static constexpr T alpha = 1.09929682680944;
     
    7987}
    8088
     89// MARK: ProPhotoRGBTransferFunction.
     90
     91template<typename T, TransferFunctionMode mode> T ProPhotoRGBTransferFunction<T, mode>::toGammaEncoded(T c)
     92{
     93    if constexpr (mode == TransferFunctionMode::Clamped) {
     94        if (c < 1.0 / 512.0)
     95            return 16.0 * c;
     96
     97        return clampTo<T>(std::pow(c, 1.0 / gamma), 0, 1);
     98    } else {
     99        if (std::abs(c) < 1.0 / 512.0)
     100            return 16.0 * c;
     101
     102        float sign = std::signbit(c) ? -1.0 : 1.0;
     103        return std::pow(c, 1.0 / gamma) * sign;
     104    }
     105}
     106
     107template<typename T, TransferFunctionMode mode> T ProPhotoRGBTransferFunction<T, mode>::toLinear(T c)
     108{
     109    if constexpr (mode == TransferFunctionMode::Clamped) {
     110        if (c <= 16.0 / 512.0)
     111            return c / 16.0;
     112
     113        return clampTo<T>(std::pow(c, gamma), 0, 1);
     114    } else {
     115        if (std::abs(c) <= 16.0 / 512.0)
     116            return c / 16.0;
     117
     118        float sign = std::signbit(c) ? -1.0 : 1.0;
     119        return std::pow(c, gamma) * sign;
     120    }
     121}
     122
    81123// MARK: Rec2020TransferFunction.
    82124
     
    93135
    94136        float sign = std::signbit(c) ? -1.0 : 1.0;
    95         return sign * alpha * std::pow(c, gamma) - (alpha - 1.0);
     137        return (alpha * std::pow(c, gamma) - (alpha - 1.0)) * sign;
    96138    }
    97139}
  • trunk/Source/WebCore/platform/graphics/ColorTypes.h

    r272123 r272125  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4141template<typename> struct LinearDisplayP3;
    4242template<typename> struct LinearExtendedSRGBA;
     43template<typename> struct LinearProPhotoRGB;
    4344template<typename> struct LinearRec2020;
    4445template<typename> struct LinearSRGBA;
     46template<typename> struct ProPhotoRGB;
    4547template<typename> struct Rec2020;
    4648template<typename> struct SRGBA;
    47 template<typename> struct XYZ;
     49template<typename> struct XYZA;
    4850
    4951// MARK: Make functions.
     
    259261template<typename T> LinearExtendedSRGBA(T, T, T, T) -> LinearExtendedSRGBA<T>;
    260262
     263template<typename T> struct LinearProPhotoRGB : RGBAType<LinearProPhotoRGB, T, RGBModel<T>> {
     264    using RGBAType<LinearProPhotoRGB, T, RGBModel<T>>::RGBAType;
     265    using GammaEncodedCounterpart = ProPhotoRGB<T>;
     266};
     267template<typename T> LinearProPhotoRGB(T, T, T, T) -> LinearProPhotoRGB<T>;
     268
    261269template<typename T> struct LinearRec2020 : RGBAType<LinearRec2020, T, RGBModel<T>> {
    262270    using RGBAType<LinearRec2020, T, RGBModel<T>>::RGBAType;
     
    271279};
    272280template<typename T> LinearSRGBA(T, T, T, T) -> LinearSRGBA<T>;
     281
     282template<typename T> struct ProPhotoRGB : RGBAType<ProPhotoRGB, T, RGBModel<T>> {
     283    using RGBAType<ProPhotoRGB, T, RGBModel<T>>::RGBAType;
     284    using LinearCounterpart = LinearProPhotoRGB<T>;
     285    static constexpr auto colorSpace = ColorSpace::ProPhotoRGB;
     286};
     287template<typename T> ProPhotoRGB(T, T, T, T) -> ProPhotoRGB<T>;
    273288
    274289template<typename T> struct Rec2020 : RGBAType<Rec2020, T, RGBModel<T>> {
  • trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp

    r272123 r272125  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    101101}
    102102
     103CGColorSpaceRef proPhotoRGBColorSpaceRef()
     104{
     105    static CGColorSpaceRef proPhotoRGBColorSpace;
     106    static std::once_flag onceFlag;
     107    std::call_once(onceFlag, [] {
     108#if PLATFORM(COCOA)
     109        proPhotoRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceROMMRGB);
     110#else
     111        proPhotoRGBColorSpace = sRGBColorSpaceRef();
     112#endif
     113    });
     114    return proPhotoRGBColorSpace;
     115}
     116
    103117CGColorSpaceRef rec2020ColorSpaceRef()
    104118{
  • trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h

    r272123 r272125  
    11/*
    2  * Copyright (C) 2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3737WEBCORE_EXPORT CGColorSpaceRef labColorSpaceRef();
    3838WEBCORE_EXPORT CGColorSpaceRef linearRGBColorSpaceRef();
     39WEBCORE_EXPORT CGColorSpaceRef proPhotoRGBColorSpaceRef();
    3940WEBCORE_EXPORT CGColorSpaceRef rec2020ColorSpaceRef();
    4041WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
     
    5152    case ColorSpace::LinearRGB:
    5253        return linearRGBColorSpaceRef();
     54    case ColorSpace::ProPhotoRGB:
     55        return proPhotoRGBColorSpaceRef();
    5356    case ColorSpace::Rec2020:
    5457        return rec2020ColorSpaceRef();
Note: See TracChangeset for help on using the changeset viewer.