fdc0ab7f7b0f5ddab418a95597edecc71a4f91d1.svn-base 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. if (!dojo._hasResource["dojox.color.Colorspace"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojox.color.Colorspace"] = true;
  6. dojo.provide("dojox.color.Colorspace");
  7. dojo.require("dojox.math.matrix");
  8. dojox.color.Colorspace = new (function() {
  9. var dxc = dojox.color;
  10. var dxm = dojox.math.matrix;
  11. var self = this;
  12. var wpMap = {
  13. "2" : {
  14. "E" : {
  15. x : 1 / 3,
  16. y : 1 / 3,
  17. t : 5400
  18. },
  19. "D50" : {
  20. x : 0.34567,
  21. y : 0.3585,
  22. t : 5000
  23. },
  24. "D55" : {
  25. x : 0.33242,
  26. y : 0.34743,
  27. t : 5500
  28. },
  29. "D65" : {
  30. x : 0.31271,
  31. y : 0.32902,
  32. t : 6500
  33. },
  34. "D75" : {
  35. x : 0.29902,
  36. y : 0.31485,
  37. t : 7500
  38. },
  39. "A" : {
  40. x : 0.44757,
  41. y : 0.40745,
  42. t : 2856
  43. },
  44. "B" : {
  45. x : 0.34842,
  46. y : 0.35161,
  47. t : 4874
  48. },
  49. "C" : {
  50. x : 0.31006,
  51. y : 0.31616,
  52. t : 6774
  53. },
  54. "9300" : {
  55. x : 0.2848,
  56. y : 0.2932,
  57. t : 9300
  58. },
  59. "F2" : {
  60. x : 0.37207,
  61. y : 0.37512,
  62. t : 4200
  63. },
  64. "F7" : {
  65. x : 0.31285,
  66. y : 0.32918,
  67. t : 6500
  68. },
  69. "F11" : {
  70. x : 0.38054,
  71. y : 0.37691,
  72. t : 4000
  73. }
  74. },
  75. "10" : {
  76. "E" : {
  77. x : 1 / 3,
  78. y : 1 / 3,
  79. t : 5400
  80. },
  81. "D50" : {
  82. x : 0.34773,
  83. y : 0.35952,
  84. t : 5000
  85. },
  86. "D55" : {
  87. x : 0.33411,
  88. y : 0.34877,
  89. t : 5500
  90. },
  91. "D65" : {
  92. x : 0.31382,
  93. y : 0.331,
  94. t : 6500
  95. },
  96. "D75" : {
  97. x : 0.29968,
  98. y : 0.3174,
  99. t : 7500
  100. },
  101. "A" : {
  102. x : 0.45117,
  103. y : 0.40594,
  104. t : 2856
  105. },
  106. "B" : {
  107. x : 0.3498,
  108. y : 0.3527,
  109. t : 4874
  110. },
  111. "C" : {
  112. x : 0.31039,
  113. y : 0.31905,
  114. t : 6774
  115. },
  116. "F2" : {
  117. x : 0.37928,
  118. y : 0.36723,
  119. t : 4200
  120. },
  121. "F7" : {
  122. x : 0.31565,
  123. y : 0.32951,
  124. t : 6500
  125. },
  126. "F11" : {
  127. x : 0.38543,
  128. y : 0.3711,
  129. t : 4000
  130. }
  131. }
  132. };
  133. var profiles = {
  134. "Adobe RGB 98" : [2.2, "D65", 0.64, 0.33, 0.297361, 0.21, 0.71,
  135. 0.627355, 0.15, 0.06, 0.075285],
  136. "Apple RGB" : [1.8, "D65", 0.625, 0.34, 0.244634, 0.28, 0.595,
  137. 0.672034, 0.155, 0.07, 0.083332],
  138. "Best RGB" : [2.2, "D50", 0.7347, 0.2653, 0.228457, 0.215, 0.775,
  139. 0.737352, 0.13, 0.035, 0.034191],
  140. "Beta RGB" : [2.2, "D50", 0.6888, 0.3112, 0.303273, 0.1986, 0.7551,
  141. 0.663786, 0.1265, 0.0352, 0.032941],
  142. "Bruce RGB" : [2.2, "D65", 0.64, 0.33, 0.240995, 0.28, 0.65,
  143. 0.683554, 0.15, 0.06, 0.075452],
  144. "CIE RGB" : [2.2, "E", 0.735, 0.265, 0.176204, 0.274, 0.717,
  145. 0.812985, 0.167, 0.009, 0.010811],
  146. "ColorMatch RGB" : [1.8, "D50", 0.63, 0.34, 0.274884, 0.295, 0.605,
  147. 0.658132, 0.15, 0.075, 0.066985],
  148. "DON RGB 4" : [2.2, "D50", 0.696, 0.3, 0.27835, 0.215, 0.765,
  149. 0.68797, 0.13, 0.035, 0.03368],
  150. "ECI RGB" : [1.8, "D50", 0.67, 0.33, 0.32025, 0.21, 0.71, 0.602071,
  151. 0.14, 0.08, 0.077679],
  152. "EktaSpace PS5" : [2.2, "D50", 0.695, 0.305, 0.260629, 0.26, 0.7,
  153. 0.734946, 0.11, 0.005, 0.004425],
  154. "NTSC RGB" : [2.2, "C", 0.67, 0.33, 0.298839, 0.21, 0.71, 0.586811,
  155. 0.14, 0.08, 0.11435],
  156. "PAL/SECAM RGB" : [2.2, "D65", 0.64, 0.33, 0.222021, 0.29, 0.6,
  157. 0.706645, 0.15, 0.06, 0.071334],
  158. "Pro Photo RGB" : [1.8, "D50", 0.7347, 0.2653, 0.28804, 0.1596,
  159. 0.8404, 0.711874, 0.0366, 0.0001, 0.000086],
  160. "SMPTE/C RGB" : [2.2, "D65", 0.63, 0.34, 0.212395, 0.31, 0.595,
  161. 0.701049, 0.155, 0.07, 0.086556],
  162. "sRGB" : [2.2, "D65", 0.64, 0.33, 0.212656, 0.3, 0.6, 0.715158,
  163. 0.15, 0.06, 0.072186],
  164. "Wide Gamut RGB" : [2.2, "D50", 0.735, 0.265, 0.258187, 0.115,
  165. 0.826, 0.724938, 0.157, 0.018, 0.016875]
  166. };
  167. var adaptors = {
  168. "XYZ scaling" : {
  169. ma : [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
  170. mai : [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
  171. },
  172. "Bradford" : {
  173. ma : [[0.8951, -0.7502, 0.0389], [0.2664, 1.7135, -0.0685],
  174. [-0.1614, 0.0367, 1.0296]],
  175. mai : [[0.986993, 0.432305, -0.008529],
  176. [-0.147054, 0.51836, 0.040043],
  177. [0.159963, 0.049291, 0.968487]]
  178. },
  179. "Von Kries" : {
  180. ma : [[0.40024, -0.2263, 0], [0.7076, 1.16532, 0],
  181. [-0.08081, 0.0457, 0.91822]],
  182. mai : [[1.859936, 0.361191, 0], [-1.129382, 0.638812, 0],
  183. [0.219897, -0.000006, 1.089064]]
  184. }
  185. };
  186. var cMaps = {
  187. "XYZ" : {
  188. "xyY" : function(xyz, kwArgs) {
  189. kwArgs = dojo.mixin({
  190. whitepoint : "D65",
  191. observer : "10",
  192. useApproximation : true
  193. }, kwArgs || {});
  194. var wp = self
  195. .whitepoint(kwArgs.whitepoint, kwArgs.observer);
  196. var sum = xyz.X + xyz.Y + xyz.Z;
  197. if (sum == 0) {
  198. var x = wp.x, y = wp.y;
  199. } else {
  200. var x = xyz.X / sum, y = xyz.Y / sum;
  201. }
  202. return {
  203. x : x,
  204. y : y,
  205. Y : xyz.Y
  206. };
  207. },
  208. "Lab" : function(xyz, kwArgs) {
  209. kwArgs = dojo.mixin({
  210. whitepoint : "D65",
  211. observer : "10",
  212. useApproximation : true
  213. }, kwArgs || {});
  214. var kappa = self.kappa(kwArgs.useApproximation), epsilon = self
  215. .epsilon(kwArgs.useApproximation);
  216. var wp = self
  217. .whitepoint(kwArgs.whitepoint, kwArgs.observer);
  218. var xr = xyz.X / wp.x, yr = xyz.Y / wp.y, zr = xyz.z / wp.z;
  219. var fx = (xr > epsilon)
  220. ? Math.pow(xr, 1 / 3)
  221. : (kappa * xr + 16) / 116;
  222. var fy = (yr > epsilon)
  223. ? Math.pow(yr, 1 / 3)
  224. : (kappa * yr + 16) / 116;
  225. var fz = (zr > epsilon)
  226. ? Math.pow(zr, 1 / 3)
  227. : (kappa * zr + 16) / 116;
  228. var L = 116 * fy - 16, a = 500 * (fx - fy), b = 200
  229. * (fy - fz);
  230. return {
  231. L : L,
  232. a : a,
  233. b : b
  234. };
  235. },
  236. "Luv" : function(xyz, kwArgs) {
  237. kwArgs = dojo.mixin({
  238. whitepoint : "D65",
  239. observer : "10",
  240. useApproximation : true
  241. }, kwArgs || {});
  242. var kappa = self.kappa(kwArgs.useApproximation), epsilon = self
  243. .epsilon(kwArgs.useApproximation);
  244. var wp = self
  245. .whitepoint(kwArgs.whitepoint, kwArgs.observer);
  246. var ud = (4 * xyz.X) / (xyz.X + 15 * xyz.Y + 3 * xyz.Z);
  247. var vd = (9 * xyz.Y) / (xyz.X + 15 * xyz.Y + 3 * xyz.Z);
  248. var udr = (4 * wp.x) / (wp.x + 15 * wp.y + 3 * wp.z);
  249. var vdr = (9 * wp.y) / (wp.x + 15 * wp.y + 3 * wp.z);
  250. var yr = xyz.Y / wp.y;
  251. var L = (yr > epsilon)
  252. ? 116 * Math.pow(yr, 1 / 3) - 16
  253. : kappa * yr;
  254. var u = 13 * L * (ud - udr);
  255. var v = 13 * L * (vd - vdr);
  256. return {
  257. L : L,
  258. u : u,
  259. v : v
  260. };
  261. }
  262. },
  263. "xyY" : {
  264. "XYZ" : function(xyY) {
  265. if (xyY.y == 0) {
  266. var X = 0, Y = 0, Z = 0;
  267. } else {
  268. var X = (xyY.x * xyY.Y) / xyY.y;
  269. var Y = xyY.Y;
  270. var Z = ((1 - xyY.x - xyY.y) * xyY.Y) / xyY.y;
  271. }
  272. return {
  273. X : X,
  274. Y : Y,
  275. Z : Z
  276. };
  277. }
  278. },
  279. "Lab" : {
  280. "XYZ" : function(lab, kwArgs) {
  281. kwArgs = dojo.mixin({
  282. whitepoint : "D65",
  283. observer : "10",
  284. useApproximation : true
  285. }, kwArgs || {});
  286. var b = kwArgs.useApproximation, kappa = self.kappa(b), epsilon = self
  287. .epsilon(b);
  288. var wp = self
  289. .whitepoint(kwArgs.whitepoint, kwArgs.observer);
  290. var yr = (lab.L > (kappa * epsilon)) ? Math.pow(
  291. (lab.L + 16) / 116, 3) : lab.L / kappa;
  292. var fy = (yr > epsilon)
  293. ? (lab.L + 16) / 116
  294. : (kappa * yr + 16) / 116;
  295. var fx = (lab.a / 500) + fy;
  296. var fz = fy - (lab.b / 200);
  297. var fxcube = Math.pow(fx, 3), fzcube = Math.pow(fz, 3);
  298. var xr = (fxcube > epsilon) ? fxcube : (116 * fx - 16)
  299. / kappa;
  300. var zr = (fzcube > epsilon) ? fzcube : (116 * fz - 16)
  301. / kappa;
  302. return {
  303. X : xr * wp.x,
  304. Y : yr * wp.y,
  305. Z : zr * wp.z
  306. };
  307. },
  308. "LCHab" : function(lab) {
  309. var L = lab.L, C = Math.pow(lab.a * lab.a + lab.b * lab.b,
  310. 0.5), H = Math.atan(lab.b, lab.a) * (180 / Math.PI);
  311. if (H < 0) {
  312. H += 360;
  313. }
  314. if (H < 360) {
  315. H -= 360;
  316. }
  317. return {
  318. L : L,
  319. C : C,
  320. H : H
  321. };
  322. }
  323. },
  324. "LCHab" : {
  325. "Lab" : function(lch) {
  326. var hRad = lch.H * (Math.PI / 180), L = lch.L, a = lch.C
  327. / Math.pow(Math.pow(Math.tan(hRad), 2) + 1, 0.5);
  328. if (90 < lchH && lch.H < 270) {
  329. a = -a;
  330. }
  331. var b = Math.pow(Math.pow(lch.C, 2) - Math.pow(a, 2), 0.5);
  332. if (lch.H > 180) {
  333. b = -b;
  334. }
  335. return {
  336. L : L,
  337. a : a,
  338. b : b
  339. };
  340. }
  341. },
  342. "Luv" : {
  343. "XYZ" : function(Luv, kwArgs) {
  344. kwArgs = dojo.mixin({
  345. whitepoint : "D65",
  346. observer : "10",
  347. useApproximation : true
  348. }, kwArgs || {});
  349. var b = kwArgs.useApproximation, kappa = self.kappa(b), epsilon = self
  350. .epsilon(b);
  351. var wp = self
  352. .whitepoint(kwArgs.whitepoint, kwArgs.observer);
  353. var uz = (4 * wp.x) / (wp.x + 15 * wp.y + 3 * wp.z);
  354. var vz = (9 * wp.y) / (wp.x + 15 * wp.y + 3 * wp.z);
  355. var Y = (Luv.L > kappa * epsilon) ? Math.pow((Luv.L + 16)
  356. / 116, 3) : Luv.L / kappa;
  357. var a = (1 / 3)
  358. * (((52 * Luv.L) / (Luv.u + 13 * Luv.L * uz)) - 1);
  359. var b = -5 * Y, c = -(1 / 3), d = Y
  360. * (((39 * Luv.L) / (Luv.v + 13 * Luv.L * vz)) - 5);
  361. var X = (d - b) / (a - c), Z = X * a + b;
  362. return {
  363. X : X,
  364. Y : Y,
  365. Z : Z
  366. };
  367. },
  368. "LCHuv" : function(Luv) {
  369. var L = Luv.L, C = Math.pow(
  370. Luv.u * Luv.u + Luv.v * Luv * v, 0.5), H = Math
  371. .atan(Luv.v, Luv.u)
  372. * (180 / Math.PI);
  373. if (H < 0) {
  374. H += 360;
  375. }
  376. if (H > 360) {
  377. H -= 360;
  378. }
  379. return {
  380. L : L,
  381. C : C,
  382. H : H
  383. };
  384. }
  385. },
  386. "LCHuv" : {
  387. "Luv" : function(LCH) {
  388. var hRad = LCH.H * (Math.PI / 180);
  389. var L = LCH.L, u = LCH.C
  390. / Math.pow(Math.pow(Math.tan(hRad), 2) + 1, 0.5);
  391. var v = Math.pow(LCH.C * LCH.C - u * u, 0.5);
  392. if (90 < LCH.H && LCH.H > 270) {
  393. u *= -1;
  394. }
  395. if (LCH.H > 180) {
  396. v *= -1;
  397. }
  398. return {
  399. L : L,
  400. u : u,
  401. v : v
  402. };
  403. }
  404. }
  405. };
  406. var converters = {
  407. "CMY" : {
  408. "CMYK" : function(obj, kwArgs) {
  409. return dxc.fromCmy(obj).toCmyk();
  410. },
  411. "HSL" : function(obj, kwArgs) {
  412. return dxc.fromCmy(obj).toHsl();
  413. },
  414. "HSV" : function(obj, kwArgs) {
  415. return dxc.fromCmy(obj).toHsv();
  416. },
  417. "Lab" : function(obj, kwArgs) {
  418. return cMaps["XYZ"]["Lab"](dxc.fromCmy(obj).toXYZ(kwArgs));
  419. },
  420. "LCHab" : function(obj, kwArgs) {
  421. return cMaps["Lab"]["LCHab"](converters["CMY"]["Lab"](obj));
  422. },
  423. "LCHuv" : function(obj, kwArgs) {
  424. return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc
  425. .fromCmy(obj).toXYZ(kwArgs)));
  426. },
  427. "Luv" : function(obj, kwArgs) {
  428. return cMaps["Luv"]["XYZ"](dxc.fromCmy(obj).toXYZ(kwArgs));
  429. },
  430. "RGB" : function(obj, kwArgs) {
  431. return dxc.fromCmy(obj);
  432. },
  433. "XYZ" : function(obj, kwArgs) {
  434. return dxc.fromCmy(obj).toXYZ(kwArgs);
  435. },
  436. "xyY" : function(obj, kwArgs) {
  437. return cMaps["XYZ"]["xyY"](dxc.fromCmy(obj).toXYZ(kwArgs));
  438. }
  439. },
  440. "CMYK" : {
  441. "CMY" : function(obj, kwArgs) {
  442. return dxc.fromCmyk(obj).toCmy();
  443. },
  444. "HSL" : function(obj, kwArgs) {
  445. return dxc.fromCmyk(obj).toHsl();
  446. },
  447. "HSV" : function(obj, kwArgs) {
  448. return dxc.fromCmyk(obj).toHsv();
  449. },
  450. "Lab" : function(obj, kwArgs) {
  451. return cMaps["XYZ"]["Lab"](dxc.fromCmyk(obj).toXYZ(kwArgs));
  452. },
  453. "LCHab" : function(obj, kwArgs) {
  454. return cMaps["Lab"]["LCHab"](converters["CMYK"]["Lab"](obj));
  455. },
  456. "LCHuv" : function(obj, kwArgs) {
  457. return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc
  458. .fromCmyk(obj).toXYZ(kwArgs)));
  459. },
  460. "Luv" : function(obj, kwArgs) {
  461. return cMaps["Luv"]["XYZ"](dxc.fromCmyk(obj).toXYZ(kwArgs));
  462. },
  463. "RGB" : function(obj, kwArgs) {
  464. return dxc.fromCmyk(obj);
  465. },
  466. "XYZ" : function(obj, kwArgs) {
  467. return dxc.fromCmyk(obj).toXYZ(kwArgs);
  468. },
  469. "xyY" : function(obj, kwArgs) {
  470. return cMaps["XYZ"]["xyY"](dxc.fromCmyk(obj).toXYZ(kwArgs));
  471. }
  472. },
  473. "HSL" : {
  474. "CMY" : function(obj, kwArgs) {
  475. return dxc.fromHsl(obj).toCmy();
  476. },
  477. "CMYK" : function(obj, kwArgs) {
  478. return dxc.fromHsl(obj).toCmyk();
  479. },
  480. "HSV" : function(obj, kwArgs) {
  481. return dxc.fromHsl(obj).toHsv();
  482. },
  483. "Lab" : function(obj, kwArgs) {
  484. return cMaps["XYZ"]["Lab"](dxc.fromHsl(obj).toXYZ(kwArgs));
  485. },
  486. "LCHab" : function(obj, kwArgs) {
  487. return cMaps["Lab"]["LCHab"](converters["CMYK"]["Lab"](obj));
  488. },
  489. "LCHuv" : function(obj, kwArgs) {
  490. return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc
  491. .fromHsl(obj).toXYZ(kwArgs)));
  492. },
  493. "Luv" : function(obj, kwArgs) {
  494. return cMaps["Luv"]["XYZ"](dxc.fromHsl(obj).toXYZ(kwArgs));
  495. },
  496. "RGB" : function(obj, kwArgs) {
  497. return dxc.fromHsl(obj);
  498. },
  499. "XYZ" : function(obj, kwArgs) {
  500. return dxc.fromHsl(obj).toXYZ(kwArgs);
  501. },
  502. "xyY" : function(obj, kwArgs) {
  503. return cMaps["XYZ"]["xyY"](dxc.fromHsl(obj).toXYZ(kwArgs));
  504. }
  505. },
  506. "HSV" : {
  507. "CMY" : function(obj, kwArgs) {
  508. return dxc.fromHsv(obj).toCmy();
  509. },
  510. "CMYK" : function(obj, kwArgs) {
  511. return dxc.fromHsv(obj).toCmyk();
  512. },
  513. "HSL" : function(obj, kwArgs) {
  514. return dxc.fromHsv(obj).toHsl();
  515. },
  516. "Lab" : function(obj, kwArgs) {
  517. return cMaps["XYZ"]["Lab"](dxc.fromHsv(obj).toXYZ(kwArgs));
  518. },
  519. "LCHab" : function(obj, kwArgs) {
  520. return cMaps["Lab"]["LCHab"](converters["CMYK"]["Lab"](obj));
  521. },
  522. "LCHuv" : function(obj, kwArgs) {
  523. return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](dxc
  524. .fromHsv(obj).toXYZ(kwArgs)));
  525. },
  526. "Luv" : function(obj, kwArgs) {
  527. return cMaps["Luv"]["XYZ"](dxc.fromHsv(obj).toXYZ(kwArgs));
  528. },
  529. "RGB" : function(obj, kwArgs) {
  530. return dxc.fromHsv(obj);
  531. },
  532. "XYZ" : function(obj, kwArgs) {
  533. return dxc.fromHsv(obj).toXYZ(kwArgs);
  534. },
  535. "xyY" : function(obj, kwArgs) {
  536. return cMaps["XYZ"]["xyY"](dxc.fromHsv(obj).toXYZ(kwArgs));
  537. }
  538. },
  539. "Lab" : {
  540. "CMY" : function(obj, kwArgs) {
  541. return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs))
  542. .toCmy();
  543. },
  544. "CMYK" : function(obj, kwArgs) {
  545. return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs))
  546. .toCmyk();
  547. },
  548. "HSL" : function(obj, kwArgs) {
  549. return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs))
  550. .toHsl();
  551. },
  552. "HSV" : function(obj, kwArgs) {
  553. return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs))
  554. .toHsv();
  555. },
  556. "LCHab" : function(obj, kwArgs) {
  557. return cMaps["Lab"]["LCHab"](obj, kwArgs);
  558. },
  559. "LCHuv" : function(obj, kwArgs) {
  560. return cMaps["Luv"]["LCHuv"](cMaps["Lab"]["XYZ"](obj,
  561. kwArgs), kwArgs);
  562. },
  563. "Luv" : function(obj, kwArgs) {
  564. return cMaps["XYZ"]["Luv"](
  565. cMaps["Lab"]["XYZ"](obj, kwArgs), kwArgs);
  566. },
  567. "RGB" : function(obj, kwArgs) {
  568. return dxc.fromXYZ(cMaps["Lab"]["XYZ"](obj, kwArgs));
  569. },
  570. "XYZ" : function(obj, kwArgs) {
  571. return cMaps["Lab"]["XYZ"](obj, kwArgs);
  572. },
  573. "xyY" : function(obj, kwArgs) {
  574. return cMaps["XYZ"]["xyY"](
  575. cMaps["Lab"]["XYZ"](obj, kwArgs), kwArgs);
  576. }
  577. },
  578. "LCHab" : {
  579. "CMY" : function(obj, kwArgs) {
  580. return dxc.fromXYZ(
  581. cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj),
  582. kwArgs), kwArgs).toCmy();
  583. },
  584. "CMYK" : function(obj, kwArgs) {
  585. return dxc.fromXYZ(
  586. cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj),
  587. kwArgs), kwArgs).toCmyk();
  588. },
  589. "HSL" : function(obj, kwArgs) {
  590. return dxc.fromXYZ(
  591. cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj),
  592. kwArgs), kwArgs).toHsl();
  593. },
  594. "HSV" : function(obj, kwArgs) {
  595. return dxc.fromXYZ(
  596. cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj),
  597. kwArgs), kwArgs).toHsv();
  598. },
  599. "Lab" : function(obj, kwArgs) {
  600. return cMaps["Lab"]["LCHab"](obj, kwArgs);
  601. },
  602. "LCHuv" : function(obj, kwArgs) {
  603. return cMaps["Luv"]["LCHuv"](
  604. cMaps["XYZ"]["Luv"](
  605. cMaps["Lab"]["XYZ"](
  606. cMaps["LCHab"]["Lab"](obj), kwArgs),
  607. kwArgs), kwArgs);
  608. },
  609. "Luv" : function(obj, kwArgs) {
  610. return cMaps["XYZ"]["Luv"](cMaps["Lab"]["XYZ"](
  611. cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs);
  612. },
  613. "RGB" : function(obj, kwArgs) {
  614. return dxc
  615. .fromXYZ(
  616. cMaps["Lab"]["XYZ"](
  617. cMaps["LCHab"]["Lab"](obj), kwArgs),
  618. kwArgs);
  619. },
  620. "XYZ" : function(obj, kwArgs) {
  621. return cMaps["Lab"]["XYZ"](cMaps["LCHab"]["Lab"](obj,
  622. kwArgs), kwArgs);
  623. },
  624. "xyY" : function(obj, kwArgs) {
  625. return cMaps["XYZ"]["xyY"](cMaps["Lab"]["XYZ"](
  626. cMaps["LCHab"]["Lab"](obj), kwArgs), kwArgs);
  627. }
  628. },
  629. "LCHuv" : {
  630. "CMY" : function(obj, kwArgs) {
  631. return dxc.fromXYZ(
  632. cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj),
  633. kwArgs), kwArgs).toCmy();
  634. },
  635. "CMYK" : function(obj, kwArgs) {
  636. return dxc.fromXYZ(
  637. cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj),
  638. kwArgs), kwArgs).toCmyk();
  639. },
  640. "HSL" : function(obj, kwArgs) {
  641. return dxc.fromXYZ(
  642. cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj),
  643. kwArgs), kwArgs).toHsl();
  644. },
  645. "HSV" : function(obj, kwArgs) {
  646. return dxc.fromXYZ(
  647. cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj),
  648. kwArgs), kwArgs).toHsv();
  649. },
  650. "Lab" : function(obj, kwArgs) {
  651. return cMaps["XYZ"]["Lab"](cMaps["Luv"]["XYZ"](
  652. cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs);
  653. },
  654. "LCHab" : function(obj, kwArgs) {
  655. return cMaps["Lab"]["LCHab"](
  656. cMaps["XYZ"]["Lab"](
  657. cMaps["Luv"]["XYZ"](
  658. cMaps["LCHuv"]["Luv"](obj), kwArgs),
  659. kwArgs), kwArgs);
  660. },
  661. "Luv" : function(obj, kwArgs) {
  662. return cMaps["LCHuv"]["Luv"](obj, kwArgs);
  663. },
  664. "RGB" : function(obj, kwArgs) {
  665. return dxc
  666. .fromXYZ(
  667. cMaps["Luv"]["XYZ"](
  668. cMaps["LCHuv"]["Luv"](obj), kwArgs),
  669. kwArgs);
  670. },
  671. "XYZ" : function(obj, kwArgs) {
  672. return cMaps["Luv"]["XYZ"](cMaps["LCHuv"]["Luv"](obj),
  673. kwArgs);
  674. },
  675. "xyY" : function(obj, kwArgs) {
  676. return cMaps["XYZ"]["xyY"](cMaps["Luv"]["XYZ"](
  677. cMaps["LCHuv"]["Luv"](obj), kwArgs), kwArgs);
  678. }
  679. ,
  680. },
  681. "Luv" : {
  682. "CMY" : function(obj, kwArgs) {
  683. return dxc
  684. .fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs)
  685. .toCmy();
  686. },
  687. "CMYK" : function(obj, kwArgs) {
  688. return dxc
  689. .fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs)
  690. .toCmyk();
  691. },
  692. "HSL" : function(obj, kwArgs) {
  693. return dxc
  694. .fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs)
  695. .toHsl();
  696. },
  697. "HSV" : function(obj, kwArgs) {
  698. return dxc
  699. .fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs)
  700. .toHsv();
  701. },
  702. "Lab" : function(obj, kwArgs) {
  703. return cMaps["XYZ"]["Lab"](
  704. cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs);
  705. },
  706. "LCHab" : function(obj, kwArgs) {
  707. return cMaps["Lab"]["LCHab"](cMaps["XYZ"]["Lab"](
  708. cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs),
  709. kwArgs);
  710. },
  711. "LCHuv" : function(obj, kwArgs) {
  712. return cMaps["Luv"]["LCHuv"](obj, kwArgs);
  713. },
  714. "RGB" : function(obj, kwArgs) {
  715. return dxc
  716. .fromXYZ(cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs);
  717. },
  718. "XYZ" : function(obj, kwArgs) {
  719. return cMaps["Luv"]["XYZ"](obj, kwArgs);
  720. },
  721. "xyY" : function(obj, kwArgs) {
  722. return cMaps["XYZ"]["xyY"](
  723. cMaps["Luv"]["XYZ"](obj, kwArgs), kwArgs);
  724. }
  725. ,
  726. },
  727. "RGB" : {
  728. "CMY" : function(obj, kwArgs) {
  729. return obj.toCmy();
  730. },
  731. "CMYK" : function(obj, kwArgs) {
  732. return obj.toCmyk();
  733. },
  734. "HSL" : function(obj, kwArgs) {
  735. return obj.toHsl();
  736. },
  737. "HSV" : function(obj, kwArgs) {
  738. return obj.toHsv();
  739. },
  740. "Lab" : function(obj, kwArgs) {
  741. return cMaps["XYZ"]["Lab"](obj.toXYZ(kwArgs), kwArgs);
  742. },
  743. "LCHab" : function(obj, kwArgs) {
  744. return cMaps["LCHab"]["Lab"](cMaps["XYZ"]["Lab"](obj
  745. .toXYZ(kwArgs), kwArgs), kwArgs);
  746. },
  747. "LCHuv" : function(obj, kwArgs) {
  748. return cMaps["LCHuv"]["Luv"](cMaps["XYZ"]["Luv"](obj
  749. .toXYZ(kwArgs), kwArgs), kwArgs);
  750. },
  751. "Luv" : function(obj, kwArgs) {
  752. return cMaps["XYZ"]["Luv"](obj.toXYZ(kwArgs), kwArgs);
  753. },
  754. "XYZ" : function(obj, kwArgs) {
  755. return obj.toXYZ(kwArgs);
  756. },
  757. "xyY" : function(obj, kwArgs) {
  758. return cMaps["XYZ"]["xyY"](obj.toXYZ(kwArgs), kwArgs);
  759. }
  760. },
  761. "XYZ" : {
  762. "CMY" : function(obj, kwArgs) {
  763. return dxc.fromXYZ(obj, kwArgs).toCmy();
  764. },
  765. "CMYK" : function(obj, kwArgs) {
  766. return dxc.fromXYZ(obj, kwArgs).toCmyk();
  767. },
  768. "HSL" : function(obj, kwArgs) {
  769. return dxc.fromXYZ(obj, kwArgs).toHsl();
  770. },
  771. "HSV" : function(obj, kwArgs) {
  772. return dxc.fromXYZ(obj, kwArgs).toHsv();
  773. },
  774. "Lab" : function(obj, kwArgs) {
  775. return cMaps["XYZ"]["Lab"](obj, kwArgs);
  776. },
  777. "LCHab" : function(obj, kwArgs) {
  778. return cMaps["Lab"]["LCHab"](cMaps["XYZ"]["Lab"](obj,
  779. kwArgs), kwArgs);
  780. },
  781. "LCHuv" : function(obj, kwArgs) {
  782. return cMaps["Luv"]["LCHuv"](cMaps["XYZ"]["Luv"](obj,
  783. kwArgs), kwArgs);
  784. },
  785. "Luv" : function(obj, kwArgs) {
  786. return cMaps["XYZ"]["Luv"](obj, kwArgs);
  787. },
  788. "RGB" : function(obj, kwArgs) {
  789. return dxc.fromXYZ(obj, kwArgs);
  790. },
  791. "xyY" : function(obj, kwArgs) {
  792. return cMaps["XYZ"]["xyY"](dxc.fromXYZ(obj, kwArgs), kwArgs);
  793. }
  794. },
  795. // TODO: revisit this. xyY represents a single color, not a spectrum
  796. // of colors.
  797. "xyY" : {
  798. "CMY" : function(obj, kwArgs) {
  799. return dxc
  800. .fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs)
  801. .toCmy();
  802. },
  803. "CMYK" : function(obj, kwArgs) {
  804. return dxc
  805. .fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs)
  806. .toCmyk();
  807. },
  808. "HSL" : function(obj, kwArgs) {
  809. return dxc
  810. .fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs)
  811. .toHsl();
  812. },
  813. "HSV" : function(obj, kwArgs) {
  814. return dxc
  815. .fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs)
  816. .toHsv();
  817. },
  818. "Lab" : function(obj, kwArgs) {
  819. return cMaps["Lab"]["XYZ"](
  820. cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs);
  821. },
  822. "LCHab" : function(obj, kwArgs) {
  823. return cMaps["LCHab"]["Lab"](cMaps["Lab"]["XYZ"](
  824. cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs),
  825. kwArgs);
  826. },
  827. "LCHuv" : function(obj, kwArgs) {
  828. return cMaps["LCHuv"]["Luv"](cMaps["Luv"]["XYZ"](
  829. cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs),
  830. kwArgs);
  831. },
  832. "Luv" : function(obj, kwArgs) {
  833. return cMaps["Luv"]["XYZ"](
  834. cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs);
  835. },
  836. "RGB" : function(obj, kwArgs) {
  837. return dxc
  838. .fromXYZ(cMaps["xyY"]["XYZ"](obj, kwArgs), kwArgs);
  839. },
  840. "XYZ" : function(obj, kwArgs) {
  841. return cMaps["xyY"]["XYZ"](obj, kwArgs);
  842. }
  843. }
  844. };
  845. this.whitepoint = function(/* String */wpName, /* String? */observer) {
  846. observer = observer || "10";
  847. var x = 0, y = 0, t = 0;
  848. if (wpMap[observer] && wpMap[observer][wpName]) {
  849. x = wpMap[observer][wpName].x;
  850. y = wpMap[observer][wpName].y;
  851. t = wpMap[observer][wpName].t;
  852. } else {
  853. console
  854. .warn(
  855. "dojox.color.Colorspace::whitepoint: either the observer or the whitepoint name was not found. ",
  856. observer, wpName);
  857. }
  858. var wp = {
  859. x : x,
  860. y : y,
  861. z : (1 - x - y),
  862. t : t,
  863. Y : 1
  864. };
  865. return this.convert(wp, "xyY", "XYZ");
  866. };
  867. this.tempToWhitepoint = function(/* Number */t) {
  868. if (t < 4000) {
  869. console
  870. .warn(
  871. "dojox.color.Colorspace::tempToWhitepoint: can't find a white point for temperatures less than 4000K. (Passed ",
  872. t, ").");
  873. return {
  874. x : 0,
  875. y : 0
  876. };
  877. }
  878. if (t > 25000) {
  879. console
  880. .warn(
  881. "dojox.color.Colorspace::tempToWhitepoint: can't find a white point for temperatures greater than 25000K. (Passed ",
  882. t, ").");
  883. return {
  884. x : 0,
  885. y : 0
  886. };
  887. }
  888. var t1 = t, t2 = t * t, t3 = t2 * t;
  889. var ten9 = Math.pow(10, 9), ten6 = Math.pow(10, 6), ten3 = Math
  890. .pow(10, 3);
  891. if (t <= 7000) {
  892. var x = (-4.607 * ten9 / t3) + (2.9678 * ten6 / t2)
  893. + (0.09911 * ten3 / t) + 0.2444063;
  894. } else {
  895. var x = (-2.0064 * ten9 / t3) + (1.9018 * ten6 / t2)
  896. + (0.24748 * ten3 / t) + 0.23704;
  897. }
  898. var y = -3 * x * x + 2.87 * x - 0.275;
  899. return {
  900. x : x,
  901. y : y
  902. };
  903. };
  904. this.primaries = function(/* Object */kwArgs) {
  905. // mix in the defaults.
  906. kwArgs = dojo.mixin({
  907. profile : "sRGB",
  908. whitepoint : "D65",
  909. observer : "10",
  910. adaptor : "Bradford"
  911. }, kwArgs || {});
  912. var m = [];
  913. if (profiles[kwArgs.profile]) {
  914. m = profiles[kwArgs.profile].slice(0);
  915. } else {
  916. console
  917. .warn(
  918. "dojox.color.Colorspace::primaries: the passed profile was not found. ",
  919. "Available profiles include: ", profiles,
  920. ". The profile passed was ", kwArgs.profile);
  921. }
  922. var primary = {
  923. name : kwArgs.profile,
  924. gamma : m[0],
  925. whitepoint : m[1],
  926. xr : m[2],
  927. yr : m[3],
  928. Yr : m[4],
  929. xg : m[5],
  930. yg : m[6],
  931. Yg : m[7],
  932. xb : m[8],
  933. yb : m[9],
  934. Yb : m[10]
  935. };
  936. // convert for the whitepoint
  937. if (kwArgs.whitepoint != primary.whitepoint) {
  938. var r = this.convert(this.adapt({
  939. color : this.convert({
  940. x : xr,
  941. y : yr,
  942. Y : Yr
  943. }, "xyY", "XYZ"),
  944. adaptor : kwArgs.adaptor,
  945. source : primary.whitepoint,
  946. destination : kwArgs.whitepoint
  947. }), "XYZ", "xyY");
  948. var g = this.convert(this.adapt({
  949. color : this.convert({
  950. x : xg,
  951. y : yg,
  952. Y : Yg
  953. }, "xyY", "XYZ"),
  954. adaptor : kwArgs.adaptor,
  955. source : primary.whitepoint,
  956. destination : kwArgs.whitepoint
  957. }), "XYZ", "xyY");
  958. var b = this.convert(this.adapt({
  959. color : this.convert({
  960. x : xb,
  961. y : yb,
  962. Y : Yb
  963. }, "xyY", "XYZ"),
  964. adaptor : kwArgs.adaptor,
  965. source : primary.whitepoint,
  966. destination : kwArgs.whitepoint
  967. }), "XYZ", "xyY");
  968. primary = dojo.mixin(primary, {
  969. xr : r.x,
  970. yr : r.y,
  971. Yr : r.Y,
  972. xg : g.x,
  973. yg : g.y,
  974. Yg : g.Y,
  975. xb : b.x,
  976. yb : b.y,
  977. Yb : b.Y,
  978. whitepoint : kwArgs.whitepoint
  979. });
  980. }
  981. return dojo.mixin(primary, {
  982. zr : 1 - primary.xr - primary.yr,
  983. zg : 1 - primary.xg - primary.yg,
  984. zb : 1 - primary.xb - primary.yb
  985. }); // Object
  986. };
  987. this.adapt = function(/* Object */kwArgs) {
  988. // color is required in the form of XYZ, source whitepoint name is
  989. // required.
  990. if (!kwArgs.color || !kwArgs.source) {
  991. console
  992. .error(
  993. "dojox.color.Colorspace::adapt: color and source arguments are required. ",
  994. kwArgs);
  995. }
  996. // defaults
  997. kwArgs = dojo.mixin({
  998. adaptor : "Bradford",
  999. destination : "D65"
  1000. }, kwArgs);
  1001. // adapt
  1002. var swp = this.whitepoint(kwArgs.source);
  1003. var dwp = this.whitepoint(kwArgs.destination);
  1004. if (adaptors[kwArgs.adaptor]) {
  1005. var ma = adaptors[kwArgs.adaptor].ma;
  1006. var mai = adaptors[kwArgs.adaptor].mai;
  1007. } else {
  1008. console.warn(
  1009. "dojox.color.Colorspace::adapt: the passed adaptor '",
  1010. kwArgs.adaptor, "' was not found.");
  1011. }
  1012. var dSrc = dxm.multiply([[swp.x, swp.y, swp.z]], ma);
  1013. var dDest = dxm.multiply([[dwp.x, dwp.y, dwp.z]], ma);
  1014. var center = [[dDest[0][0] / dSrc[0][0], 0, 0],
  1015. [0, dDest[0][1] / dSrc[0][1], 0],
  1016. [0, 0, dDest[0][2] / dSrc[0][2]]];
  1017. var m = dxm.multiply(dxm.multiply(ma, center), mai);
  1018. var r = dxm.multiply([[kwArgs.color.X, kwArgs.color.Y,
  1019. kwArgs.color.Z]], m)[0];
  1020. return {
  1021. X : r[0],
  1022. Y : r[1],
  1023. Z : r[2]
  1024. };
  1025. };
  1026. this.matrix = function(/* String */to, /* Object */primary) {
  1027. var wp = this.whitepoint(primary.whitepoint);
  1028. var Xr = p.xr / p.yr, Yr = 1, Zr = (1 - p.xr - p.yr) / p.yr;
  1029. var Xg = p.xg / p.yg, Yg = 1, Zg = (1 - p.xg - p.yg) / p.yg;
  1030. var Xb = p.xb / p.yb, Yb = 1, Zr = (1 - p.xb - p.yb) / p.yb;
  1031. var m1 = [[Xr, Yr, Zr], [Xg, Yg, Zg], [Xb, Yb, Zb]];
  1032. var m2 = [[wp.X, wp.Y, wp.Z]];
  1033. var sm = dojox.math.matrix.multiply(m2, dojox.math.matrix
  1034. .inverse(m1));
  1035. var Sr = sm[0][0], Sg = sm[0][1], Sb = sm[0][2];
  1036. var result = [[Sr * Xr, Sr * Yr, Sr * Zr],
  1037. [Sg * Xg, Sg * Yg, Sg * Zg], [Sb * Xb, Sb * Yb, Sb * Zb]];
  1038. if (to == "RGB") {
  1039. return dojox.math.inverse(result);
  1040. }
  1041. return result;
  1042. };
  1043. this.epsilon = function(/* bool? */useApprox) {
  1044. return (useApprox || typeof(useApprox) == "undefined")
  1045. ? 0.008856
  1046. : 216 / 24289;
  1047. };
  1048. this.kappa = function(/* bool? */useApprox) {
  1049. return (useApprox || typeof(useApprox) == "undefined")
  1050. ? 903.3
  1051. : 24389 / 27;
  1052. };
  1053. this.convert = function(/* Object */color, /* string */from, /* string */
  1054. to, /* Object? */kwArgs) {
  1055. if (converters[from] && converters[from][to]) {
  1056. return converters[from][to](obj, kwArgs);
  1057. }
  1058. console.warn("dojox.color.Colorspace::convert: Can't convert ",
  1059. color, " from ", from, " to ", to, ".");
  1060. };
  1061. })();
  1062. // More dojox.color and dojox.color.Color extensions
  1063. dojo.mixin(dojox.color, {
  1064. fromXYZ : function(/* Object */xyz, /* Object? */kwArgs) {
  1065. kwArgs = kwArgs || {};
  1066. var p = dojox.color.Colorspace.primaries(kwArgs);
  1067. var m = dojox.color.Colorspace.matrix("RGB", p);
  1068. var rgb = dojox.math.matrix.mutliply([[xyz.X, xyz.Y, xyz.Z]], m);
  1069. var r = rgb[0][0], g = rgb[0][1], b = rgb[0][2];
  1070. if (p.profile == "sRGB") {
  1071. var R = (r > 0.0031308) ? (1.055 * Math.pow(r, 1 / 2.4))
  1072. - 0.055 : 12.92 * r;
  1073. var G = (g > 0.0031308) ? (1.055 * Math.pow(g, 1 / 2.4))
  1074. - 0.055 : 12.92 * g;
  1075. var B = (b > 0.0031308) ? (1.055 * Math.pow(b, 1 / 2.4))
  1076. - 0.055 : 12.92 * b;
  1077. } else {
  1078. var R = Math.pow(r, 1 / p.gamma), G = Math.pow(g, 1 / p.gamma), B = Math
  1079. .pow(b, 1 / p.gamma);
  1080. }
  1081. return new dojox.color.Color({
  1082. r : Math.floor(R * 255),
  1083. g : Math.floor(G * 255),
  1084. b : Math.floor(B * 255)
  1085. });
  1086. }
  1087. });
  1088. dojo.extend(dojox.color.Color, {
  1089. toXYZ : function(/* Object */kwArgs) {
  1090. kwArgs = kwArgs || {};
  1091. var p = dojox.color.Colorspace.primaries(kwArgs);
  1092. var m = dojox.color.Colorspace.matrix("XYZ", p);
  1093. var _r = this.r / 255, _g = this.g / 255, _b = this.b / 255;
  1094. if (p.profile == "sRGB") {
  1095. var r = (_r > 0.04045)
  1096. ? Math.pow(((_r + 0.055) / 1.055), 2.4)
  1097. : _r / 12.92;
  1098. var g = (_g > 0.04045)
  1099. ? Math.pow(((_g + 0.055) / 1.055), 2.4)
  1100. : _g / 12.92;
  1101. var b = (_b > 0.04045)
  1102. ? Math.pow(((_b + 0.055) / 1.055), 2.4)
  1103. : _b / 12.92;
  1104. } else {
  1105. var r = Math.pow(_r, p.gamma), g = Math.pow(_g, p.gamma), b = Math
  1106. .pow(_b, p.gamma);
  1107. }
  1108. var xyz = dojox.math.matrix([[r, g, b]], m);
  1109. return {
  1110. X : xyz[0][0],
  1111. Y : xyz[0][1],
  1112. Z : xyz[0][2]
  1113. }; // Object
  1114. }
  1115. });
  1116. }