diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..05633b5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +### 0.1.3 + +Addeed the DIN99o Delta-E color difference formula. \ No newline at end of file diff --git a/README.md b/README.md index a3d2cd4..8a7cc99 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # d3-color-difference -See this [Observable notebook](https://beta.observablehq.com/@danburzo/color-difference-formulas-with-d3-color-difference). +See this [Observable notebook](https://beta.observablehq.com/@danburzo/color-difference-formulas-with-d3-color-difference) for a demonstration. ## Installing @@ -64,6 +64,14 @@ _Note:_ ΔE\*CMC is not considered a metric since it's not symmetrica Returns a [CMC l:c (1984)][CMC] difference function with custom weighting parameters. +# d3.__differenceDin99o__(_a_, _b_) [<>](https://github.com/danburzo/d3-color-difference/blob/master/src/din99o.js "Source") + +Computes the [DIN99o][DIN99oDE] ΔE\*99o color difference between the colors _a_ and _b_. The computation is done in the [DIN99o][DIN99o] color space with the default weights _kCH = kE = 1_. + +# d3.__differenceDin99oWeighted__(_kCH_, _kE_) [<>](https://github.com/danburzo/d3-color-difference/blob/master/src/din99o.js "Source") + +Returns a [DIN99o][DIN99oDE] difference function with custom weighting parameters. + ### Opacity # d3.__differenceWithOpacity__(_differenceFunction_, _a_, _b_) [<>](https://github.com/danburzo/d3-color-difference/blob/master/src/withOpacity.js "Source") @@ -76,6 +84,8 @@ The difference functions don't take the colors' alpha channel into account when [CIE94]: https://en.wikipedia.org/wiki/Color_difference#CIE94 [CIEDE2000]: https://en.wikipedia.org/wiki/Color_difference#CIEDE2000 [CMC]: https://en.wikipedia.org/wiki/Color_difference#CMC_l:c_(1984) +[DIN99o]: https://de.wikipedia.org/wiki/DIN99-Farbraum +[DIN99oDE]: https://de.wikipedia.org/wiki/DIN99-Farbraum#Farbabstandsformel [RGB]: https://github.com/d3/d3-color#rgb [HSL]: https://github.com/d3/d3-color#hsl [Lab]: https://github.com/d3/d3-color#lab diff --git a/index.js b/index.js index 5af994a..3b10e4e 100644 --- a/index.js +++ b/index.js @@ -8,4 +8,5 @@ export { } from './src/euclidean'; export { default as differenceCie94, differenceCie94Weighted } from './src/cie94'; export { default as differenceCiede2000, differenceCiede2000Weighted } from './src/ciede2000'; -export { default as differenceCmc, differenceCmcWeighted } from './src/cmc'; \ No newline at end of file +export { default as differenceCmc, differenceCmcWeighted } from './src/cmc'; +export { default as differenceDin99o, differenceDin99oWeighted } from './src/din99o.js'; \ No newline at end of file diff --git a/package.json b/package.json index 71db6f6..f4930f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d3-color-difference", - "version": "0.1.1", + "version": "0.1.3", "main": "build/d3-color-difference.js", "module": "index", "jsnext:main": "index", @@ -11,6 +11,16 @@ "name": "Dan Burzo", "url": "http://danburzo.ro" }, + "keywords": [ + "d3", + "d3-color", + "color", + "color-difference", + "cie76", + "cie94", + "ciede2000", + "cmc" + ], "devDependencies": { "eslint": "^4.19.1", "package-preamble": "^0.1.0", diff --git a/src/din99o.js b/src/din99o.js new file mode 100644 index 0000000..195f944 --- /dev/null +++ b/src/din99o.js @@ -0,0 +1,39 @@ +import { lab } from 'd3-color'; +import { euclidean } from './euclidean'; + +var θ = 26 / 180 * Math.PI; +var cosθ = Math.cos(θ); +var sinθ = Math.sin(θ); +var factor = 100/Math.log(139/100); // ~ 303.67 + +function din99o(color, kCH, kE) { + var l = factor / kE * Math.log(1 + 0.0039 * color.l); + if (color.a === 0 && color.b === 0) { + return lab(l, 0, 0); // achromatic colors + } + var e = color.a * cosθ + color.b * sinθ; + var f = 0.83 * (color.b * cosθ - color.a * sinθ); + var G = Math.sqrt(e * e + f * f); + var c = Math.log(1 + 0.075 * G) / (0.0435 * kCH * kE); + var h = (Math.atan2(f, e) + θ) / Math.PI * 180; + return lab(l, c * Math.cos(h / 180 * Math.PI), c * Math.sin(h / 180 * Math.PI)); +} + +function differenceDin99o(kCH, kE) { + + kCH = kCH !== undefined ? kCH : 1; + kE = kE !== undefined ? kE : 1; + + return function(std, smp) { + std = din99o(lab(std), kCH, kE); + smp = din99o(lab(smp), kCH, kE); + return euclidean(std.l, std.a, std.b, smp.l, smp.a, smp.b); + } +} + +var differenceDin99oDefault = differenceDin99o(); + +export { + differenceDin99oDefault as default, + differenceDin99o as differenceDin99oWeighted +} \ No newline at end of file diff --git a/src/euclidean.js b/src/euclidean.js index 4cdae4a..d75dabe 100644 --- a/src/euclidean.js +++ b/src/euclidean.js @@ -30,6 +30,7 @@ function differenceEuclideanCubehelix(std, smp) { } export { + euclidean, differenceEuclideanRGB, differenceEuclideanLab, differenceEuclideanHcl, diff --git a/test/din99o-test.js b/test/din99o-test.js new file mode 100644 index 0000000..6531370 --- /dev/null +++ b/test/din99o-test.js @@ -0,0 +1,9 @@ +var tape = require('tape'); +var diff = require('../'); + +tape('', function(test) { + + test.equal(diff.differenceDin99o('red', 'green'), 68.61703579396708); + + test.end(); +});