Public
Edited
Feb 23, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
tristimulus = coords => ({
X: coords.x / coords.y,
Y: 1,
Z: (1 - coords.x - coords.y) / coords.y
})
Insert cell
/*
Compute the RGB to XYZ matrix for a color space,
relative to the specified illuminant.
Both arguments hold x/y chromaticities.
*/
compute_M = (colorSpace, illuminant) => {
// Compute XYZ tristimulus values for the
// color space primaries & reference white.
let r = tristimulus(colorSpace.r);
let g = tristimulus(colorSpace.g);
let b = tristimulus(colorSpace.b);
let W = tristimulus(illuminant);

let inv = invert([r.X, g.X, b.X, r.Y, g.Y, b.Y, r.Z, g.Z, b.Z]);
let S = [
inv[0] * W.X + inv[1] * W.Y + inv[2] * W.Z,
inv[3] * W.X + inv[4] * W.Y + inv[5] * W.Z,
inv[6] * W.X + inv[7] * W.Y + inv[8] * W.Z,
];
return [
S[0] * r.X, S[1] * g.X, S[2] * b.X,
S[0] * r.Y, S[1] * g.Y, S[2] * b.Y,
S[0] * r.Z, S[1] * g.Z, S[2] * b.Z
];
};
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more