2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.color.Colorspace"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.color.Colorspace"] = true;
|
|
|
3 |
dojo.provide("dojox.color.Colorspace");
|
|
|
4 |
dojo.require("dojox.math.matrix");
|
|
|
5 |
|
|
|
6 |
dojox.color.Colorspace=new (function(){
|
|
|
7 |
var dxc=dojox.color;
|
|
|
8 |
var dxm=dojox.math.matrix;
|
|
|
9 |
var self=this;
|
|
|
10 |
var wpMap={
|
|
|
11 |
"2":{
|
|
|
12 |
"E": { x:1/3, y:1/3, t:5400 },
|
|
|
13 |
"D50": { x:0.34567, y:0.3585, t:5000 },
|
|
|
14 |
"D55": { x:0.33242, y:0.34743, t:5500 },
|
|
|
15 |
"D65": { x:0.31271, y:0.32902, t:6500 },
|
|
|
16 |
"D75": { x:0.29902, y:0.31485, t:7500 },
|
|
|
17 |
"A": { x:0.44757, y:0.40745, t:2856 },
|
|
|
18 |
"B": { x:0.34842, y:0.35161, t:4874 },
|
|
|
19 |
"C": { x:0.31006, y:0.31616, t:6774 },
|
|
|
20 |
"9300": { x:0.2848, y:0.2932, t:9300 },
|
|
|
21 |
"F2": { x:0.37207, y:0.37512, t:4200 },
|
|
|
22 |
"F7": { x:0.31285, y:0.32918, t:6500 },
|
|
|
23 |
"F11": { x:0.38054, y:0.37691, t:4000 }
|
|
|
24 |
},
|
|
|
25 |
"10":{
|
|
|
26 |
"E": { x:1/3, y:1/3, t:5400 },
|
|
|
27 |
"D50": { x:0.34773, y:0.35952, t:5000 },
|
|
|
28 |
"D55": { x:0.33411, y:0.34877, t:5500 },
|
|
|
29 |
"D65": { x:0.31382, y:0.331, t:6500 },
|
|
|
30 |
"D75": { x:0.29968, y:0.3174, t:7500 },
|
|
|
31 |
"A": { x:0.45117, y:0.40594, t:2856 },
|
|
|
32 |
"B": { x:0.3498, y:0.3527, t:4874 },
|
|
|
33 |
"C": { x:0.31039, y:0.31905, t:6774 },
|
|
|
34 |
"F2": { x:0.37928, y:0.36723, t:4200 },
|
|
|
35 |
"F7": { x:0.31565, y:0.32951, t:6500 },
|
|
|
36 |
"F11": { x:0.38543, y:0.3711, t:4000 }
|
|
|
37 |
}
|
|
|
38 |
};
|
|
|
39 |
|
|
|
40 |
var profiles={
|
|
|
41 |
"Adobe RGB 98":[2.2, "D65", 0.64, 0.33, 0.297361, 0.21, 0.71, 0.627355, 0.15, 0.06, 0.075285],
|
|
|
42 |
"Apple RGB":[1.8, "D65", 0.625, 0.34, 0.244634, 0.28, 0.595, 0.672034, 0.155, 0.07, 0.083332],
|
|
|
43 |
"Best RGB":[2.2, "D50", 0.7347, 0.2653, 0.228457, 0.215, 0.775, 0.737352, 0.13, 0.035, 0.034191],
|
|
|
44 |
"Beta RGB":[2.2, "D50", 0.6888, 0.3112, 0.303273, 0.1986, 0.7551, 0.663786, 0.1265, 0.0352, 0.032941],
|
|
|
45 |
"Bruce RGB":[2.2, "D65", 0.64, 0.33, 0.240995, 0.28, 0.65, 0.683554, 0.15, 0.06, 0.075452],
|
|
|
46 |
"CIE RGB":[2.2, "E", 0.735, 0.265, 0.176204, 0.274, 0.717, 0.812985, 0.167, 0.009, 0.010811],
|
|
|
47 |
"ColorMatch RGB":[1.8, "D50", 0.63, 0.34, 0.274884, 0.295, 0.605, 0.658132, 0.15, 0.075, 0.066985],
|
|
|
48 |
"DON RGB 4":[2.2, "D50", 0.696, 0.3, 0.27835, 0.215, 0.765, 0.68797, 0.13, 0.035, 0.03368],
|
|
|
49 |
"ECI RGB":[1.8, "D50", 0.67, 0.33, 0.32025, 0.21, 0.71, 0.602071, 0.14, 0.08, 0.077679],
|
|
|
50 |
"EktaSpace PS5":[2.2, "D50", 0.695, 0.305, 0.260629, 0.26, 0.7, 0.734946, 0.11, 0.005, 0.004425],
|
|
|
51 |
"NTSC RGB":[2.2, "C", 0.67, 0.33, 0.298839, 0.21, 0.71, 0.586811, 0.14, 0.08, 0.11435],
|
|
|
52 |
"PAL/SECAM RGB":[2.2, "D65", 0.64, 0.33, 0.222021, 0.29, 0.6, 0.706645, 0.15, 0.06, 0.071334],
|
|
|
53 |
"Pro Photo RGB":[1.8, "D50", 0.7347, 0.2653, 0.28804, 0.1596, 0.8404, 0.711874, 0.0366, 0.0001, 0.000086],
|
|
|
54 |
"SMPTE/C RGB":[2.2, "D65", 0.63, 0.34, 0.212395, 0.31, 0.595, 0.701049, 0.155, 0.07, 0.086556],
|
|
|
55 |
"sRGB":[2.2, "D65", 0.64, 0.33, 0.212656, 0.3, 0.6, 0.715158, 0.15, 0.06, 0.072186],
|
|
|
56 |
"Wide Gamut RGB":[2.2, "D50", 0.735, 0.265, 0.258187, 0.115, 0.826, 0.724938, 0.157, 0.018, 0.016875]
|
|
|
57 |
};
|
|
|
58 |
|
|
|
59 |
var adaptors={
|
|
|
60 |
"XYZ scaling":{
|
|
|
61 |
ma: [[1,0,0], [0,1,0], [0,0,1]],
|
|
|
62 |
mai: [[1,0,0], [0,1,0], [0,0,1]]
|
|
|
63 |
},
|
|
|
64 |
"Bradford":{
|
|
|
65 |
ma: [[0.8951, -0.7502, 0.0389], [0.2664, 1.7135, -0.0685], [-0.1614, 0.0367, 1.0296]],
|
|
|
66 |
mai: [[0.986993, 0.432305, -0.008529], [-0.147054, 0.51836, 0.040043], [0.159963, 0.049291, 0.968487]]
|
|
|
67 |
},
|
|
|
68 |
"Von Kries":{
|
|
|
69 |
ma: [[0.40024, -0.2263, 0], [0.7076, 1.16532, 0], [-0.08081, 0.0457, 0.91822]],
|
|
|
70 |
mai: [[1.859936, 0.361191, 0], [-1.129382, 0.638812, 0], [0.219897, -0.000006, 1.089064]]
|
|
|
71 |
}
|
|
|
72 |
};
|
|
|
73 |
|
|
|
74 |
var cMaps={
|
|
|
75 |
"XYZ":{
|
|
|
76 |
"xyY":function(xyz, kwArgs){
|
|
|
77 |
kwArgs=dojo.mixin({
|
|
|
78 |
whitepoint:"D65",
|
|
|
79 |
observer:"10",
|
|
|
80 |
useApproximation:true
|
|
|
81 |
}, kwArgs||{});
|
|
|
82 |
var wp=self.whitepoint(kwArgs.whitepoint, kwArgs.observer);
|
|
|
83 |
var sum=xyz.X+xyz.Y+xyz.Z;
|
|
|
84 |
if(sum==0){ var x=wp.x, y=wp.y; }
|
|
|
85 |
else{ var x=xyz.X/sum, y=xyz.Y/sum; }
|
|
|
86 |
return { x:x, y:y, Y:xyz.Y };
|
|
|
87 |
},
|
|
|
88 |
"Lab":function(xyz, kwArgs){
|
|
|
89 |
kwArgs=dojo.mixin({
|
|
|
90 |
whitepoint:"D65",
|
|
|
91 |
observer:"10",
|
|
|
92 |
useApproximation:true
|
|
|
93 |
}, kwArgs||{});
|
|
|
94 |
|
|
|
95 |
var kappa=self.kappa(kwArgs.useApproximation), epsilon=self.epsilon(kwArgs.useApproximation);
|
|
|
96 |
var wp=self.whitepoint(kwArgs.whitepoint, kwArgs.observer);
|
|
|
97 |
var xr=xyz.X/wp.x, yr=xyz.Y/wp.y, zr=xyz.z/wp.z;
|
|
|
98 |
var fx=(xr>epsilon)?Math.pow(xr,1/3):(kappa*xr+16)/116;
|
|
|
99 |
var fy=(yr>epsilon)?Math.pow(yr,1/3):(kappa*yr+16)/116;
|
|
|
100 |
var fz=(zr>epsilon)?Math.pow(zr,1/3):(kappa*zr+16)/116;
|
|
|
101 |
var L=116*fy-16, a=500*(fx-fy), b=200*(fy-fz);
|
|
|
102 |
return { L:L, a:a, b:b };
|
|
|
103 |
},
|
|
|
104 |
"Luv": function(xyz, kwArgs){
|
|
|
105 |
kwArgs=dojo.mixin({
|
|
|
106 |
whitepoint:"D65",
|
|
|
107 |
observer:"10",
|
|
|
108 |
useApproximation:true
|
|
|
109 |
}, kwArgs||{});
|
|
|
110 |
|
|
|
111 |
var kappa=self.kappa(kwArgs.useApproximation), epsilon=self.epsilon(kwArgs.useApproximation);
|
|
|
112 |
var wp=self.whitepoint(kwArgs.whitepoint, kwArgs.observer);
|
|
|
113 |
var ud=(4*xyz.X)/(xyz.X+15*xyz.Y+3*xyz.Z);
|
|
|
114 |
var vd=(9*xyz.Y)/(xyz.X+15*xyz.Y+3*xyz.Z);
|
|
|
115 |
var udr=(4*wp.x)/(wp.x+15*wp.y+3*wp.z);
|
|
|
116 |
var vdr=(9*wp.y)/(wp.x+15*wp.y+3*wp.z);
|
|
|
117 |
var yr=xyz.Y/wp.y;
|
|
|
118 |
var L=(yr>epsilon)?116*Math.pow(yr, 1/3)-16:kappa*yr;
|
|
|
119 |
var u=13*L*(ud-udr);
|
|
|
120 |
var v=13*L*(vd-vdr);
|
|
|
121 |
return { L:L, u:u, v:v };
|
|
|
122 |
}
|
|
|
123 |
},
|
|
|
124 |
"xyY":{
|
|
|
125 |
"XYZ":function(xyY){
|
|
|
126 |
if(xyY.y==0){ var X=0, Y=0, Z=0; }
|
|
|
127 |
else{
|
|
|
128 |
var X=(xyY.x*xyY.Y)/xyY.y;
|
|
|
129 |
var Y=xyY.Y;
|
|
|
130 |
var Z=((1-xyY.x-xyY.y)*xyY.Y)/xyY.y;
|
|
|
131 |
}
|
|
|
132 |
return { X:X, Y:Y, Z:Z };
|
|
|
133 |
}
|
|
|
134 |
},
|
|
|
135 |
"Lab":{
|
|
|
136 |
"XYZ": function(lab, kwArgs){
|
|
|
137 |
kwArgs=dojo.mixin({
|
|
|
138 |
whitepoint:"D65",
|
|
|
139 |
observer:"10",
|
|
|
140 |
useApproximation:true
|
|
|
141 |
}, kwArgs||{});
|
|
|
142 |
|
|
|
143 |
var b=kwArgs.useApproximation, kappa=self.kappa(b), epsilon=self.epsilon(b);
|
|
|
144 |
var wp=self.whitepoint(kwArgs.whitepoint, kwArgs.observer);
|
|
|
145 |
var yr=(lab.L>(kappa*epsilon))?Math.pow((lab.L+16)/116, 3):lab.L/kappa;
|
|
|
146 |
var fy=(yr>epsilon)?(lab.L+16)/116:(kappa*yr+16)/116;
|
|
|
147 |
var fx=(lab.a/500)+fy;
|
|
|
148 |
var fz=fy-(lab.b/200);
|
|
|
149 |
var fxcube=Math.pow(fx, 3), fzcube=Math.pow(fz, 3);
|
|
|
150 |
var xr=(fxcube>epsilon)?fxcube:(116*fx-16)/kappa;
|
|
|
151 |
var zr=(fzcube>epsilon)?fzcube:(116*fz-16)/kappa;
|
|
|
152 |
return { X: xr*wp.x, Y: yr*wp.y, Z: zr*wp.z };
|
|
|
153 |
},
|
|
|
154 |
"LCHab": function(lab){
|
|
|
155 |
var L=lab.L, C=Math.pow(lab.a*lab.a+lab.b*lab.b, 0.5), H=Math.atan(lab.b, lab.a)*(180/Math.PI);
|
|
|
156 |
if(H<0){ H+=360; }
|
|
|
157 |
if(H<360){ H-=360; }
|
|
|
158 |
return { L:L, C:C, H:H };
|
|
|
159 |
}
|
|
|
160 |
},
|
|
|
161 |
"LCHab":{
|
|
|
162 |
"Lab":function(lch){
|
|
|
163 |
var hRad=lch.H*(Math.PI/180), L=lch.L, a=lch.C/Math.pow(Math.pow(Math.tan(hRad),2)+1, 0.5);
|
|
|
164 |
if(90<lchH && lch.H<270){ a = -a; }
|
|
|
165 |
var b=Math.pow(Math.pow(lch.C,2)-Math.pow(a, 2), 0.5);
|
|
|
166 |
if(lch.H>180){ b = -b; }
|
|
|
167 |
return { L: L, a:a, b:b };
|
|
|
168 |
}
|
|
|
169 |
},
|
|
|
170 |
"Luv":{
|
|
|
171 |
"XYZ": function(Luv, kwArgs){
|
|
|
172 |
kwArgs=dojo.mixin({
|
|
|
173 |
whitepoint:"D65",
|
|
|
174 |
observer:"10",
|
|
|
175 |
useApproximation:true
|
|
|
176 |
}, kwArgs||{});
|
|
|
177 |
|
|
|
178 |
var b=kwArgs.useApproximation, kappa=self.kappa(b), epsilon=self.epsilon(b);
|
|
|
179 |
var wp=self.whitepoint(kwArgs.whitepoint, kwArgs.observer);
|
|
|
180 |
var uz=(4*wp.x)/(wp.x+15*wp.y+3*wp.z);
|
|
|
181 |
var vz=(9*wp.y)/(wp.x+15*wp.y+3*wp.z);
|
|
|
182 |
var Y=(Luv.L>kappa*epsilon)?Math.pow((Luv.L+16)/116, 3):Luv.L/kappa;
|
|
|
183 |
var a=(1/3)*(((52*Luv.L)/(Luv.u+13*Luv.L*uz))-1);
|
|
|
184 |
var b=-5*Y, c=-(1/3), d=Y*(((39*Luv.L)/(Luv.v+13*Luv.L*vz))-5);
|
|
|
185 |
var X=(d-b)/(a-c), Z=X*a+b;
|
|
|
186 |
return { X:X, Y:Y, Z:Z };
|
|
|
187 |
},
|
|
|
188 |
"LCHuv": function(Luv){
|
|
|
189 |
var L=Luv.L, C=Math.pow(Luv.u*Luv.u+Luv.v*Luv*v, 0.5), H=Math.atan(Luv.v, Luv.u)*(180/Math.PI);
|
|
|
190 |
if(H<0){ H+=360; }
|
|
|
191 |
if(H>360){ H-=360; }
|
|
|
192 |
return { L:L, C:C, H:H };
|
|
|
193 |
}
|
|
|
194 |
},
|
|
|
195 |
"LCHuv":{
|
|
|
196 |
"Luv": function(LCH){
|
|
|
197 |
var hRad=LCH.H*(Math.PI/180);
|
|
|
198 |
var L=LCH.L, u=LCH.C/Math.pow(Math.pow(Math.tan(hRad),2)+1, 0.5);
|
|
|
199 |
var v=Math.pow(LCH.C*LCH.C-u*u, 0.5);
|
|
|
200 |
if(90<LCH.H && LCH.H>270){ u*=-1; }
|
|
|
201 |
if(LCH.H>180){ v*=-1; }
|
|
|
202 |
return { L:L, u:u, v:v };
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
};
|
|
|
206 |
var converters={
|
|
|
207 |
"CMY":{
|
|
|
208 |
"CMYK":function(obj, kwArgs){ return dxc.fromCmy(obj).toCmyk(); },
|
|
|
209 |
"HSL":function(obj, kwArgs){ return dxc.fromCmy(obj).toHsl(); },
|
|
|
210 |
"HSV":function(obj, kwArgs){ return dxc.fromCmy(obj).toHsv(); },
|
|
|
211 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](dxc.fromCmy(obj).toXYZ(kwArgs)); },
|
|
|
212 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](converters["CMY"]["Lab"](obj)); },
|
|
|
213 |
"LCHuv":function(obj, kwArgs){ return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc.fromCmy(obj).toXYZ(kwArgs))); },
|
|
|
214 |
"Luv":function(obj, kwArgs){ return cMaps["Luv"]["XYZ"](dxc.fromCmy(obj).toXYZ(kwArgs)); },
|
|
|
215 |
"RGB":function(obj, kwArgs){ return dxc.fromCmy(obj); },
|
|
|
216 |
"XYZ":function(obj, kwArgs){ return dxc.fromCmy(obj).toXYZ(kwArgs); },
|
|
|
217 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](dxc.fromCmy(obj).toXYZ(kwArgs)); }
|
|
|
218 |
},
|
|
|
219 |
"CMYK":{
|
|
|
220 |
"CMY":function(obj, kwArgs){ return dxc.fromCmyk(obj).toCmy(); },
|
|
|
221 |
"HSL":function(obj, kwArgs){ return dxc.fromCmyk(obj).toHsl(); },
|
|
|
222 |
"HSV":function(obj, kwArgs){ return dxc.fromCmyk(obj).toHsv(); },
|
|
|
223 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](dxc.fromCmyk(obj).toXYZ(kwArgs)); },
|
|
|
224 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](converters["CMYK"]["Lab"](obj)); },
|
|
|
225 |
"LCHuv":function(obj, kwArgs){ return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc.fromCmyk(obj).toXYZ(kwArgs))); },
|
|
|
226 |
"Luv":function(obj, kwArgs){ return cMaps["Luv"]["XYZ"](dxc.fromCmyk(obj).toXYZ(kwArgs)); },
|
|
|
227 |
"RGB":function(obj, kwArgs){ return dxc.fromCmyk(obj); },
|
|
|
228 |
"XYZ":function(obj, kwArgs){ return dxc.fromCmyk(obj).toXYZ(kwArgs); },
|
|
|
229 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](dxc.fromCmyk(obj).toXYZ(kwArgs)); }
|
|
|
230 |
},
|
|
|
231 |
"HSL":{
|
|
|
232 |
"CMY":function(obj, kwArgs){ return dxc.fromHsl(obj).toCmy(); },
|
|
|
233 |
"CMYK":function(obj, kwArgs){ return dxc.fromHsl(obj).toCmyk(); },
|
|
|
234 |
"HSV":function(obj, kwArgs){ return dxc.fromHsl(obj).toHsv(); },
|
|
|
235 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](dxc.fromHsl(obj).toXYZ(kwArgs)); },
|
|
|
236 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](converters["CMYK"]["Lab"](obj)); },
|
|
|
237 |
"LCHuv":function(obj, kwArgs){ return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc.fromHsl(obj).toXYZ(kwArgs))); },
|
|
|
238 |
"Luv":function(obj, kwArgs){ return cMaps["Luv"]["XYZ"](dxc.fromHsl(obj).toXYZ(kwArgs)); },
|
|
|
239 |
"RGB":function(obj, kwArgs){ return dxc.fromHsl(obj); },
|
|
|
240 |
"XYZ":function(obj, kwArgs){ return dxc.fromHsl(obj).toXYZ(kwArgs); },
|
|
|
241 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](dxc.fromHsl(obj).toXYZ(kwArgs)); }
|
|
|
242 |
},
|
|
|
243 |
"HSV":{
|
|
|
244 |
"CMY":function(obj, kwArgs){ return dxc.fromHsv(obj).toCmy(); },
|
|
|
245 |
"CMYK":function(obj, kwArgs){ return dxc.fromHsv(obj).toCmyk(); },
|
|
|
246 |
"HSL":function(obj, kwArgs){ return dxc.fromHsv(obj).toHsl(); },
|
|
|
247 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](dxc.fromHsv(obj).toXYZ(kwArgs)); },
|
|
|
248 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](converters["CMYK"]["Lab"](obj)); },
|
|
|
249 |
"LCHuv":function(obj, kwArgs){ return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc.fromHsv(obj).toXYZ(kwArgs))); },
|
|
|
250 |
"Luv":function(obj, kwArgs){ return cMaps["Luv"]["XYZ"](dxc.fromHsv(obj).toXYZ(kwArgs)); },
|
|
|
251 |
"RGB":function(obj, kwArgs){ return dxc.fromHsv(obj); },
|
|
|
252 |
"XYZ":function(obj, kwArgs){ return dxc.fromHsv(obj).toXYZ(kwArgs); },
|
|
|
253 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](dxc.fromHsv(obj).toXYZ(kwArgs)); }
|
|
|
254 |
},
|
|
|
255 |
"Lab":{
|
|
|
256 |
"CMY":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs)).toCmy(); },
|
|
|
257 |
"CMYK":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs)).toCmyk(); },
|
|
|
258 |
"HSL":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs)).toHsl(); },
|
|
|
259 |
"HSV":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs)).toHsv(); },
|
|
|
260 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](obj, kwArgs); },
|
|
|
261 |
"LCHuv":function(obj, kwArgs){ return cMaps["Luv"]["LCHuv"](cMaps["Lab"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
262 |
"Luv":function(obj, kwArgs){ return cMaps["XYZ"]["Luv"](cMaps["Lab"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
263 |
"RGB":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs)); },
|
|
|
264 |
"XYZ":function(obj, kwArgs){ return cMaps["Lab"]["XYZ"](obj, kwArgs); },
|
|
|
265 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](cMaps["Lab"]["XYZ"](obj, kwArgs), kwArgs); }
|
|
|
266 |
},
|
|
|
267 |
"LCHab":{
|
|
|
268 |
"CMY":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs).toCmy(); },
|
|
|
269 |
"CMYK":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs).toCmyk(); },
|
|
|
270 |
"HSL":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs).toHsl(); },
|
|
|
271 |
"HSV":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs).toHsv(); },
|
|
|
272 |
"Lab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](obj, kwArgs); },
|
|
|
273 |
"LCHuv":function(obj, kwArgs){ return cMaps["Luv"]["LCHuv"](cMaps["XYZ"]["Luv"](cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs), kwArgs);},
|
|
|
274 |
"Luv":function(obj, kwArgs){ return cMaps["XYZ"]["Luv"](cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs);},
|
|
|
275 |
"RGB":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs); },
|
|
|
276 |
"XYZ":function(obj, kwArgs){ return cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj, kwArgs), kwArgs); },
|
|
|
277 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs); }
|
|
|
278 |
},
|
|
|
279 |
"LCHuv":{
|
|
|
280 |
"CMY":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs).toCmy(); },
|
|
|
281 |
"CMYK":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs).toCmyk(); },
|
|
|
282 |
"HSL":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs).toHsl(); },
|
|
|
283 |
"HSV":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs).toHsv(); },
|
|
|
284 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs); },
|
|
|
285 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](cMaps["XYZ"]["Lab"](cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs), kwArgs); },
|
|
|
286 |
"Luv":function(obj, kwArgs){ return cMaps["LCHuv"]["Luv"](obj, kwArgs); },
|
|
|
287 |
"RGB":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs); },
|
|
|
288 |
"XYZ":function(obj, kwArgs){ return cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs); },
|
|
|
289 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs); },
|
|
|
290 |
},
|
|
|
291 |
"Luv":{
|
|
|
292 |
"CMY":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs).toCmy(); },
|
|
|
293 |
"CMYK":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs).toCmyk(); },
|
|
|
294 |
"HSL":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs).toHsl(); },
|
|
|
295 |
"HSV":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs).toHsv(); },
|
|
|
296 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
297 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](cMaps["XYZ"]["Lab"](cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs), kwArgs); },
|
|
|
298 |
"LCHuv":function(obj, kwArgs){ return cMaps["Luv"]["LCHuv"](obj, kwArgs); },
|
|
|
299 |
"RGB":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
300 |
"XYZ":function(obj, kwArgs){ return cMaps["Luv"]["XYZ"](obj, kwArgs); },
|
|
|
301 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
302 |
},
|
|
|
303 |
"RGB":{
|
|
|
304 |
"CMY":function(obj, kwArgs){ return obj.toCmy(); },
|
|
|
305 |
"CMYK":function(obj, kwArgs){ return obj.toCmyk(); },
|
|
|
306 |
"HSL":function(obj, kwArgs){ return obj.toHsl(); },
|
|
|
307 |
"HSV":function(obj, kwArgs){ return obj.toHsv(); },
|
|
|
308 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](obj.toXYZ(kwArgs), kwArgs); },
|
|
|
309 |
"LCHab":function(obj, kwArgs){ return cMaps["LCHab"]["Lab"](cMaps["XYZ"]["Lab"](obj.toXYZ(kwArgs), kwArgs), kwArgs);},
|
|
|
310 |
"LCHuv":function(obj, kwArgs){ return cMaps["LCHuv"]["Luv"](cMaps["XYZ"]["Luv"](obj.toXYZ(kwArgs), kwArgs), kwArgs);},
|
|
|
311 |
"Luv":function(obj, kwArgs){ return cMaps["XYZ"]["Luv"](obj.toXYZ(kwArgs), kwArgs); },
|
|
|
312 |
"XYZ":function(obj, kwArgs){ return obj.toXYZ(kwArgs); },
|
|
|
313 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](obj.toXYZ(kwArgs), kwArgs); }
|
|
|
314 |
},
|
|
|
315 |
"XYZ":{
|
|
|
316 |
"CMY":function(obj, kwArgs){ return dxc.fromXYZ(obj, kwArgs).toCmy(); },
|
|
|
317 |
"CMYK":function(obj, kwArgs){ return dxc.fromXYZ(obj, kwArgs).toCmyk(); },
|
|
|
318 |
"HSL":function(obj, kwArgs){ return dxc.fromXYZ(obj, kwArgs).toHsl(); },
|
|
|
319 |
"HSV":function(obj, kwArgs){ return dxc.fromXYZ(obj, kwArgs).toHsv(); },
|
|
|
320 |
"Lab":function(obj, kwArgs){ return cMaps["XYZ"]["Lab"](obj, kwArgs); },
|
|
|
321 |
"LCHab":function(obj, kwArgs){ return cMaps["Lab"]["LCHab"](cMaps["XYZ"]["Lab"](obj, kwArgs), kwArgs); },
|
|
|
322 |
"LCHuv":function(obj, kwArgs){ return cMaps["Luv"]["LCHuv"](cMaps["XYZ"]["Luv"](obj, kwArgs), kwArgs); },
|
|
|
323 |
"Luv":function(obj, kwArgs){ return cMaps["XYZ"]["Luv"](obj, kwArgs); },
|
|
|
324 |
"RGB":function(obj, kwArgs){ return dxc.fromXYZ(obj, kwArgs); },
|
|
|
325 |
"xyY":function(obj, kwArgs){ return cMaps["XYZ"]["xyY"](dxc.fromXYZ(obj, kwArgs), kwArgs); }
|
|
|
326 |
},
|
|
|
327 |
// TODO: revisit this. xyY represents a single color, not a spectrum of colors.
|
|
|
328 |
"xyY":{
|
|
|
329 |
"CMY":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs).toCmy(); },
|
|
|
330 |
"CMYK":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs).toCmyk(); },
|
|
|
331 |
"HSL":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs).toHsl(); },
|
|
|
332 |
"HSV":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs).toHsv(); },
|
|
|
333 |
"Lab":function(obj, kwArgs){ return cMaps["Lab"]["XYZ"](cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
334 |
"LCHab":function(obj, kwArgs){ return cMaps["LCHab"]["Lab"](cMaps["Lab"]["XYZ"](cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs), kwArgs); },
|
|
|
335 |
"LCHuv":function(obj, kwArgs){ return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs), kwArgs); },
|
|
|
336 |
"Luv":function(obj, kwArgs){ return cMaps["Luv"]["XYZ"](cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
337 |
"RGB":function(obj, kwArgs){ return dxc.fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs); },
|
|
|
338 |
"XYZ":function(obj, kwArgs){ return cMaps["xyY"]["XYZ"](obj, kwArgs); }
|
|
|
339 |
}
|
|
|
340 |
};
|
|
|
341 |
|
|
|
342 |
this.whitepoint=function(/* String */wpName, /* String? */observer){
|
|
|
343 |
observer=observer||"10";
|
|
|
344 |
var x=0, y=0, t=0;
|
|
|
345 |
if(wpMap[observer] && wpMap[observer][wpName]){
|
|
|
346 |
x=wpMap[observer][wpName].x;
|
|
|
347 |
y=wpMap[observer][wpName].y;
|
|
|
348 |
t=wpMap[observer][wpName].t;
|
|
|
349 |
} else {
|
|
|
350 |
console.warn(
|
|
|
351 |
"dojox.color.Colorspace::whitepoint: either the observer or the whitepoint name was not found. ",
|
|
|
352 |
observer, wpName
|
|
|
353 |
);
|
|
|
354 |
}
|
|
|
355 |
var wp={ x:x, y:y, z:(1-x-y), t:t, Y:1 };
|
|
|
356 |
return this.convert(wp, "xyY", "XYZ");
|
|
|
357 |
};
|
|
|
358 |
|
|
|
359 |
this.tempToWhitepoint=function(/* Number */t){
|
|
|
360 |
if(t<4000){
|
|
|
361 |
console.warn("dojox.color.Colorspace::tempToWhitepoint: can't find a white point for temperatures less than 4000K. (Passed ", t, ").");
|
|
|
362 |
return { x:0, y:0 };
|
|
|
363 |
}
|
|
|
364 |
if(t>25000){
|
|
|
365 |
console.warn("dojox.color.Colorspace::tempToWhitepoint: can't find a white point for temperatures greater than 25000K. (Passed ", t, ").");
|
|
|
366 |
return { x:0, y:0 };
|
|
|
367 |
}
|
|
|
368 |
var t1=t, t2=t*t, t3=t2*t;
|
|
|
369 |
var ten9=Math.pow(10, 9), ten6=Math.pow(10, 6), ten3=Math.pow(10,3);
|
|
|
370 |
if(t<=7000){
|
|
|
371 |
var x=(-4.607*ten9/t3)+(2.9678*ten6/t2)+(0.09911*ten3/t)+0.2444063;
|
|
|
372 |
} else {
|
|
|
373 |
var x=(-2.0064*ten9/t3)+(1.9018*ten6/t2)+(0.24748*ten3/t)+0.23704;
|
|
|
374 |
}
|
|
|
375 |
var y=-3*x*x+2.87*x-0.275;
|
|
|
376 |
return { x:x, y:y };
|
|
|
377 |
};
|
|
|
378 |
|
|
|
379 |
this.primaries=function(/* Object */kwArgs){
|
|
|
380 |
// mix in the defaults.
|
|
|
381 |
kwArgs=dojo.mixin({
|
|
|
382 |
profile:"sRGB",
|
|
|
383 |
whitepoint:"D65",
|
|
|
384 |
observer:"10",
|
|
|
385 |
adaptor:"Bradford"
|
|
|
386 |
}, kwArgs||{});
|
|
|
387 |
|
|
|
388 |
var m=[];
|
|
|
389 |
if(profiles[kwArgs.profile]){
|
|
|
390 |
m=profiles[kwArgs.profile].slice(0);
|
|
|
391 |
} else {
|
|
|
392 |
console.warn(
|
|
|
393 |
"dojox.color.Colorspace::primaries: the passed profile was not found. ",
|
|
|
394 |
"Available profiles include: ", profiles,
|
|
|
395 |
". The profile passed was ", kwArgs.profile
|
|
|
396 |
);
|
|
|
397 |
}
|
|
|
398 |
var primary={
|
|
|
399 |
name:kwArgs.profile,
|
|
|
400 |
gamma:m[0], whitepoint:m[1],
|
|
|
401 |
xr:m[2], yr:m[3], Yr:m[4],
|
|
|
402 |
xg:m[5], yg:m[6], Yg:m[7],
|
|
|
403 |
xb:m[8], yb:m[9], Yb:m[10]
|
|
|
404 |
};
|
|
|
405 |
|
|
|
406 |
// convert for the whitepoint
|
|
|
407 |
if(kwArgs.whitepoint!=primary.whitepoint){
|
|
|
408 |
var r=this.convert(
|
|
|
409 |
this.adapt({
|
|
|
410 |
color:this.convert({ x:xr, y:yr, Y:Yr }, "xyY", "XYZ"),
|
|
|
411 |
adaptor:kwArgs.adaptor,
|
|
|
412 |
source:primary.whitepoint,
|
|
|
413 |
destination:kwArgs.whitepoint
|
|
|
414 |
}),
|
|
|
415 |
"XYZ",
|
|
|
416 |
"xyY"
|
|
|
417 |
);
|
|
|
418 |
var g=this.convert(
|
|
|
419 |
this.adapt({
|
|
|
420 |
color:this.convert({ x:xg, y:yg, Y:Yg }, "xyY", "XYZ"),
|
|
|
421 |
adaptor:kwArgs.adaptor,
|
|
|
422 |
source:primary.whitepoint,
|
|
|
423 |
destination:kwArgs.whitepoint
|
|
|
424 |
}),
|
|
|
425 |
"XYZ",
|
|
|
426 |
"xyY"
|
|
|
427 |
);
|
|
|
428 |
var b=this.convert(
|
|
|
429 |
this.adapt({
|
|
|
430 |
color:this.convert({ x:xb, y:yb, Y:Yb }, "xyY", "XYZ"),
|
|
|
431 |
adaptor:kwArgs.adaptor,
|
|
|
432 |
source:primary.whitepoint,
|
|
|
433 |
destination:kwArgs.whitepoint
|
|
|
434 |
}),
|
|
|
435 |
"XYZ",
|
|
|
436 |
"xyY"
|
|
|
437 |
);
|
|
|
438 |
primary=dojo.mixin(primary, {
|
|
|
439 |
xr: r.x, yr: r.y, Yr: r.Y,
|
|
|
440 |
xg: g.x, yg: g.y, Yg: g.Y,
|
|
|
441 |
xb: b.x, yb: b.y, Yb: b.Y,
|
|
|
442 |
whitepoint: kwArgs.whitepoint
|
|
|
443 |
});
|
|
|
444 |
}
|
|
|
445 |
return dojo.mixin(primary, {
|
|
|
446 |
zr: 1-primary.xr-primary.yr,
|
|
|
447 |
zg: 1-primary.xg-primary.yg,
|
|
|
448 |
zb: 1-primary.xb-primary.yb
|
|
|
449 |
}); // Object
|
|
|
450 |
};
|
|
|
451 |
|
|
|
452 |
this.adapt=function(/* Object */kwArgs){
|
|
|
453 |
// color is required in the form of XYZ, source whitepoint name is required.
|
|
|
454 |
if(!kwArgs.color || !kwArgs.source){
|
|
|
455 |
console.error("dojox.color.Colorspace::adapt: color and source arguments are required. ", kwArgs);
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
// defaults
|
|
|
459 |
kwArgs=dojo.mixin({
|
|
|
460 |
adaptor:"Bradford",
|
|
|
461 |
destination:"D65"
|
|
|
462 |
}, kwArgs);
|
|
|
463 |
|
|
|
464 |
// adapt
|
|
|
465 |
var swp = this.whitepoint(kwArgs.source);
|
|
|
466 |
var dwp = this.whitepoint(kwArgs.destination);
|
|
|
467 |
if(adaptors[kwArgs.adaptor]){
|
|
|
468 |
var ma=adaptors[kwArgs.adaptor].ma;
|
|
|
469 |
var mai=adaptors[kwArgs.adaptor].mai;
|
|
|
470 |
}else{
|
|
|
471 |
console.warn("dojox.color.Colorspace::adapt: the passed adaptor '", kwArgs.adaptor, "' was not found.");
|
|
|
472 |
}
|
|
|
473 |
var dSrc=dxm.multiply([[swp.x, swp.y, swp.z]], ma);
|
|
|
474 |
var dDest=dxm.multiply([[dwp.x, dwp.y, dwp.z]], ma);
|
|
|
475 |
var center=[
|
|
|
476 |
[dDest[0][0]/dSrc[0][0], 0, 0],
|
|
|
477 |
[0, dDest[0][1]/dSrc[0][1], 0],
|
|
|
478 |
[0, 0, dDest[0][2]/dSrc[0][2]]
|
|
|
479 |
];
|
|
|
480 |
var m=dxm.multiply(dxm.multiply(ma, center), mai);
|
|
|
481 |
var r=dxm.multiply([[ kwArgs.color.X, kwArgs.color.Y, kwArgs.color.Z ]], m)[0];
|
|
|
482 |
return { X:r[0], Y:r[1], Z:r[2] };
|
|
|
483 |
};
|
|
|
484 |
|
|
|
485 |
this.matrix=function(/* String */to, /* Object */primary){
|
|
|
486 |
var wp=this.whitepoint(primary.whitepoint);
|
|
|
487 |
var Xr = p.xr/p.yr, Yr = 1, Zr = (1-p.xr-p.yr)/p.yr;
|
|
|
488 |
var Xg = p.xg/p.yg, Yg = 1, Zg = (1-p.xg-p.yg)/p.yg;
|
|
|
489 |
var Xb = p.xb/p.yb, Yb = 1, Zr = (1-p.xb-p.yb)/p.yb;
|
|
|
490 |
|
|
|
491 |
var m1 = [[ Xr, Yr, Zr ], [ Xg, Yg, Zg ], [ Xb, Yb, Zb ]];
|
|
|
492 |
var m2 = [[ wp.X, wp.Y, wp.Z ]];
|
|
|
493 |
var sm = dojox.math.matrix.multiply(m2, dojox.math.matrix.inverse(m1));
|
|
|
494 |
var Sr = sm[0][0], Sg = sm[0][1], Sb = sm[0][2];
|
|
|
495 |
var result=[
|
|
|
496 |
[Sr*Xr, Sr*Yr, Sr*Zr],
|
|
|
497 |
[Sg*Xg, Sg*Yg, Sg*Zg],
|
|
|
498 |
[Sb*Xb, Sb*Yb, Sb*Zb]
|
|
|
499 |
];
|
|
|
500 |
if(to=="RGB"){ return dojox.math.inverse(result); }
|
|
|
501 |
return result;
|
|
|
502 |
};
|
|
|
503 |
|
|
|
504 |
this.epsilon=function(/* bool? */useApprox){
|
|
|
505 |
return (useApprox || typeof(useApprox)=="undefined")? 0.008856: 216/24289;
|
|
|
506 |
};
|
|
|
507 |
this.kappa=function(/* bool? */useApprox){
|
|
|
508 |
return (useApprox || typeof(useApprox)=="undefined")? 903.3: 24389/27;
|
|
|
509 |
};
|
|
|
510 |
|
|
|
511 |
this.convert=function(/* Object */color, /* string */from, /* string */to, /* Object? */kwArgs){
|
|
|
512 |
if(converters[from] && converters[from][to]){
|
|
|
513 |
return converters[from][to](obj, kwArgs);
|
|
|
514 |
}
|
|
|
515 |
console.warn("dojox.color.Colorspace::convert: Can't convert ", color, " from ", from, " to ", to, ".");
|
|
|
516 |
};
|
|
|
517 |
})();
|
|
|
518 |
|
|
|
519 |
// More dojox.color and dojox.color.Color extensions
|
|
|
520 |
dojo.mixin(dojox.color, {
|
|
|
521 |
fromXYZ: function(/* Object */xyz, /* Object?*/kwArgs){
|
|
|
522 |
kwArgs=kwArgs||{};
|
|
|
523 |
var p=dojox.color.Colorspace.primaries(kwArgs);
|
|
|
524 |
var m=dojox.color.Colorspace.matrix("RGB", p);
|
|
|
525 |
var rgb=dojox.math.matrix.mutliply([[ xyz.X, xyz.Y, xyz.Z ]], m);
|
|
|
526 |
var r=rgb[0][0], g=rgb[0][1], b=rgb[0][2];
|
|
|
527 |
if(p.profile=="sRGB"){
|
|
|
528 |
var R = (r>0.0031308)?(1.055*Math.pow(r, 1/2.4))-0.055: 12.92*r;
|
|
|
529 |
var G = (g>0.0031308)?(1.055*Math.pow(g, 1/2.4))-0.055: 12.92*g;
|
|
|
530 |
var B = (b>0.0031308)?(1.055*Math.pow(b, 1/2.4))-0.055: 12.92*b;
|
|
|
531 |
}else{
|
|
|
532 |
var R=Math.pow(r, 1/p.gamma), G=Math.pow(g, 1/p.gamma), B=Math.pow(b, 1/p.gamma);
|
|
|
533 |
}
|
|
|
534 |
return new dojox.color.Color({ r:Math.floor(R*255), g:Math.floor(G*255), b:Math.floor(B*255) });
|
|
|
535 |
}
|
|
|
536 |
});
|
|
|
537 |
|
|
|
538 |
dojo.extend(dojox.color.Color, {
|
|
|
539 |
toXYZ: function(/* Object */kwArgs){
|
|
|
540 |
kwArgs=kwArgs||{};
|
|
|
541 |
var p=dojox.color.Colorspace.primaries(kwArgs);
|
|
|
542 |
var m=dojox.color.Colorspace.matrix("XYZ", p);
|
|
|
543 |
var _r=this.r/255, _g=this.g/255, _b=this.b/255;
|
|
|
544 |
if(p.profile=="sRGB"){
|
|
|
545 |
var r=(_r>0.04045) ? Math.pow(((_r+0.055)/1.055), 2.4):_r/12.92;
|
|
|
546 |
var g=(_g>0.04045) ? Math.pow(((_g+0.055)/1.055), 2.4):_g/12.92;
|
|
|
547 |
var b=(_b>0.04045) ? Math.pow(((_b+0.055)/1.055), 2.4):_b/12.92;
|
|
|
548 |
} else {
|
|
|
549 |
var r=Math.pow(_r, p.gamma), g=Math.pow(_g, p.gamma), b=Math.pow(_b, p.gamma);
|
|
|
550 |
}
|
|
|
551 |
var xyz=dojox.math.matrix([[ r, g, b ]], m);
|
|
|
552 |
return { X: xyz[0][0], Y: xyz[0][1], Z: xyz[0][2] }; // Object
|
|
|
553 |
}
|
|
|
554 |
});
|
|
|
555 |
|
|
|
556 |
}
|