Skip to content

Commit

Permalink
Adds DIN99o color difference; v 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
danburzo committed Apr 20, 2018
1 parent 12220b4 commit fc05893
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,3 @@
### 0.1.3

Addeed the DIN99o Delta-E color difference formula.
12 changes: 11 additions & 1 deletion 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

Expand Down Expand Up @@ -64,6 +64,14 @@ _Note:_ 螖E\*<sub>CMC</sub> is not considered a metric since it's not symmetrica

Returns a [CMC l:c (1984)][CMC] difference function with custom weighting parameters.

<a name="differenceDin99o" href="#differenceDin99o">#</a> d3.__differenceDin99o__(_a_, _b_) [<>](https://github.com/danburzo/d3-color-difference/blob/master/src/din99o.js "Source")

Computes the [DIN99o][DIN99oDE] 螖E\*<sub>99o</sub> 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_.

<a name="differenceDin99oWeighted" href="#differenceDin99oWeighted">#</a> 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

<a name="differenceWithOpacity" href="#differenceWithOpacity">#</a> d3.__differenceWithOpacity__(_differenceFunction_, _a_, _b_) [<>](https://github.com/danburzo/d3-color-difference/blob/master/src/withOpacity.js "Source")
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -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';
export { default as differenceCmc, differenceCmcWeighted } from './src/cmc';
export { default as differenceDin99o, differenceDin99oWeighted } from './src/din99o.js';
12 changes: 11 additions & 1 deletion 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",
Expand All @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions 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
}
1 change: 1 addition & 0 deletions src/euclidean.js
Expand Up @@ -30,6 +30,7 @@ function differenceEuclideanCubehelix(std, smp) {
}

export {
euclidean,
differenceEuclideanRGB,
differenceEuclideanLab,
differenceEuclideanHcl,
Expand Down
9 changes: 9 additions & 0 deletions 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();
});

0 comments on commit fc05893

Please sign in to comment.