// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/renderers/colorUtils",["dojo/_base/Color","dojo/_base/array"],function(l,m){var g={COEF_RGB2XYZ:[[.4124,.3576,.1805],[.2126,.7152,.0722],[.0193,.1192,.9505]],COEF_XYZ2RGB:[[3.2406,-1.5372,-.4986],[-.9689,1.8758,.0415],[.0557,-.204,1.057]],matrixProduct:function(a,b){var d=[],c,e;if(a[0].length!==b.length)throw"dimensions do not match";var f=a.length,g=a[0].length,h=0;for(c=0;c<f;c++){for(e=h=0;e<g;e++)h+=a[c][e]*b[e];d.push(h)}return d},rgb2xyz:function(a){a=[a.r/255,a.g/255,a.b/255].map(function(a){return.04045>=
a?a/12.92:Math.pow((a+.055)/1.055,2.4)});a=this.matrixProduct(this.COEF_RGB2XYZ,a);return{x:100*a[0],y:100*a[1],z:100*a[2]}},xyz2rgb:function(a){a=this.matrixProduct(this.COEF_XYZ2RGB,[a.x/100,a.y/100,a.z/100]).map(function(a){return Math.min(1,Math.max(.0031308>=a?12.92*a:1.055*Math.pow(a,1/2.4)-.055,0))});return{r:Math.round(255*a[0]),g:Math.round(255*a[1]),b:Math.round(255*a[2])}},xyz2lab:function(a){a=[a.x/95.047,a.y/100,a.z/108.883].map(function(a){return a>Math.pow(6/29,3)?Math.pow(a,1/3):1/
3*Math.pow(29/6,2)*a+4/29});return{l:116*a[1]-16,a:500*(a[0]-a[1]),b:200*(a[1]-a[2])}},lab2xyz:function(a){var b=a.l;a=[(b+16)/116+a.a/500,(b+16)/116,(b+16)/116-a.b/200].map(function(a){return a>6/29?Math.pow(a,3):3*Math.pow(6/29,2)*(a-4/29)});return{x:95.047*a[0],y:100*a[1],z:108.883*a[2]}},lab2lch:function(a){var b=a.l,d=a.a,c=a.b;a=Math.sqrt(d*d+c*c);d=Math.atan2(c,d);d=0<d?d:d+2*Math.PI;return{l:b,c:a,h:d}},lch2lab:function(a){var b=a.c,d=a.h;return{l:a.l,a:b*Math.cos(d),b:b*Math.sin(d)}},rgb2lab:function(a){return this.xyz2lab(this.rgb2xyz(a))},
lab2rgb:function(a){return this.xyz2rgb(this.lab2xyz(a))},rgb2lch:function(a){return this.lab2lch(this.xyz2lab(this.rgb2xyz(a)))},lch2rgb:function(a){return this.xyz2rgb(this.lab2xyz(this.lch2lab(a)))}},k={rgb2hsv:function(a){var b=a.r,d=a.g;a=a.b;var c=Math.max(b,d,a),e=c-Math.min(b,d,a),f;0===e?f=0:c===b?f=(d-a)/e%6:c===d?f=(a-b)/e+2:c===a&&(f=(b-d)/e+4);0>f&&(f+=6);return{h:60*f,s:100*(0===e?0:e/c),v:100/255*c}},hsv2rgb:function(a){var b=(a.h+360)%360/60,d=a.v/100*255;a=a.s/100*d;var c=a*(1-Math.abs(b%
2-1));switch(Math.floor(b)){case 0:b={r:a,g:c,b:0};break;case 1:b={r:c,g:a,b:0};break;case 2:b={r:0,g:a,b:c};break;case 3:b={r:0,g:c,b:a};break;case 4:b={r:c,g:0,b:a};break;case 5:case 6:b={r:a,g:0,b:c};break;default:b={r:0,g:0,b:0}}b.r=Math.round(b.r+d-a);b.g=Math.round(b.g+d-a);b.b=Math.round(b.b+d-a);return b}};return{toRGB:function(a){var b;void 0!==a.r&&void 0!==a.g&&void 0!==a.b?b=a:void 0!==a.l&&void 0!==a.c&&void 0!==a.h?b=g.lch2rgb(a):void 0!==a.l&&void 0!==a.a&&void 0!==a.b?b=g.lab2rgb(a):
void 0!==a.x&&void 0!==a.y&&void 0!==a.z?b=g.xyz2rgb(a):void 0!==a.h&&void 0!==a.s&&void 0!==a.v&&(b=k.hsv2rgb(a));return b},toHSV:function(a){if(void 0!==a.h&&void 0!==a.s&&void 0!==a.v)return a;a=this.toRGB(a);return k.rgb2hsv(a)},toLAB:function(a){return void 0!==a.l&&void 0!==a.a&&void 0!==a.b?a:g.rgb2lab(this.toRGB(a))},toLCH:function(a){return void 0!==a.l&&void 0!==a.c&&void 0!==a.h?a:g.rgb2lch(this.toRGB(a))},toXYZ:function(a){return void 0!==a.x&&void 0!==a.y&&void 0!==a.z?a:g.rgb2xyz(this.toRGB(a))},
getDojoColor:function(a){if(a){if(Array.isArray(a))return l.fromArray(a);if(void 0!==a.r&&void 0!==a.g&&void 0!==a.b)return a}},correctRGBLimits:function(a){var b=[a.r,a.g,a.b];m.forEach(b,function(a,c){0>b[c]?b[c]=0:255<b[c]&&(b[c]=255);b[c]=Math.floor(b[c])});return{r:b[0],g:b[1],b:b[2],a:1}}}});