Comments (2)
Hi Jeremy, thanks for the issue.
The results you’re seeing are caused by the fact that a roundtrip from sRGB to Oklch and back introduces subtle precision errors. They are, to some extent, unavoidable and unfortunately need to be actively managed depending on the usage.
I believe we are currently using the matrices from the original Oklab article, while the CSS Color Level 4 spec has updated them (see this discussion). It offers better roundtripping but does not completely eliminate these sort of small errors.
You may want to experiment with rounding these small values to a number of decimals that make practical sense for your use case. Culori has the culori.round()
helper for that:
import { round } from 'culori';
round(7)(0.9999999608276361); // => 1
(As a sidenote, you may also want to look at culori.mapper
as a way to apply round()
to all components in a color)
In the specific case of Oklch colors, you may want to consider colors with a very small chroma to be achromatic:
import { rgb, oklch } from 'culori';
const color = oklch(rgb(oklch('white')));
// => { mode: "oklch", l: 0.9999999934735458, c: 1.5700924586837752e-16, h: 135 }
// make color with infinitely small chroma achromatic.
if (color.c < 1e-8) {
color.c = 0;
delete color.h;
}
from culori.
Dan, thank you so much for your quick reply and for all of the helpful tips and code examples! A good bit to add to the documentation.
from culori.
Related Issues (20)
- culori.d.ts - Is there an updated type declaration file to use with TypeScript? HOT 1
- Implement parse-time clamping of L lab/oklab/lch/oklch
- XYB: is the Chroma from Luma adjustment correction really in the JXL implementation? HOT 2
- Interpolator throwing a NaN/undefined HOT 4
- Library-wide handling of missing and powerless components HOT 2
- Endless loop when using a double point HOT 2
- Add RYB colors HOT 19
- mix() function, and 2d/3d counterparts
- Dead link in docs HOT 1
- Precise chroma clamping in P3 color space HOT 2
- Suggestion to specify target gamut for clampChroma() HOT 1
- Provide ability to tree-shake parsers. HOT 2
- Adjust <number> parsing in HSL / HWB / etc(?) modern syntaxes to appropriate component ranges
- `'culori/fn'` regression in 4.0 HOT 3
- Switch tests from `tape` to native Node test runner
- Addition of CMYK color space HOT 1
- Add DIN99c/d color space HOT 6
- bug: add missing exports for blerp and trilerp HOT 3
- Consider updating Oklab matrices for better round-tripping
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from culori.