Skip to content

chromashift: model RGB colour spaces as first class values - #1553

Merged
keithamus merged 1 commit into
mainfrom
chromashift-model-rgb-colour-spaces-as-first-class-values
Oct 7, 2026
Merged

keithamus merged 1 commit into
mainfrom
chromashift-model-rgb-colour-spaces-as-first-class-values

Conversation

@keithamus

Copy link
Copy Markdown
Member

Currently we have seven near-identical RGB and XYZ modules, each with their own
inline matrix arithmetic and the sRGB curve was duplicated in four modules. This
also allowed drift.

This change completely reworks these into:

  • A Chromaticity type which models white points.
  • A generic Matrix3 type which allows for the various 3x3 transforms.
  • A Transfer type which encodes/decodes between linear light and a
    space's encoding.
  • An RgbSpace type which wraps all of these, defining a white point, transfer
    function, and two Matrices which determine how the type moves between
    encoded and CIE XYZ forms.

This comes with some behavioural changes:

  • a98-rgb convers primaries, so rebeccapurple is now (0.358 0.212
    0.584).
  • Gammut mapping is now per-destination not just sRGB.
  • Float-to-float conversions (e.g. oklab->lab) now no longer go through
    sRGB, which clamped them.

In doing so, this gets us closer to conceptual parts of the spec, such as the
reduction of colours to XYZ, but also exposes these parts for various ways to
re-apply colours (such as ICC profiles). In addition, it also allows us to
feature gate new rec2020/rec2020-bt1886 flags which flip between BT.2020
OETF (current engines) and BT.1886 2.4 Gamma defined in
w3c/csswg-drafts#12574.

@keithamus
keithamus enabled auto-merge (squash) October 6, 2026 17:36
Currently we have seven near-identical RGB and XYZ modules, each with their own
inline matrix arithmetic and the sRGB curve was duplicated in four modules. This
also allowed drift.

This change completely reworks these into:

- A `Chromaticity` type which models white points.
- A generic `Matrix3` type which allows for the various 3x3 transforms.
- A `Transfer` type which encodes/decodes between linear light and a
  space's encoding.
- An `RgbSpace` type which wraps all of these, defining a white point, transfer
  function, and two Matrices which determine how the type moves between
  encoded and CIE XYZ forms.

This comes with some behavioural changes:

- a98-rgb convers primaries, so rebeccapurple is now (0.358 0.212
  0.584).
- Gammut mapping is now per-destination not just sRGB.
- Float-to-float conversions (e.g. oklab->lab) now no longer go through
  sRGB, which clamped them.

In doing so, this gets us closer to conceptual parts of the spec, such as the
reduction of colours to XYZ, but also exposes these parts for various ways to
re-apply colours (such as ICC profiles). In addition, it also allows us to
feature gate new `rec2020`/`rec2020-bt1886` flags which flip between BT.2020
OETF (current engines) and BT.1886 2.4 Gamma defined in
w3c/csswg-drafts#12574.
@keithamus
keithamus force-pushed the chromashift-model-rgb-colour-spaces-as-first-class-values branch from be7767c to b35436a Compare October 7, 2026 09:32
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

✅ CI passed

Job Result
Build & Test (win32-x64, win32-arm64, linux-x64, linux-arm64, darwin-x64, darwin-arm64) ✅ success
Build & Test (default features) ✅ success
Build & Test (nightly) ✅ success
Build each library ✅ success
Build benches ✅ success
Acceptance Tests ✅ success
Fuzz Corpus Replay ✅ success
Wasm Build & JS Tests ✅ success
Napi Addon & JS Tests ✅ success
Generated File Drift ✅ success

@keithamus
keithamus merged commit 8bd11a1 into main Oct 7, 2026
38 of 40 checks passed
@keithamus
keithamus deleted the chromashift-model-rgb-colour-spaces-as-first-class-values branch October 7, 2026 12:03
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2026
## [0.0.35] - 2026-10-07

### Other Changes
- Chore(deps): update dependencies to v1.49.0 (#1546) ([#1546](#1546))

### Chromashift
- chromashift: model RGB colour spaces as first class values (#1553) ([#1553](#1553))

### Css_ast
- Regenerate css_ast/src/values from csswg drafts (#1545) ([#1545](#1545))

### Csskit_vscode
- chore(deps): update dependency @types/vscode to v1.140.0 (#1548) ([#1548](#1548))

[forcebuild]
@keithamus keithamus mentioned this pull request Oct 7, 2026
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2026
## [0.0.35] - 2026-10-07

### Other Changes
- Chore(deps): update dependencies to v1.49.0 (#1546) ([#1546](#1546))

### Chromashift
- chromashift: model RGB colour spaces as first class values (#1553) ([#1553](#1553))

### Css_ast
- Regenerate css_ast/src/values from csswg drafts (#1545) ([#1545](#1545))

### Csskit_vscode
- chore(deps): update dependency @types/vscode to v1.140.0 (#1548) ([#1548](#1548))
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2026
## [0.0.35] - 2026-10-07

### Other Changes
- Chore(deps): update dependencies to v1.49.0 (#1546) ([#1546](#1546))

### Chromashift
- chromashift: model RGB colour spaces as first class values (#1553) ([#1553](#1553))

### Css_ast
- Regenerate css_ast/src/values from csswg drafts (#1545) ([#1545](#1545))

### Csskit_vscode
- chore(deps): update dependency @types/vscode to v1.140.0 (#1548) ([#1548](#1548))

[forcebuild]
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2026
## [0.0.35] - 2026-10-07

### Other Changes
- Chore(deps): update dependencies to v1.49.0 (#1546) ([#1546](#1546))

### Chromashift
- chromashift: model RGB colour spaces as first class values (#1553) ([#1553](#1553))

### Css_ast
- Regenerate css_ast/src/values from csswg drafts (#1545) ([#1545](#1545))

### Csskit_vscode
- chore(deps): update dependency @types/vscode to v1.140.0 (#1548) ([#1548](#1548))
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2026
## [0.0.35] - 2026-10-07

### Other Changes
- Chore(deps): update dependencies to v1.49.0 (#1546) ([#1546](#1546))

### Chromashift
- chromashift: model RGB colour spaces as first class values (#1553) ([#1553](#1553))
- chromashift: Align serialisation to CSS Spec (#1555) ([#1555](#1555))

### Css_ast
- Regenerate css_ast/src/values from csswg drafts (#1545) ([#1545](#1545))

### Csskit_vscode
- chore(deps): update dependency @types/vscode to v1.140.0 (#1548) ([#1548](#1548))

[forcebuild]
github-actions Bot pushed a commit that referenced this pull request Oct 7, 2026
## [0.0.35] - 2026-10-07

### Other Changes
- Chore(deps): update dependencies to v1.49.0 (#1546) ([#1546](#1546))

### Chromashift
- chromashift: model RGB colour spaces as first class values (#1553) ([#1553](#1553))
- chromashift: Align serialisation to CSS Spec (#1555) ([#1555](#1555))

### Css_ast
- Regenerate css_ast/src/values from csswg drafts (#1545) ([#1545](#1545))

### Csskit_vscode
- chore(deps): update dependency @types/vscode to v1.140.0 (#1548) ([#1548](#1548))
keithamus added a commit that referenced this pull request Oct 11, 2026
## [0.0.35] - 2026-10-07

### Other Changes
- Chore(deps): update dependencies to v1.49.0 (#1546)
([#1546](#1546))


### Chromashift
- chromashift: model RGB colour spaces as first class values (#1553)
([#1553](#1553))
- chromashift: Align serialisation to CSS Spec (#1555)
([#1555](#1555))


### Css_ast
- Regenerate css_ast/src/values from csswg drafts (#1545)
([#1545](#1545))


### Csskit_vscode
- chore(deps): update dependency @types/vscode to v1.140.0 (#1548)
([#1548](#1548))
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