Title: [287982] trunk
Revision
287982
Author
[email protected]
Date
2022-01-13 10:58:47 -0800 (Thu, 13 Jan 2022)

Log Message

Referenced SVG filter uses always sRGB color space for its result
https://bugs.webkit.org/show_bug.cgi?id=235159

Reviewed by Simon Fraser.

Source/WebCore:

Do not setOperatingColorSpace() of the lastEffect() of the referenced
SVGFilter to DestinationColorSpace::SRGB(). This will have the pixels
of the result FilterImage of the lastEffect() in the color space which
is defined by the color-interpolation style of the effect SVGElement.

Test: css3/filters/reference-filter-color-space.html

* platform/graphics/filters/Filter.h:
* rendering/CSSFilter.cpp:
(WebCore::CSSFilter::create):
Move checking the CoreImage support to this function.

(WebCore::CSSFilter::buildFilterFunctions):
Remove resetting m_functions and m_outsets from this function since it
is now called only once from CSSFilter::create().

(WebCore::CSSFilter::lastEffect const): Deleted.
* rendering/CSSFilter.h:
* svg/graphics/filters/SVGFilter.h:

LayoutTests:

The new test defines a <feComponentTransfer> effect with linear component
functions. The values of these functions make the lookup tables have zeros
in the first 65 elements. The test applies the filter to a <div> with green
background.

-- With sRGB color-space, the green channel value is 0x80. So the value
   in the lookup table is not zero. So the result filter image in this
   case is a some green square.

-- With linearRGB color-space , the green channel value is 0x37. So the
   value in the lookup table is zero. So the result filter image in this
   case is a black square.

Because the color-space will be linearRGB, the expected test case should
have black squares.

* css3/filters/reference-filter-color-space-expected.html: Added.
* css3/filters/reference-filter-color-space.html: Added.

* css3/filters/reference-filter-set-filter-regions.html:
* fast/gradients/conic-gradient-alpha-unpremultiplied.html:
* fast/gradients/conic-gradient-extended-stops.html:
* fast/gradients/conic-gradient.html:
* fast/gradients/conic-repeating-last-stop.html:
* fast/hidpi/filters-turbulence.html:
Add color-interpolation-filters="sRGB" to get the old result so they match
the expected pages.

* platform/win/TestExpectations:
LinearSRGB color space is not supported on Windows.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (287981 => 287982)


--- trunk/LayoutTests/ChangeLog	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/ChangeLog	2022-01-13 18:58:47 UTC (rev 287982)
@@ -1,3 +1,41 @@
+2022-01-13  Said Abou-Hallawa  <[email protected]>
+
+        Referenced SVG filter uses always sRGB color space for its result
+        https://bugs.webkit.org/show_bug.cgi?id=235159
+
+        Reviewed by Simon Fraser.
+
+        The new test defines a <feComponentTransfer> effect with linear component
+        functions. The values of these functions make the lookup tables have zeros
+        in the first 65 elements. The test applies the filter to a <div> with green
+        background. 
+
+        -- With sRGB color-space, the green channel value is 0x80. So the value
+           in the lookup table is not zero. So the result filter image in this 
+           case is a some green square.
+
+        -- With linearRGB color-space , the green channel value is 0x37. So the
+           value in the lookup table is zero. So the result filter image in this
+           case is a black square. 
+
+        Because the color-space will be linearRGB, the expected test case should
+        have black squares.
+
+        * css3/filters/reference-filter-color-space-expected.html: Added.
+        * css3/filters/reference-filter-color-space.html: Added.
+
+        * css3/filters/reference-filter-set-filter-regions.html:
+        * fast/gradients/conic-gradient-alpha-unpremultiplied.html:
+        * fast/gradients/conic-gradient-extended-stops.html:
+        * fast/gradients/conic-gradient.html:
+        * fast/gradients/conic-repeating-last-stop.html:
+        * fast/hidpi/filters-turbulence.html:
+        Add color-interpolation-filters="sRGB" to get the old result so they match
+        the expected pages.
+
+        * platform/win/TestExpectations:
+        LinearSRGB color space is not supported on Windows.
+
 2022-01-13  Alan Bujtas  <[email protected]>
 
         REGRESSION (r278561): Right clicking a link selects the full line with unrelated text

Added: trunk/LayoutTests/css3/filters/reference-filter-color-space-expected.html (0 => 287982)


--- trunk/LayoutTests/css3/filters/reference-filter-color-space-expected.html	                        (rev 0)
+++ trunk/LayoutTests/css3/filters/reference-filter-color-space-expected.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -0,0 +1,13 @@
+<style>
+    .box {
+        width: 100px;
+        height: 100px;
+        display: inline-block;
+        background-color: black;
+    }
+</style>
+<body>
+    <div class="box"></div>
+    <div class="box"></div>
+    <div class="box"></div>
+</body>

Added: trunk/LayoutTests/css3/filters/reference-filter-color-space.html (0 => 287982)


--- trunk/LayoutTests/css3/filters/reference-filter-color-space.html	                        (rev 0)
+++ trunk/LayoutTests/css3/filters/reference-filter-color-space.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -0,0 +1,41 @@
+<style>
+    .box {
+        width: 100px;
+        height: 100px;
+        display: inline-block;
+        background-color: green;
+    }
+</style>
+<body>
+    <div class="box" style="filter: url(#component-transfer-1);"></div>
+    <div class="box" style="filter: url(#component-transfer-2);"></div>
+    <div class="box" style="filter: url(#component-transfer-3);"></div>
+    <br>
+    <svg>
+        <filter id="component-transfer-1">
+            <feComponentTransfer>
+                <feFuncR type="linear" slope="2" intercept="-0.5"/>
+                <feFuncG type="linear" slope="2" intercept="-0.5"/>
+                <feFuncB type="linear" slope="2" intercept="-0.5"/>
+            </feComponentTransfer>
+        </filter>
+    </svg>
+    <svg style="position: absolute; top: -99999px">
+        <filter id="component-transfer-2">
+            <feComponentTransfer>
+                <feFuncR type="linear" slope="2" intercept="-0.5"/>
+                <feFuncG type="linear" slope="2" intercept="-0.5"/>
+                <feFuncB type="linear" slope="2" intercept="-0.5"/>
+            </feComponentTransfer>
+        </filter>
+    </svg>
+    <svg style="display: none;">
+        <filter id="component-transfer-3">
+            <feComponentTransfer>
+                <feFuncR type="linear" slope="2" intercept="-0.5"/>
+                <feFuncG type="linear" slope="2" intercept="-0.5"/>
+                <feFuncB type="linear" slope="2" intercept="-0.5"/>
+            </feComponentTransfer>
+        </filter>
+    </svg>
+</body>

Modified: trunk/LayoutTests/css3/filters/reference-filter-set-filter-regions.html (287981 => 287982)


--- trunk/LayoutTests/css3/filters/reference-filter-set-filter-regions.html	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/css3/filters/reference-filter-set-filter-regions.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -18,7 +18,7 @@
         <filter id="filter">
             <feTurbulence type="turbulence" baseFrequency="0.01" numOctaves="1" seed="5" stitchTiles="stitch"/>
             <feColorMatrix type="saturate" values="0"/>
-            <feComponentTransfer>
+            <feComponentTransfer color-interpolation-filters="sRGB">
                 <feFuncR type="linear" slope="0" intercept="0"/>
                 <feFuncG type="linear" slope="0" intercept="0.5"/>
                 <feFuncB type="linear" slope="0" intercept="0"/>

Modified: trunk/LayoutTests/fast/gradients/conic-gradient-alpha-unpremultiplied.html (287981 => 287982)


--- trunk/LayoutTests/fast/gradients/conic-gradient-alpha-unpremultiplied.html	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/fast/gradients/conic-gradient-alpha-unpremultiplied.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -38,7 +38,7 @@
 <svg viewBox="0 0 700 100">
 <defs>
     <filter id="posterize" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox">
-        <feComponentTransfer>
+        <feComponentTransfer color-interpolation-filters="sRGB">
             <feFuncR type="discrete" tableValues="0 0.125 0.25 0.375 0.5 0.625 0.75 0.875"/>
             <feFuncG type="discrete" tableValues="0 0.125 0.25 0.375 0.5 0.625 0.75 0.875"/>
             <feFuncB type="discrete" tableValues="0 0.125 0.25 0.375 0.5 0.625 0.75 0.875"/>

Modified: trunk/LayoutTests/fast/gradients/conic-gradient-extended-stops.html (287981 => 287982)


--- trunk/LayoutTests/fast/gradients/conic-gradient-extended-stops.html	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/fast/gradients/conic-gradient-extended-stops.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -38,7 +38,7 @@
 <svg viewBox="0 0 700 100">
 <defs>
     <filter id="posterize" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox">
-        <feComponentTransfer>
+        <feComponentTransfer color-interpolation-filters="sRGB">
             <feFuncR type="discrete" tableValues="0 0.0625 0.125 0.1875 0.25 0.3125 0.375 0.4375 0.5 0.5625 0.625 0.6875 0.75 0.8125 0.875 0.9375"/>
             <feFuncG type="discrete" tableValues="0 0.0625 0.125 0.1875 0.25 0.3125 0.375 0.4375 0.5 0.5625 0.625 0.6875 0.75 0.8125 0.875 0.9375"/>
             <feFuncB type="discrete" tableValues="0 0.0625 0.125 0.1875 0.25 0.3125 0.375 0.4375 0.5 0.5625 0.625 0.6875 0.75 0.8125 0.875 0.9375"/>

Modified: trunk/LayoutTests/fast/gradients/conic-gradient.html (287981 => 287982)


--- trunk/LayoutTests/fast/gradients/conic-gradient.html	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/fast/gradients/conic-gradient.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -38,7 +38,7 @@
 <svg viewBox="0 0 700 100">
 <defs>
     <filter id="posterize" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox">
-        <feComponentTransfer>
+        <feComponentTransfer color-interpolation-filters="sRGB">
             <feFuncR type="discrete" tableValues="0 0.125 0.25 0.375 0.5 0.625 0.75 0.875"/>
             <feFuncG type="discrete" tableValues="0 0.125 0.25 0.375 0.5 0.625 0.75 0.875"/>
             <feFuncB type="discrete" tableValues="0 0.125 0.25 0.375 0.5 0.625 0.75 0.875"/>

Modified: trunk/LayoutTests/fast/gradients/conic-repeating-last-stop.html (287981 => 287982)


--- trunk/LayoutTests/fast/gradients/conic-repeating-last-stop.html	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/fast/gradients/conic-repeating-last-stop.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -27,7 +27,7 @@
 <svg viewBox="0 0 700 100">
 <defs>
     <filter id="posterize" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox">
-        <feComponentTransfer>
+        <feComponentTransfer color-interpolation-filters="sRGB">
             <feFuncR type="discrete" tableValues="0 1"/>
             <feFuncG type="discrete" tableValues="0 1"/>
             <feFuncB type="discrete" tableValues="0 1"/>

Modified: trunk/LayoutTests/fast/hidpi/filters-turbulence.html (287981 => 287982)


--- trunk/LayoutTests/fast/hidpi/filters-turbulence.html	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/fast/hidpi/filters-turbulence.html	2022-01-13 18:58:47 UTC (rev 287982)
@@ -11,7 +11,7 @@
     <div></div>
     <svg>
         <filter id="filter" x="0" y="0" width="100%" height="100%"> 
-            <feTurbulence type="fractalNoise" numOctaves="0" />
+            <feTurbulence type="fractalNoise" numOctaves="0" color-interpolation-filters="sRGB" />
         </filter>
   </svg>
 </body>

Modified: trunk/LayoutTests/platform/win/TestExpectations (287981 => 287982)


--- trunk/LayoutTests/platform/win/TestExpectations	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/LayoutTests/platform/win/TestExpectations	2022-01-13 18:58:47 UTC (rev 287982)
@@ -4791,4 +4791,7 @@
 
 webkit.org/b/235124 webanimations/frame-rate/animation-frame-rate.html [ Failure ]
 
-webkit.org/b/235126 webanimations/accelerated-animation-after-forward-filling-animation.html [ ImageOnlyFailure ]
\ No newline at end of file
+webkit.org/b/235126 webanimations/accelerated-animation-after-forward-filling-animation.html [ ImageOnlyFailure ]
+
+# LinearSRGB color space is not supported on Windows.
+css3/filters/reference-filter-color-space.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (287981 => 287982)


--- trunk/Source/WebCore/ChangeLog	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/Source/WebCore/ChangeLog	2022-01-13 18:58:47 UTC (rev 287982)
@@ -1,3 +1,30 @@
+2022-01-13  Said Abou-Hallawa  <[email protected]>
+
+        Referenced SVG filter uses always sRGB color space for its result
+        https://bugs.webkit.org/show_bug.cgi?id=235159
+
+        Reviewed by Simon Fraser.
+
+        Do not setOperatingColorSpace() of the lastEffect() of the referenced
+        SVGFilter to DestinationColorSpace::SRGB(). This will have the pixels
+        of the result FilterImage of the lastEffect() in the color space which
+        is defined by the color-interpolation style of the effect SVGElement.
+
+        Test: css3/filters/reference-filter-color-space.html
+
+        * platform/graphics/filters/Filter.h:
+        * rendering/CSSFilter.cpp:
+        (WebCore::CSSFilter::create):
+        Move checking the CoreImage support to this function.
+
+        (WebCore::CSSFilter::buildFilterFunctions):
+        Remove resetting m_functions and m_outsets from this function since it
+        is now called only once from CSSFilter::create().
+
+        (WebCore::CSSFilter::lastEffect const): Deleted.
+        * rendering/CSSFilter.h:
+        * svg/graphics/filters/SVGFilter.h:
+
 2022-01-13  Alan Bujtas  <[email protected]>
 
         REGRESSION (r278561): Right clicking a link selects the full line with unrelated text

Modified: trunk/Source/WebCore/platform/graphics/filters/Filter.h (287981 => 287982)


--- trunk/Source/WebCore/platform/graphics/filters/Filter.h	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/Source/WebCore/platform/graphics/filters/Filter.h	2022-01-13 18:58:47 UTC (rev 287982)
@@ -61,7 +61,6 @@
     FloatRect maxEffectRect(const FloatRect& primitiveSubregion) const;
     FloatRect clipToMaxEffectRect(const FloatRect& imageRect, const FloatRect& primitiveSubregion) const;
 
-    virtual RefPtr<FilterEffect> lastEffect() const = 0;
     virtual FilterEffectVector effectsOfType(FilterFunction::Type) const = 0;
 
     bool clampFilterRegionIfNeeded();

Modified: trunk/Source/WebCore/rendering/CSSFilter.cpp (287981 => 287982)


--- trunk/Source/WebCore/rendering/CSSFilter.cpp	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/Source/WebCore/rendering/CSSFilter.cpp	2022-01-13 18:58:47 UTC (rev 287982)
@@ -54,6 +54,10 @@
     if (!filter->buildFilterFunctions(renderer, operations, targetBoundingBox))
         return nullptr;
 
+#if USE(CORE_IMAGE)
+    if (!filter->supportsCoreImageRendering())
+        filter->setRenderingMode(RenderingMode::Unaccelerated);
+#endif
     return filter;
 }
 
@@ -237,14 +241,10 @@
 
 bool CSSFilter::buildFilterFunctions(RenderElement& renderer, const FilterOperations& operations, const FloatRect& targetBoundingBox)
 {
-    m_functions.clear();
-    m_outsets = { };
+    RefPtr<FilterEffect> effect;
+    RefPtr<SVGFilter> filter;
 
-    RefPtr<SVGFilter> filter;
-    
     for (auto& operation : operations.operations()) {
-        RefPtr<FilterEffect> effect;
-
         switch (operation->type()) {
         case FilterOperation::APPLE_INVERT_LIGHTNESS:
             ASSERT_NOT_REACHED(); // APPLE_INVERT_LIGHTNESS is only used in -apple-color-filter.
@@ -292,7 +292,6 @@
 
         case FilterOperation::REFERENCE:
             filter = createSVGFilter(*this, downcast<ReferenceFilterOperation>(*operation), renderer, targetBoundingBox);
-            effect = nullptr;
             break;
 
         default:
@@ -299,20 +298,16 @@
             break;
         }
 
-        if ((filter || effect) && m_functions.isEmpty())
+        if (!filter && !effect)
+            continue;
+
+        if (m_functions.isEmpty())
             m_functions.append(SourceGraphic::create());
-        
-        if (filter) {
-            effect = filter->lastEffect();
-            effect->setOperatingColorSpace(DestinationColorSpace::SRGB());
+
+        if (filter)
             m_functions.append(filter.releaseNonNull());
-            continue;
-        }
-
-        if (effect) {
-            effect->setOperatingColorSpace(DestinationColorSpace::SRGB());
+        else
             m_functions.append(effect.releaseNonNull());
-        }
     }
 
     // If we didn't make any effects, tell our caller we are not valid.
@@ -320,27 +315,9 @@
         return false;
 
     m_functions.shrinkToFit();
-
-#if USE(CORE_IMAGE)
-    if (!supportsCoreImageRendering())
-        setRenderingMode(RenderingMode::Unaccelerated);
-#endif
-
     return true;
 }
 
-RefPtr<FilterEffect> CSSFilter::lastEffect() const
-{
-    if (m_functions.isEmpty())
-        return nullptr;
-
-    auto& function = m_functions.last();
-    if (function->isSVGFilter())
-        return downcast<SVGFilter>(function.ptr())->lastEffect();
-
-    return downcast<FilterEffect>(function.ptr());
-}
-
 FilterEffectVector CSSFilter::effectsOfType(FilterFunction::Type filterType) const
 {
     FilterEffectVector effects;

Modified: trunk/Source/WebCore/rendering/CSSFilter.h (287981 => 287982)


--- trunk/Source/WebCore/rendering/CSSFilter.h	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/Source/WebCore/rendering/CSSFilter.h	2022-01-13 18:58:47 UTC (rev 287982)
@@ -50,7 +50,6 @@
     bool hasFilterThatMovesPixels() const { return m_hasFilterThatMovesPixels; }
     bool hasFilterThatShouldBeRestrictedBySecurityOrigin() const { return m_hasFilterThatShouldBeRestrictedBySecurityOrigin; }
 
-    RefPtr<FilterEffect> lastEffect() const final;
     FilterEffectVector effectsOfType(FilterFunction::Type) const final;
 
     IntOutsets outsets() const final;

Modified: trunk/Source/WebCore/svg/graphics/filters/SVGFilter.h (287981 => 287982)


--- trunk/Source/WebCore/svg/graphics/filters/SVGFilter.h	2022-01-13 18:21:34 UTC (rev 287981)
+++ trunk/Source/WebCore/svg/graphics/filters/SVGFilter.h	2022-01-13 18:58:47 UTC (rev 287982)
@@ -44,7 +44,6 @@
 
     const SVGFilterExpression& _expression_() const { return m_expression; }
     
-    RefPtr<FilterEffect> lastEffect() const final;
     FilterEffectVector effectsOfType(FilterFunction::Type) const final;
 
     RefPtr<FilterImage> apply(FilterImage* sourceImage, FilterResults&) final;
@@ -57,6 +56,8 @@
 
     void setExpression(SVGFilterExpression&& _expression_) { m_expression = WTFMove(_expression_); }
 
+    RefPtr<FilterEffect> lastEffect() const;
+
 #if USE(CORE_IMAGE)
     bool supportsCoreImageRendering() const final;
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to