forked from matkl/average-color
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeltae.min.js
More file actions
2 lines (2 loc) · 4.97 KB
/
deltae.min.js
File metadata and controls
2 lines (2 loc) · 4.97 KB
1
2
// https://github.com/zschuessler/DeltaE
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i;i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,i.DeltaE=t()}}(function(){return function t(i,e,s){function h(a,n){if(!e[a]){if(!i[a]){var o="function"==typeof require&&require;if(!n&&o)return o(a,!0);if(r)return r(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var m=e[a]={exports:{}};i[a][0].call(m.exports,function(t){var e=i[a][1][t];return h(e?e:t)},m,m.exports,t,i,e,s)}return e[a].exports}for(var r="function"==typeof require&&require,a=0;a<s.length;a++)h(s[a]);return h}({1:[function(t,i){"use strict";function e(){}var s=t("./dE76"),h=t("./dE94"),r=t("./dE00");e.prototype.getDeltaE76=function(t,i){var e=new s(t,i);return e.getDeltaE()},e.prototype.getDeltaE94=function(t,i){var e=new h(t,i);return e.getDeltaE()},e.prototype.getDeltaE00=function(t,i){var e=new r(t,i);return e.getDeltaE()},i.exports=new e},{"./dE00":2,"./dE76":3,"./dE94":4}],2:[function(t,i){"use strict";function e(t,i,e){var s=Math.sqrt,h=Math.pow;this.x1=t,this.x2=i,this.weights=e||{},this.ksubL=this.weights.lightness||1,this.ksubC=this.weights.chroma||1,this.ksubH=this.weights.hue||1,this.deltaLPrime=i.L-t.L,this.LBar=(t.L+i.L)/2,this.C1=s(h(t.A,2)+h(t.B,2)),this.C2=s(h(i.A,2)+h(i.B,2)),this.CBar=(this.C1+this.C2)/2,this.aPrime1=t.A+t.A/2*(1-s(h(this.CBar,7)/(h(this.CBar,7)+h(25,7)))),this.aPrime2=i.A+i.A/2*(1-s(h(this.CBar,7)/(h(this.CBar,7)+h(25,7)))),this.CPrime1=s(h(this.aPrime1,2)+h(t.B,2)),this.CPrime2=s(h(this.aPrime2,2)+h(i.B,2)),this.CBarPrime=(this.CPrime1+this.CPrime2)/2,this.deltaCPrime=this.CPrime2-this.CPrime1,this.SsubL=1+.015*h(this.LBar-50,2)/s(20+h(this.LBar-50,2)),this.SsubC=1+.045*this.CBarPrime,this.hPrime1=0,this.hPrime2=0,this.deltahPrime=0,this.deltaHPrime=0,this.HBarPrime=0,this.T=0,this.SsubH=0,this.RsubT=0}e.prototype.getDeltaE=function(){var t=Math.sqrt,i=Math.sin,e=Math.pow;this.hPrime1=this.gethPrime1(),this.hPrime2=this.gethPrime2(),this.deltahPrime=this.getDeltahPrime(),this.deltaHPrime=2*t(this.CPrime1*this.CPrime2)*i(this.degreesToRadians(this.deltahPrime)/2),this.HBarPrime=this.getHBarPrime(),this.T=this.getT(),this.SsubH=1+.015*this.CBarPrime*this.T,this.RsubT=this.getRsubT();var s=this.deltaLPrime/(this.ksubL*this.SsubL),h=this.deltaCPrime/(this.ksubC*this.SsubC),r=this.deltaHPrime/(this.ksubH*this.SsubH);return t(e(s,2)+e(h,2)+e(r,2)+this.RsubT*h*r)},e.prototype.getRsubT=function(){var t=Math.sin,i=Math.sqrt,e=Math.pow,s=Math.exp;return-2*i(e(this.CBarPrime,7)/(e(this.CBarPrime,7)+e(25,7)))*t(this.degreesToRadians(60*s(-e((this.HBarPrime-275)/25,2))))},e.prototype.getT=function(){var t=Math.cos;return 1-.17*t(this.degreesToRadians(this.HBarPrime-30))+.24*t(this.degreesToRadians(2*this.HBarPrime))+.32*t(this.degreesToRadians(3*this.HBarPrime+6))-.2*t(this.degreesToRadians(4*this.HBarPrime-63))},e.prototype.getHBarPrime=function(){var t=Math.abs;return t(this.hPrime1-this.hPrime2)>180?(this.hPrime1+this.hPrime2+360)/2:(this.hPrime1+this.hPrime2)/2},e.prototype.getDeltahPrime=function(){var t=Math.abs;return 0===this.C1||0===this.C2?0:t(this.hPrime1-this.hPrime2)<=180?this.hPrime2-this.hPrime1:this.hPrime2<=this.hPrime1?this.hPrime2-this.hPrime1+360:this.hPrime2-this.hPrime1-360},e.prototype.gethPrime1=function(){return this._gethPrimeFn(this.x1.B,this.aPrime1)},e.prototype.gethPrime2=function(){return this._gethPrimeFn(this.x2.B,this.aPrime2)},e.prototype._gethPrimeFn=function(t,i){var e;return 0===t&&0===i?0:(e=this.radiansToDegrees(Math.atan2(t,i)),e>=0?e:e+360)},e.prototype.radiansToDegrees=function(t){return t*(180/Math.PI)},e.prototype.degreesToRadians=function(t){return t*(Math.PI/180)},i.exports=e},{}],3:[function(t,i){"use strict";function e(t,i){this.x1=t,this.x2=i}e.prototype.getDeltaE=function(){var t=this.x1,i=this.x2;return Math.sqrt(Math.pow(i.L-t.L,2)+Math.pow(i.A-t.A,2)+Math.pow(i.B-t.B,2))},i.exports=e},{}],4:[function(t,i){"use strict";function e(t,i,e){this.x1=t,this.x2=i,this.weights=e||{},this.weights.lightness=this.weights.lightness||1,this.weights.chroma=this.weights.chroma||1,this.weights.hue=this.weights.hue||1,1===this.weights.lightness?(this.weights.K1=.045,this.weights.K2=.015):(this.weights.K1=.048,this.weights.K2=.014)}e.prototype.getDeltaE=function(){var t=this.x1,i=this.x2,e=Math.sqrt,s=Math.pow;return e(s(this.calculateL(t,i),2)+s(this.calculateA(t,i),2)+s(this.calculateB(t,i),2))},e.prototype.calculateL=function(t,i){return(t.L-i.L)/this.weights.lightness},e.prototype.calculateA=function(t,i){var e=Math.sqrt,s=Math.pow,h=e(s(t.A,2)+s(t.B,2)),r=e(s(i.A,2)+s(i.B,2)),a=h-r,n=1+this.weights.K1*h;return a/(this.weights.chroma*n)},e.prototype.calculateB=function(t,i){var e=Math.sqrt,s=Math.pow,h=e(s(t.A,2)+s(t.B,2)),r=e(s(i.A,2)+s(i.B,2)),a=h-r,n=t.A-i.A,o=t.B-i.B,u=e(s(n,2)+s(o,2)-s(a,2)),h=e(s(t.A,2)+s(t.B,2)),m=1+this.weights.K2*h;return u/m},i.exports=e},{}]},{},[1])(1)});