Skip to content

Commit 2a88934

Browse files
committed
[css-color-4] chromaticity utilities
1 parent b223ecb commit 2a88934

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

css-color-4/utilities.js

+34
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,38 @@ function naive_sRGB_to_CMYK(RGB) {
166166
var yellow = (black == 1.0)? 0: (1 - blue - black) / (1 - black);
167167

168168
return [cyan, magenta, yellow, black];
169+
}
170+
171+
// Chromaticity utilities
172+
173+
function XYZ_to_xy(XYZ) {
174+
// Convert an array of three XYZ values
175+
// to x,y chromaticity coordinates
176+
177+
var X = XYZ[0];
178+
var Y = XYZ[1];
179+
var Z = XYZ[2];
180+
var sum = X+Y+Z;
181+
return [X/sum, Y/sum];
182+
}
183+
184+
function xy_to_uv(xy) {
185+
// convert an x,y chromaticity pair
186+
// to u*,v* chromaticities
187+
188+
var x = xy[0];
189+
var y = xy[1];
190+
var denom = -2*x + 12*y +3;
191+
return [4*x / denom, 9*y / denom];
192+
}
193+
194+
function XYZ_to_uv(XYZ) {
195+
// Convert an array of three XYZ values
196+
// to u*,v* chromaticity coordinates
197+
198+
var X = XYZ[0];
199+
var Y = XYZ[1];
200+
var Z = XYZ[2];
201+
var denom = X + 15*Y +3*Z;
202+
return [4*X / denom, 9*Y / denom];
169203
}

0 commit comments

Comments
 (0)