feat(color): add ktsu.Semantics.Color (linear-RGB color science)#104
Merged
Conversation
Cross-task netstandard2.0 fixes in Color.Conversions.cs and Semantics.Color.csproj: - Replace byte.Parse(AsSpan) with Convert.ToByte(Substring, 16) (no CA1846, works on all TFMs) - Add System.Numerics.Vectors package reference for netstandard2.0 (Vector3/Vector4) - Add System.Numerics.Vectors version to Directory.Packages.props All 5 TFMs (net10.0, net9.0, net8.0, netstandard2.1, netstandard2.0) build clean; 39 Color tests pass.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
Adds
ktsu.Semantics.Color— a new dependency-light color-science package (multi-targetnet10/9/8+netstandard2.0/2.1), the first shippable unit of the color consolidation described indocs/roadmap-semantic-domains.md.The canonical type is
readonly partial record struct Color(double R, double G, double B, double A)storing linear RGB + straight alpha. Around it:Srgb,Hsl,Hsv,Oklab,Oklch; hex (#RGB/#RRGGBB/#RRGGBBAA) and 8-bit byte parsing (sRGB-interpreted).RelativeLuminance,ContrastRatio,AccessibilityLevel,AdjustForContrast.DistanceTo(Oklab),MixOklab,Lerp,Gradient.NamedColors(CSS/X11 subset) with case-insensitive lookup.The correctness fix
The existing ThemeProvider/ImGuiStyler color code fed sRGB values straight into the Oklab matrix and WCAG luminance (the structs were labelled "linear" but never gamma-decoded). This package confines the gamma transfer to the single
Srgb↔Colorboundary, so perceptual math always runs on linear values and "feed sRGB into Oklab" is unrepresentable through the API.hex → linear → sRGBround-trips to identity (pinned byGammaRegressionTests).ToSrgbVector4()(never a raw linear cast).Scope
Core package only. The
ktsu.ImGui.Coloradapter (ToImColor/ToImGuiVector4/ImGuiVector4, ImGuiApp repo) and thektsu.ThemeProvider/ktsu.ImGui.Stylermigrations are intentionally separate follow-on PRs in their own repos, once this publishes. Spec:docs/superpowers/specs/2026-06-29-semantics-color-design.md; plan:docs/superpowers/plans/2026-06-29-semantics-color.md.Verification
net10.0,net9.0,net8.0,netstandard2.1,netstandard2.0.netstandard2.0needs a conditionalSystem.Numerics.Vectorsreference (forVector3/4) and a sign-awareCbrt(noMath.Cbrt).Notes
1e-6, not1e-9: the published Ottosson forward/inverse matrices are independently-rounded and don't invert to exact identity (~1e-7). Non-Oklab conversions round-trip to ~1e-9.Follow-ups (non-blocking)
AdjustForContrasttest (lighten branch); gradient out-of-gamut doc/clamp decision; cacheNamedColorsas static readonly; broaden a few R-only test asserts.ktsu.ImGui.Colorlands: a cross-package smoke test thatToSrgbVector4is what reaches ImGui.🤖 Generated with Claude Code