Bug 268537 - Regression(251234@main): [Cairo][GTK][WPE] Darker output of SVG with filters fediffuselighting
Summary: Regression(251234@main): [Cairo][GTK][WPE] Darker output of SVG with filters ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Normal
Assignee: Przemyslaw Gorszkowski
URL:
Keywords: InRadar
Depends on: 234118
Blocks:
  Show dependency treegraph
 
Reported: 2024-02-01 03:23 PST by Przemyslaw Gorszkowski
Modified: 2024-02-21 04:24 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Przemyslaw Gorszkowski 2024-02-01 03:23:31 PST
The problem can be observed with output rendered in https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDiffuseLighting.
Comment 1 Przemyslaw Gorszkowski 2024-02-01 03:46:37 PST
Turn off the support for linearRGB color space in case of Cairo (https://bugs.webkit.org/show_bug.cgi?id=234118) causes that SVG with filter where linearRGB as inputs is demanded, generates darker output.

Actually the source image provided as initial input (SourceGraphic) should be in linearRGB color space, from the spec (https://www.w3.org/TR/filter-effects-1/#attr-valuedef-in-sourcegraphic):

"SourceGraphic. This built-in input represents the graphics elements that were the original input into the <filter> element. For raster effects processing nodes, the graphics elements will be rasterized into an initially clear RGBA raster in image space. Pixels left untouched by the original graphic will be left clear. The image is specified to be rendered in linear RGBA pixels. The alpha channel of this image captures any anti-aliasing specified by SVG. (Since the raster is linear, the alpha channel of this image will represent the exact percent coverage of each pixel.)"

But if we turn on support for linearRGB in case of Cairo we have problem with lighter outputs (observed in https://bugs.webkit.org/show_bug.cgi?id=234118).
Comment 2 Przemyslaw Gorszkowski 2024-02-01 03:54:31 PST
The reason of the lighter output with enabled support for linearRGB (in case of Cairo) is that the source image (SourceGraphic) when we create:

FilterImageTargetSwitcher::FilterImageTargetSwitcher(GraphicsContext& destinationContext, Filter& filter, const FloatRect &sourceImageRect, const DestinationColorSpace& colorSpace, FilterResults* results)
    : FilterTargetSwitcher(filter)
    , m_sourceImageRect(sourceImageRect)
    , m_results(results)
{
    if (sourceImageRect.isEmpty())
        return;

    m_sourceImage = destinationContext.createScaledImageBuffer(m_sourceImageRect, filter.filterScale(), colorSpace, filter.renderingMode());
    if (!m_sourceImage) {
        m_filter = nullptr;
        return;
    }

    auto state = destinationContext.state();
    m_sourceImage->context().mergeAllChanges(state);
}

we assume/pretend it will be in linearRGB but Cairo paints it with SRGB. 


To fix this in case of Cairo we should create m_sourceImage with SRGB color space and in FilterImageTargetSwitcher::endDrawSourceImage, before destinationContext.drawFilteredImageBuffer, transform its color space to linearRGB.
Comment 3 Przemyslaw Gorszkowski 2024-02-01 05:03:50 PST
Pull request: https://github.com/WebKit/WebKit/pull/23663
Comment 4 EWS 2024-02-21 04:23:10 PST
Committed 275091@main (cfa8125ddf7c): <https://commits.webkit.org/275091@main>

Reviewed commits have been landed. Closing PR #23663 and removing active labels.
Comment 5 Radar WebKit Bug Importer 2024-02-21 04:24:15 PST
<rdar://problem/123371014>