{ RCSid $Id: cieluv.cal,v 1.4 2015/06/18 00:12:18 greg Exp $ }
{
	Compute Luv color space and color differences from XYZ primaries.

	5/4/98	G.W.Larson
}
Xw = 1; Yw = 1; Zw = 1;			{ default white }
sq(x) : x*x;
up(Xi,Yi,Zi) : 4*Xi/(Xi + 15*Yi + 3*Zi);
vp(Xi,Yi,Zi) : 9*Yi/(Xi + 15*Yi + 3*Zi);
up_neu : up(1,1,1);
vp_neu : vp(1,1,1);
uw = up(Xw,Yw,Zw);
vw = vp(Xw,Yw,Zw);
Ls(Yi) = if(Yi/Yw - .01, 116*(Yi/Yw)^(1/3) - 16, 903.3*Yi/Yw);
us(Xi,Yi,Zi) = 13*Ls(Yi)*(up(Xi,Yi,Zi) - uw);
vs(Xi,Yi,Zi) = 13*Ls(Yi)*(vp(Xi,Yi,Zi) - vw);
hue_deg(Xi,Yi,Zi) = 180/PI*atan2(vs(Xi,Yi,Zi),us(Xi,Yi,Zi));
sat_uv(Xi,Yi,Zi) = 13*sqrt(sq(up(Xi,Yi,Zi)-uw) + sq(vp(Xi,Yi,Zi)-vw));
dE(X1,Y1,Z1,X2,Y2,Z2) = sqrt(sq(Ls(Y1)-Ls(Y2)) + sq(us(X1,Y1,Z1)-us(X2,Y2,Z2))
				+ sq(vs(X1,Y1,Z1)-vs(X2,Y2,Z2)));
