Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds DIN99o color difference; v 0.1.3
- Loading branch information
Showing
7 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### 0.1.3 | ||
|
||
Addeed the DIN99o Delta-E color difference formula. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var tape = require('tape'); | ||
var diff = require('../'); | ||
|
||
tape('', function(test) { | ||
|
||
test.equal(diff.differenceDin99o('red', 'green'), 68.61703579396708); | ||
|
||
test.end(); | ||
}); |