Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Set default charset and indentation style
[*.{js,json,html,dust,styl,yml,md}]
charset = utf-8
indent_style = space
indent_size = 2
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"root": true,
"extends": [
"eslint-config-exp/all"
]
}
28 changes: 28 additions & 0 deletions .github/workflows/build-latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Built latest

on:
push:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/build-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Built pull request

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ reference/
jscoverage_lib/
temp/
coverage/


.eslintcache
.nyc_output
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

## 1.3.0

* don't support mixing casing for r,g,b properties, either all upper or all lower
* use camelCase instead of snake_case
* snake_case -> camelCase mappings are still present to not break more dependents than necessary.
* fixed jsdoc types and type checking using tsc
* only run tests on node > 18
* no more travis, use github actions
* bumped all deps
* added linting
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012-2016, Markus Ekholm
Copyright (c) 2012-2023, Markus Ekholm
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
72 changes: 51 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Color-diff
[![Build Status](https://travis-ci.com/markusn/color-diff.png)](https://travis-ci.com/markusn/color-diff)
# color-diff
[![Build Status](https://github.com/markusn/color-diff/actions/workflows/build-latest.yaml/badge.svg?branch=master)](https://github.com/markusn/color-diff/actions/workflows/build-latest.yaml)
[![Coverage Status](https://coveralls.io/repos/markusn/color-diff/badge.png?branch=master)](https://coveralls.io/r/markusn/color-diff?branch=master)

Implements the CIEDE2000 color difference algorithm, conversion between RGB and
Expand All @@ -16,80 +16,110 @@ npm install color-diff --save

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

npm test

```bash
npm test
```

## Usage

```js
var diff = require('color-diff');
const {
closest,
furthest,
diff,
mapPalette,
paletteMapKey,
rgbaToLab,
mapPaletteLab,
labPaletteMapKey,
} = require('color-diff');
```

### diff.closest(color, palette, bc)
### closest(color, palette, bc)

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

```js
var color = { R: 255, G: 1, B: 30 };
const color = { R: 255, G: 1, B: 30 };
// red, green, blue
var palette = [ {R: 255, G: 0, B: 0 },
const 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
closest(color, palette); // {R: 255, G: 0, B: 0 }, red
```

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

### diff.furthest(color, palette, bc)
### furthest(color, palette, bc)

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.

```js
var color = { R: 255, G: 255, B: 255 };
const color = { R: 255, G: 255, B: 255 };
// black, white
var palette = [ {R: 0, G: 0, B: 0 }, {R: 255, G: 255, B: 255 } ];
const palette = [ {R: 0, G: 0, B: 0 }, {R: 255, G: 255, B: 255 } ];

diff.furthest(color, palette); // {R: 0, G: 0, B: 0 }, black
furthest(color, palette); // {R: 0, G: 0, B: 0 }, black
```

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


### diff.map_palette(palette1, palette2)
### mapPalette(palette1, palette2)

Returns a mapping from the colors in palette1 to palette2.

### paletteMapKey(color)

Return the palette map key for the color, to be used with the result from mapPalette.

### diff(color1, color2, bc)

Returns the difference between the lab colors color1 and color2. The parameter bc is optional and
is used as background color when one of the colors uses alpha channels.

#### rgba color

#### color
`Object`

`color` is an object containing 3 properties: 'R', 'G', 'B' (case insensitive), such as:
`RGBAColor` is an object containing 4 properties: 'R', 'G', 'B', 'A', where 'A' is optional OR
'r', 'g', 'b', 'a', where 'a' is optional . Such as:

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

There is an optional property 'A', which specifies the alpha channel between 0.0
and 1.0.
and 1.0. If not present the color will be treated as fully opaque, i.e. A = 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).

#### palette
### lab color

`Array.<Object>`
`Object`

Color palette array which contains many `color`-like objects.
`LabColor` is an object containing 3 properties 'L', 'a', 'b' such as:

```js
{ L: 100, a: 0.005, b: -0.010 }
```

#### palette

`Array.<RGBAColor>`

Color palette array which contains many `RGBAColor` objects.

## Author

Markus Ekholm

## License

3-clause BSD. For details see `COPYING`.
Loading