Skip to content

Add gradient interpolation color space support (CSS Color Level 4) - #3775

Draft
mattleibow wants to merge 3 commits into
mainfrom
mattleibow/dev-gradient-interpolation-colorspace
Draft

Add gradient interpolation color space support (CSS Color Level 4)#3775
mattleibow wants to merge 3 commits into
mainfrom
mattleibow/dev-gradient-interpolation-colorspace

Conversation

@mattleibow

Copy link
Copy Markdown
Collaborator

Fixes #3773

Summary

Adds CSS Color Level 4 gradient interpolation support to SkiaSharp's gradient shader APIs, wrapping Skia's SkGradient::Interpolation.

New API surface

Type Description
SKGradientInterpolationColorSpace 11 color spaces: Destination, SrgbLinear, Lab, OKLab, OKLabGamutMap, LCH, OKLCH, OKLCHGamutMap, Srgb, HSL, HWB
SKGradientInterpolationHueMethod 4 hue methods: Shorter, Longer, Increasing, Decreasing
SKGradientInterpolation Struct with ColorSpace, HueMethod, InPremul fields
SKShader.CreateLinearGradient +2 overloads (±localMatrix) with interpolation
SKShader.CreateRadialGradient +2 overloads (±localMatrix) with interpolation
SKShader.CreateSweepGradient +2 overloads (±localMatrix) with interpolation
SKShader.CreateTwoPointConicalGradient +2 overloads (±localMatrix) with interpolation

Why

OKLab/OKLCH interpolation eliminates the muddy gray midpoints that plague sRGB gradient blending. Web platforms now default to OKLab (CSS Color Level 4). Display P3 and Rec2020 wide-gamut displays need proper color space interpolation.

Notes

Tests

39 tests covering all 4 gradient types, all 11 color spaces, all 4 hue methods, struct equality/defaults, premul, error cases, and a perceptual quality comparison (OKLab vs sRGB midpoint saturation).

Gallery sample

Updated GradientSample.cs with an "Interpolation Color Space" picker (9 non-experimental options).

mattleibow and others added 3 commits April 27, 2026 16:18
Add CSS Color Level 4 gradient interpolation to SkiaSharp's gradient shader APIs,
wrapping Skia's SkGradientShader::Interpolation (available since m114).

C API:
- sk_gradient_interpolation_colorspace_t enum (11 color spaces)
- sk_gradient_interpolation_huemethod_t enum (4 hue methods)
- sk_gradient_interpolation_t struct
- 4 new gradient functions with interpolation parameter

C# API:
- SKGradientInterpolationColorSpace enum (Destination, SrgbLinear, Lab, OKLab,
  OKLabGamutMap, LCH, OKLCH, OKLCHGamutMap, Srgb, HSL, HWB)
- SKGradientInterpolationHueMethod enum (Shorter, Longer, Increasing, Decreasing)
- SKGradientInterpolation struct
- New overloads on CreateLinearGradient, CreateRadialGradient,
  CreateSweepGradient, CreateTwoPointConicalGradient

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nt-interpolation-colorspace

# Conflicts:
#	externals/skia
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

Do not run these scripts without first reviewing the code in this PR.

Step 1 — Download the packages

bash / macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 3775

PowerShell / Windows:

iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 3775"

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-3775/packages --name skiasharp-pr-3775
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-3775

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[api] Add gradient interpolation color space support (CSS Color Level 4)

1 participant