W3C home > Mailing lists > Public > public-css-archive@w3.org > June 2020

Re: [csswg-drafts] [css-color4] Precision issues when converting colors between Lab and sRGB (#5262)

From: Dan Burzo via GitHub <sysbot+gh@w3.org>
Date: Mon, 29 Jun 2020 16:21:11 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-651223980-1593447669-sysbot+gh@w3.org>
You might find [this thread](https://github.com/w3c/csswg-drafts/issues/2492) useful. I'm hard-pressed remembering the exact details, but you can look at the conversions in [culori](https://github.com/evercoder/culori). I think the errors in a rgb -> lab -> rgb roundtrip are now negligible, or at least don't produce a different hex code.

You can test with this sample code:

```js
let culori = require('culori');
let hex = culori.formatter('hex');

for (var r = 0; r <= 255; r++) {
    for (var g = 0; g <= 255; g++) {
        for (var b = 0; b <= 255; b++) {
            let c = {
                mode: 'rgb',
                r: r/255,
                g: g/255,
                b: b/255
            };
            let ret = culori.rgb(culori.lab(c));
            if (hex(c) !== hex(ret)) {
                console.log(hex(c), hex(ret));
            }
        }
    }
}
```

-- 
GitHub Notification of comment by danburzo
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5262#issuecomment-651223980 using your GitHub account
Received on Monday, 29 June 2020 16:21:12 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:42:09 UTC