Skip to content

[css-images-4] Rendering gradients with missing color components #9295

Open
@mysteryDate

Description

@mysteryDate

There is disagreement over interactions between the css-color-4 and css-images-4 specifications here: crbug.com/1462612. Specifically, what is the desired behavior color stops with missing components in gradients. For example:

linear-gradient(to right in srgb, color(srgb 1 0 0), color(srgb none 0 0), color(srgb 0 0 1)

Intuitively, I assumed that the red channel of the above gradient should interpolate as if the 2nd color stop were not there and thus would be a linear interpolation of the surrounding color stops:

linear-gradient(to right in srgb, color(srgb 1 0 0), color(srgb 0.5 0 0), color(srgb 0 0 1)

Screenshot 2023-09-02 at 11 33 08 AM

@brianosman Pointed out several things that are problematic with this approach at here:

From https://csswg.sesse.net/css-color-4/#interpolation-missing:

If a color with a carried forward missing component is interpolated with another color which is not missing that component, the missing component is treated as having the other color’s component value.

And from https://csswg.sesse.net/css-images-4/#coloring-gradient-line:

Between two color stops, the gradient line’s color is interpolated between the colors of the two color stops

From these two things @brianosman concluded that the color of any point on a gradient should be fully determined neighboring color stops and that "none"s should be resolved by splitting into two color stops and interpolating with the neighbors, resulting in:

linear-gradient(to right in srgb, color(srgb 1 0 0), color(srgb 1 0 0) 50%, color(srgb 0 0 1) 50%, color(srgb 0 0 1)

Screenshot 2023-09-02 at 11 39 57 AM

This, to me, seems intuitively like the incorrect result. What is the correct behavior? Can we clarify the spec?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions