node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…

color-diff

Implemets the CIEDE2000 color difference algorithm, conversion between RGB and LAB color and mapping all colors in palette X to the closest or most different color in palette Y based on the CIEDE2000 difference.

Color-diff

Implements the CIEDE2000 color difference algorithm, conversion between RGB and LAB color and mapping all colors in palette X to the closest color in palette Y based on the CIEDE2000 difference.

npm install color-diff --save

Are located in the test/ folder and are run by:

npm test
var diff = require('color-diff');

Returns the closest color. The parameter bc is optional and is used as background color when the color and/or palette uses alpha channels.

var color = { R: 255, G: 1, B: 30 };
// red, green, blue 
var palette = [ {R: 255, G: 0, B: 0 },
                {R: 0, G: 255, B: 0 },
                {R: 0, G: 0, B: 255} ];
 
diff.closest(color, palette); // {R: 255, G: 0, B: 0 }, red 

The result above is obvious, but diff.closest could deal with more complicated cases.

Returns the most different color. The parameter bc is optional and is used as background color when the color and/or palette uses alpha channels.

var color = { R: 255, G: 255, B: 255 };
// black, white 
var palette = [ {R: 0, G: 0, B: 0 }, {R: 255, G: 255, B: 255 } ];
 
diff.furthest(color, palette); // {R: 0, G: 0, B: 0 }, black 

The result above is obvious, but diff.furthest could deal with more complicated cases.

Returns a mapping from the colors in palette1 to palette2.

Object

color is an object containing 3 properties: 'R', 'G', 'B', such as:

{ R: 255, G: 1, B: 0 }

There is an optional property 'A', which specifies the alpha channel between 0.0 and 1.0.

Each RGBA-color is transformed into a RGB-color before being used to calculate the CIEDE2000 difference, using the specified background color (defaults to white).

Array.<Object>

Color palette array which contains many color-like objects.

Markus Ekholm

3-clause BSD. For details see COPYING.