GitHub - heavyrain266/colourspace: A pragmatic set of modern colour space transforms · GitHub
/" data-turbo-transient="true" />
Skip to content
Search or jump to...
Search code, repositories, users, issues, pull requests...
-->
Search
Clear
Search syntax tips
Provide feedback
--><br>We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contacted
Cancel
Submit feedback
Saved searches
Use saved searches to filter your results more quickly
-->
Name
Query
To see all available qualifiers, see our documentation.
Cancel
Create saved search
Sign in
/;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up
Appearance settings
Resetting focus
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
heavyrain266
colourspace
Public
Uh oh!
There was an error while loading. Please reload this page.
Notifications<br>You must be signed in to change notification settings
Fork
Star<br>15
main
BranchesTags
Go to file
CodeOpen more actions menu
Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit
History<br>8 Commits<br>8 Commits
.github
.github
LICENSE.txt
LICENSE.txt
README.md
README.md
colourspace.odin
colourspace.odin
gamma.odin
gamma.odin
linear_p3.odin
linear_p3.odin
linear_rec2020.odin
linear_rec2020.odin
linear_srgb.odin
linear_srgb.odin
oklab_cylindrical.odin
oklab_cylindrical.odin
oklab_p3.odin
oklab_p3.odin
oklab_rec2020.odin
oklab_rec2020.odin
oklab_srgb.odin
oklab_srgb.odin
types.odin
types.odin
View all files
Repository files navigation
colourspace
A pragmatic set of modern colour space transforms
Overview
colourspace provides correct, minimal colour space transforms for UI frameworks and creative tooling, covering OKLCh, OKLab, sRGB, Display P3, and Rec. 2020. Transforms between linear RGB spaces are direct matrix multiplications with pre-computed matrices. Perceptual manipulation and colour appearance work uses OKLab as the working space.
Gamut mapping (in progress) follows Björn Ottosson's cusp-projection approach rather than the chroma-reduction method in CSS Color Module 4, which produces hue drift on sRGB displays, most visibly P3 blues rendering as purple.
Quick Start
Construct colours in any covered space, convert between them freely, and encode for display. All conversions are hue-preserving and operate in linear light unless explicitly encoded.
package main
import "core:fmt"<br>import cs "colourspace"
main :: proc() {<br>// Construct colours<br>lch: cs.OKLCh = cs.oklch(0.6456, 0.1003, 71.27)<br>lab: cs.OKLab = cs.oklab(0.6456, 0.0337, 0.0942)<br>srgb: cs.Linear_sRGB = cs.linear_srgb(0.5, 0.3, 0.1)<br>p3: cs.Linear_P3 = cs.linear_p3(0.5, 0.3, 0.1)
// OKLab roundtrip<br>linear_from_lch: cs.Linear_sRGB = cs.oklch_to_srgb(lch)<br>lch_from_linear: cs.OKLCh = cs.srgb_to_oklch(linear_from_lch)<br>linear_from_lab: cs.Linear_sRGB = cs.oklab_to_srgb(lab)
// Linear roundtrip<br>p3_to_srgb: cs.Linear_sRGB = cs.p3_to_srgb(p3)<br>srgb_to_p3: cs.Linear_P3 = cs.srgb_to_p3(srgb)
// Gamma (de)compression<br>decoded: cs.Linear_sRGB = cs.srgb_decode(cs.sRGB{0.5, 0.3, 0.1})<br>encoded: cs.sRGB = cs.linear_srgb_encode(decoded)
fmt.println(linear_from_lch, lch_from_linear, linear_from_lab, p3_to_srgb, srgb_to_p3, decoded, encoded)
References
Björn Ottosson
A perceptual color space for image processing
Two new color spaces for color picking - Okhsv and Okhsl
sRGB gamut clipping
ITU-R (Rec. 2020)
Recommendation ITU-R BT.2020-2 - Parameter values for ultra-high definition television systems
W3C / CSS Working Group
CSS Color Module Level 4 - Specifying Lab and LCH
CSS Color Module Level 4 - Gamut Mapping
International Color Consortium
sRGB transfer function (IEC 61966-2-1)
About
A pragmatic set of modern colour space transforms
Resources
Readme
License
View license
Uh oh!
There was an error while loading. Please reload this page.
Activity
Stars
15<br>stars
Watchers
watching
Forks
forks
Report repository
Releases
No releases published
Sponsor this project
Sponsor
Uh oh!
There was an error while loading. Please reload this page.
Learn more about GitHub Sponsors
Contributors
Uh oh!
There was an error while loading. Please reload this page.
Languages
Odin<br>100.0%
You can’t perform that action at this time.