惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Engineering at Meta
Engineering at Meta
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
小众软件
小众软件
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
Last Week in AI
Last Week in AI
博客园_首页
I
InfoQ
T
Tailwind CSS Blog
爱范儿
爱范儿
雷峰网
雷峰网
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
B
Blog
WordPress大学
WordPress大学
A
About on SuperTechFans
V
Visual Studio Blog
有赞技术团队
有赞技术团队
P
Proofpoint News Feed

Lobsters

CIFSwitch: a non-universal Linux local root vulnerability RIPE NCC session fixation: poaching logins with an Atlas probe GNOME 2.20 but its Web Components Agentic Search for Context Engineering – Leonie Monigatti Garnix is shutting down [not OC] akashina.tngl.sh/jjc Concerning Emacs (and Jazz) Nitpicking the shell history scene in ‘Tron: Legacy’ What's cooking on SourceHut? Q2 2026 The tenth OpenPGP email summit Package managers that package package managers Clojure on Fennel part three: parsing WordPress at 23 Finding Miscompiles for Fun, Not Profit GitHub - creusot-rs/creusot: Creusot helps you prove your Rust code is correct. Announcing Rust 1.96.0 | Rust Blog A Love Letter to Neovim sqlite AGENTS.md Am I a Bad Friend? CSS vs. JavaScript • Josh W. Comeau Erlang Ecosystem Foundation - Supporting the BEAM community A brief note about slot access cost in Common Lisp Keyboard latency probe Rethinking the GNOME clipboard issues Back to the Building Blocks’ Building Blocks Tech Notes: Theseus: translating win32 to wasm Fast is better than slow Content-addressed Rust builds (or, what kache actually caches) Intent to Prototype: Embedding API Canada’s Bill C-22 and the security cost of collecting more data
GitHub - heavyrain266/colourspace: A pragmatic set of mod...
github.com b · 2026-05-31 · via Lobsters

A pragmatic set of modern colour space transforms

Overview

colourspace provides correct, minimal colour space transforms optimised for UI frameworks and creative tooling, covering OKLCh, OKLab, sRGB, Display P3, and Rec. 2020. Transforms are direct matrix multiplications with pre-computed matrices derived with tools/builder.odin. Perceptual manipulation and colour appearance work uses OKLab as the working space.

Gamut mapping is explicitly out of scope. Out-of-gamut values are passed through as-is, and handling is left to the caller — typically shader-side in a display pipeline.

High Dynamic Range (HDR) Support

Rec. 2020 alongside Perceptual Quantizer and Hybrid Log-Gamma transfer functions are kept behind a compile-time flag -define:COLOURSPACE_ENABLE_HDR.

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"
import cs "colourspace"


main :: proc() {
	// Construct colours
	lch:  cs.OKLCh       = cs.oklch(0.6456, 0.1003, 71.27)
	lab:  cs.OKLab       = cs.oklab(0.6456, 0.0337, 0.0942)
	srgb: cs.Linear_sRGB = cs.linear_srgb(0.5, 0.3, 0.1)
	p3:   cs.Linear_P3   = cs.linear_p3(0.5, 0.3, 0.1)

	// OKLab roundtrip
	linear_from_lch: cs.Linear_sRGB = cs.oklch_to_srgb(lch)
	lch_from_linear: cs.OKLCh       = cs.srgb_to_oklch(linear_from_lch)
	linear_from_lab: cs.Linear_sRGB = cs.oklab_to_srgb(lab)

	// Linear roundtrip
	p3_to_srgb: cs.Linear_sRGB = cs.p3_to_srgb(p3)
	srgb_to_p3: cs.Linear_P3   = cs.srgb_to_p3(srgb)

	// Gamma (de)compression
	decoded: cs.Linear_sRGB = cs.srgb_decode(cs.sRGB{0.5, 0.3, 0.1})
	encoded: cs.sRGB        = cs.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

International Color Consortium (ICC)

ITU-R (Rec. 2020)