Skip to content

Lower CSS brightness/contrast/invert/opacity filters to ColorMatrix - #104

Merged
nicoburns merged 1 commit into
mainfrom
devin/1790703701-css-filters-colormatrix
Sep 30, 2026
Merged

nicoburns merged 1 commit into
mainfrom
devin/1790703701-css-filters-colormatrix

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

FilterEffect::{opacity, invert, brightness, contrast} now build FilterEffect::ColorMatrix (via new ColorMatrix::{opacity, invert, brightness, contrast} constructors) instead of FilterEffect::ComponentTransfer. hue_rotate/saturate/sepia/grayscale already work this way, so now every non-spatial CSS filter function lowers to the same primitive kind.

Why:

  • A matrix is how the spec defines these functions (Shorthand Equivalents).
  • It's exact in f32. The Skia backend turns ComponentTransfer into 8-bit lookup tables.
  • Backends only need one color pass, and adjacent color functions can be fused later.
  • Vello's CPU/GPU renderers are getting a ColorMatrix primitive (sparse_strips: Add ColorMatrix filter linebender/vello#1765) but have no ComponentTransfer, so this unblocks CSS filters on the vello backends.

Matrices (row-major 4x5, straight-alpha input [r, g, b, a, 1]):

fn R,G,B rows A row
brightness(a) slope a, offset 0 identity
contrast(a) slope a, offset 0.5 - 0.5a identity
invert(a) slope 1 - 2a, offset a identity
opacity(a) identity [0,0,0,a,0]

ComponentTransferFilter::{opacity, invert, brightness, contrast} and the ComponentTransfer variant are left alone because SVG feComponentTransfer still needs them. Backends are unchanged.

Tests: I added unit tests that apply each matrix to sample RGBA colors and compare the output with the spec formulas. They also check that the identity values (brightness(1), contrast(1), invert(0), opacity(1)) produce exactly ColorMatrix::IDENTITY.

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/d07362412f074435869c2e434653070f
Open in Devin Desktop: https://dioxus.staging.devinenterprise.com/desktop/session/d07362412f074435869c2e434653070f?variant=devin-insiders
Requested by: @nicoburns

@staging-devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@nicoburns
nicoburns merged commit 0b24559 into main Sep 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant