GithubHelp home page GithubHelp logo

Comments (2)

danburzo avatar danburzo commented on June 3, 2024 1

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.

Jeremy-Knudsen avatar Jeremy-Knudsen commented on June 3, 2024 1

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.