Comments (8)
...since some of the math — such as conversion between color spaces, luminance computation etc. — is already in our codebase, we would want to use that code. apca-w3 uses slightly different constants & formulas.... which would make our implementation non-compliant (I think!).
Yes, APCA does not use the sRGB to XYZ of IEC, instead, APCA calculates "Estimated Screen Luminance" Which is intended to more correctly model a calibrated sRGB monitor. And this is important for some yet unreleased feaures that more specifically accommodate certain color vision issues.
As far as color spaces, as it is perceptual contrast, It's based around color spaces of physical monitors as opposed to theoretical spaces.
We have been talking about ways to reconcile with the "math convenience" methods, But I'm currently very swamped with other pressing matters.
IN THE MEANTIME
There is a variant that is designed to work with existing standard color maths—convert the color to
It is not polarity aware, and is a more general contrast math, But it is also much much simpler. Here's the repo:
https://github.com/Myndex/deltaphistar
from culori.
Hi @danburzo
Doh! I just saw this, but yes, that's it... Be aware there may be a change regarding DPS contrast in the next few months, mainly for tighter alignment with APCA light mode.
from culori.
Given APCA's license requirements around accuracy, correctness and up-to-dateness, as well as its current status as a work in progress, I don't see it as a good fit for inclusion in culori at the moment, but since culori itself is mostly a collection of functions, interoperation is fairly simple.
To obtain the Y (luminance) to pass to the contrast algorithm, you can use the wcagLuminance()
function.
import { wcagLuminance } from 'culori';
import { APCAcontrast } from 'apca-w3';
const textY = wcagLuminance('black');
const backgroundY = wcagLuminance('tomato');
const contrast = APCAcontrast(textY, backgroundY);
Note that culori's wcagLuminance
function is a bit different (but not fundamentally) from the equations proposed in apca-w3. You can use apca-w3
's sRGBtoY()
as an alternative computation that matches the exact formula.
from culori.
@danburzo thanks! I was not aware of the "non commercial" license. Such a strange decisions, especially for something like that
from culori.
@danburzo looks like there is a different license for the w3 version, that is more permissive: https://github.com/Myndex/apca-w3
from culori.
I was actually referring to the license for the w3 version :-).
To give an example, since some of the math — such as conversion between color spaces, luminance computation etc. — is already in our codebase, we would want to use that code. apca-w3 uses slightly different constants & formulas (see this w3c/silver issue), which would make our implementation non-compliant (I think!).
It really sounds like this should remain a separate library, at least until it gets merged in some form in w3 specs.
from culori.
Makes total sense. Thanks for clarifying.
from culori.
@Myndex thanks for the pointer! So that would basically be:
import { lab65 } from 'culori';
/*
Delta Phi Star perceptual lightness contrast by Andrew Somers:
https://github.com/Myndex/deltaphistar
*/
const PHI = 0.5 + Math.sqrt(1.25);
function dpsContrast(a, b) {
const dps = Math.abs(Math.pow(lab65(a).l, PHI) - Math.pow(lab65(b).l, PHI));
const contrast = Math.pow(dps, 1/PHI) * Math.SQRT2 - 40;
return contrast < 7.5 ? 0 : contrast;
}
from culori.
Related Issues (20)
- `lch()` and `lab()` in `formatCss` has no `%` HOT 3
- Culori ESM import throws an error in Next.js production build HOT 5
- Bug in displayable() in oklch HOT 3
- 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
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.