6589.js 7.1 KB

12
  1. (()=>{var t={name:"xyz",min:[0,0,0],channel:["X","Y","Z"],alias:["XYZ","ciexyz","cie1931"],whitepoint:{2:{A:[109.85,100,35.585],C:[98.074,100,118.232],D50:[96.422,100,82.521],D55:[95.682,100,92.149],D65:[95.045592705167,100,108.9057750759878],D75:[94.972,100,122.638],F2:[99.187,100,67.395],F7:[95.044,100,108.755],F11:[100.966,100,64.37],E:[100,100,100]},10:{A:[111.144,100,35.2],C:[97.285,100,116.145],D50:[96.72,100,81.427],D55:[95.799,100,90.926],D65:[94.811,100,107.304],D75:[94.416,100,120.641],F2:[103.28,100,69.026],F7:[95.792,100,107.687],F11:[103.866,100,65.627],E:[100,100,100]}}};t.max=t.whitepoint[2].D65,t.rgb=function(i,s){s=s||t.whitepoint[2].E;var e,a,n,h=i[0]/s[0],r=i[1]/s[1],o=i[2]/s[2];return a=-.96924363628087*h+1.87596750150772*r+.041555057407175*o,n=.055630079696993*h+-.20397695888897*r+1.056971514242878*o,e=(e=3.240969941904521*h+-1.537383177570093*r+-.498610760293*o)>.0031308?1.055*Math.pow(e,1/2.4)-.055:e*=12.92,a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:a*=12.92,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:n*=12.92,[255*(e=Math.min(Math.max(0,e),1)),255*(a=Math.min(Math.max(0,a),1)),255*(n=Math.min(Math.max(0,n),1))]};t.lab=function(t){var i=t[0],s=t[1],e=t[2];return s/=100,e/=108.883,i=(i/=95.047)>.008856?Math.pow(i,1/3):7.787*i+16/116,[116*(s=s>.008856?Math.pow(s,1/3):7.787*s+16/116)-16,500*(i-s),200*(s-(e=e>.008856?Math.pow(e,1/3):7.787*e+16/116))]};const i=3*Math.max(499,491,487,503),s={ncycles:100,netsize:256,samplefac:10};class e{constructor(t,i){if(function(t){for(let i=1,s=arguments.length;i<s;i++){const s=arguments[i];if(null!=s)for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&(t[i]=s[i])}}(this,s,{pixels:t},i),this.netsize<4||this.netsize>256)throw new Error("Color count must be between 4 and 256");if(this.samplefac<1||this.samplefac>30)throw new Error("Sampling factor must be between 1 and 30");this.maxnetpos=this.netsize-1,this.netbiasshift=4,this.intbiasshift=16,this.intbias=1<<this.intbiasshift,this.gammashift=10,this.gamma=1<<this.gammashift,this.betashift=10,this.beta=this.intbias>>this.betashift,this.betagamma=this.beta*this.gamma,this.initrad=this.netsize>>3,this.radiusbiasshift=6,this.radiusbias=1<<this.radiusbiasshift,this.initradius=this.initrad*this.radiusbias,this.radiusdec=30,this.alphabiasshift=10,this.initalpha=1<<this.alphabiasshift,this.radbiasshift=8,this.radbias=1<<this.radbiasshift,this.alpharadbshift=this.alphabiasshift+this.radbiasshift,this.alpharadbias=1<<this.alpharadbshift,this.network=[],this.netindex=new Uint32Array(256),this.bias=new Uint32Array(this.netsize),this.freq=new Uint32Array(this.netsize),this.radpower=new Uint32Array(this.netsize>>3);for(let t=0,i=this.netsize;t<i;t++){let i=(t<<this.netbiasshift+8)/this.netsize;this.network[t]=new Float64Array([i,i,i,0]),this.freq[t]=this.intbias/this.netsize,this.bias[t]=0}}unbiasnet(){for(let t=0,i=this.netsize;t<i;t++)this.network[t][0]>>=this.netbiasshift,this.network[t][1]>>=this.netbiasshift,this.network[t][2]>>=this.netbiasshift,this.network[t][3]=t}altersingle(t,i,s,e,a){this.network[i][0]-=t*(this.network[i][0]-s)/this.initalpha,this.network[i][1]-=t*(this.network[i][1]-e)/this.initalpha,this.network[i][2]-=t*(this.network[i][2]-a)/this.initalpha}alterneigh(t,i,s,e,a){const n=Math.abs(i-t),h=Math.min(i+t,this.netsize);let r=i+1,o=i-1,l=1;for(;r<h||o>n;){const t=this.radpower[l++];if(r<h){const i=this.network[r++];i[0]-=t*(i[0]-s)/this.alpharadbias,i[1]-=t*(i[1]-e)/this.alpharadbias,i[2]-=t*(i[2]-a)/this.alpharadbias}if(o>n){const i=this.network[o--];i[0]-=t*(i[0]-s)/this.alpharadbias,i[1]-=t*(i[1]-e)/this.alpharadbias,i[2]-=t*(i[2]-a)/this.alpharadbias}}}contest(t,i,s){let e=~(1<<31),a=e,n=-1,h=n;for(let r=0,o=this.netsize;r<o;r++){let o=this.network[r],l=Math.abs(o[0]-t)+Math.abs(o[1]-i)+Math.abs(o[2]-s);l<e&&(e=l,n=r);let f=l-(this.bias[r]>>this.intbiasshift-this.netbiasshift);f<a&&(a=f,h=r);let b=this.freq[r]>>this.betashift;this.freq[r]-=b,this.bias[r]+=b<<this.gammashift}return this.freq[n]+=this.beta,this.bias[n]-=this.betagamma,h}inxbuild(){let t=0,i=0;for(let s=0,e=this.netsize;s<e;s++){let a=this.network[s],n=null,h=s,r=a[1];for(let t=s+1;t<e;t++)n=this.network[t],n[1]<r&&(h=t,r=n[1]);if(n=this.network[h],s!==h&&([a[0],n[0]]=[n[0],a[0]],[a[1],n[1]]=[n[1],a[1]],[a[2],n[2]]=[n[2],a[2]],[a[3],n[3]]=[n[3],a[3]]),r!==t){this.netindex[t]=i+s>>1;for(let i=t+1;i<r;i++)this.netindex[i]=s;t=r,i=s}}this.netindex[t]=i+this.maxnetpos>>1;for(let i=t+1;i<256;i++)this.netindex[i]=this.maxnetpos}learn(){const t=this.pixels.length,s=30+(this.samplefac-1)/3,e=t/(3*this.samplefac);let a,n=e/this.ncycles|0,h=this.initalpha,r=this.initradius,o=r>>this.radiusbiasshift;o<=1&&(o=0);for(let t=0;t<o;t++)this.radpower[t]=h*((o*o-t*t)*this.radbias/(o*o));t<i?(this.samplefac=1,a=3):a=t%499!=0?1497:t%491!=0?1473:t%487!=0?1461:1509;let l=0;for(let i=0;i<e;){let e=(255&this.pixels[l])<<this.netbiasshift,f=(255&this.pixels[l+1])<<this.netbiasshift,b=(255&this.pixels[l+2])<<this.netbiasshift,c=this.contest(e,f,b);if(this.altersingle(h,c,e,f,b),0!==o&&this.alterneigh(o,c,e,f,b),l+=a,l>=t&&(l-=t),0===n&&(n=1),++i%n==0){h-=h/s,r-=r/this.radiusdec,o=r>>this.radiusbiasshift,o<=1&&(o=0);for(let t=0;t<o;t++)this.radpower[t]=h*((o*o-t*t)*this.radbias/(o*o))}}}buildColorMap(){this.learn(),this.unbiasnet(),this.inxbuild()}getColorMap(){const t=new Uint8Array(3*this.netsize),i=new Uint8Array(this.netsize);for(let t=0,s=this.netsize;t<s;t++)i[this.network[t][3]]=t;for(let s=0,e=0,a=0,n=this.netsize;s<n;s++)a=i[s],t[e++]=255&this.network[a][0],t[e++]=255&this.network[a][1],t[e++]=255&this.network[a][2];return t}}function a(t,i,s,e){let a=0,n=16777216;for(let h=0,r=t.length;h<r;){const r=i-t[h++],o=s-t[h++],l=e-t[h],f=r*r+o*o+l*l;f<n&&(n=f,a=h/3|0),h++}return a}function n(t,i,s=1){const n=function(t){const i=new Uint8ClampedArray(t.length/4*3),s=t.length;let e=0;for(let a=0;a<s;){for(let s=0;s<3;s++)i[e++]=t[a++];a++}return i}(t),r=function(t,i){const s=new e(t,i);return s.buildColorMap(),s.getColorMap()}(n,{netsize:i,samplefac:s}),o=function(t,i){const s=new Uint8Array(t.length/3),e={};for(let n=0,h=0,r=t.length;n<r;){const r=t[n++],o=t[n++],l=t[n++],f=r<<16|o<<8|l;s[h++]=f in e?e[f]:e[f]=a(i,r,o,l)}return s}(n,r),l=[],f=r.length;for(let t=0;t<f;)l.push([r[t++],r[t++],r[t++],255]);return{centroid:l,label:h(i,o)}}function h(t,i){const s=new Array(t).fill(0);for(const t of i)s[t]++;return s}function r(t,i){const s=document.createElement("canvas"),e=s.getContext("2d");return s.height=i,s.width=t,e}function o(t,i){return new OffscreenCanvas(t,i).getContext("2d")}function l(t,i){const{naturalWidth:s,naturalHeight:e}=i,a=t(s,e);return a.drawImage(i,0,0,s,e),a.getImageData(0,0,s,e)}l.bind(void 0,r),l.bind(void 0,o);function f(t,i,s){let{naturalWidth:e,naturalHeight:a}=i;const n=e*a/s;if(n>1){const t=Math.sqrt(n);e=e/t|0,a=a/t|0}const h=t(e,a);return h.drawImage(i,0,0,e,a),h.getImageData(0,0,e,a)}f.bind(void 0,r),f.bind(void 0,o);var b;b=function(t){const{label:i,centroid:s}=n(t,8),e=Math.max(...i);return s[i.findIndex((t=>t==e))]},self.addEventListener("message",(async t=>{const i=t.data,s=i[0],e=i[1];try{const t=[],i=await b(e,(i=>t.push(i)));self.postMessage([s,null,i],t.length?{transfer:t}:void 0)}catch(t){self.postMessage([s,{message:t.message}])}}))})();
  2. //# sourceMappingURL=6589.js.map