Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ceoss/color-diff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: markusn/color-diff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 12 commits
  • 22 files changed
  • 3 contributors

Commits on Feb 23, 2020

  1. Copy the full SHA
    cadc9ba View commit details
  2. Merge pull request markusn#18 from ceoss/lower-rgb

    Allow lowercase rgb objects, test only with deepStrictEquals
    markusn authored Feb 23, 2020
    Copy the full SHA
    6a65e9f View commit details

Commits on Mar 22, 2020

  1. bump version

    markusn committed Mar 22, 2020
    Copy the full SHA
    4530ea0 View commit details

Commits on Mar 14, 2021

  1. Update README.md

    Updated travis badge
    markusn authored Mar 14, 2021
    Copy the full SHA
    1fa343e View commit details

Commits on Apr 26, 2023

  1. Modernize and adapt to standards

    * 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 wrapper sare still present to not break more dependents than necessary.
    * the snake_case wrappers are marked as deprecated
    * 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
    markusn committed Apr 26, 2023
    Copy the full SHA
    ab19af9 View commit details
  2. Merge pull request markusn#21 from markusn/modernize

    Modernize and adapt to standards
    markusn authored Apr 26, 2023
    Copy the full SHA
    0a7010e View commit details

Commits on May 31, 2023

  1. Copy the full SHA
    2b4b95b View commit details
  2. Merge pull request markusn#22 from markusn/esm-module

    convert to esm module, cjs support using rollup
    markusn authored May 31, 2023
    Copy the full SHA
    8bf8e74 View commit details

Commits on Jul 20, 2023

  1. Bump word-wrap from 1.2.3 to 1.2.4

    Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
    - [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
    - [Commits](jonschlinkert/word-wrap@1.2.3...1.2.4)
    
    ---
    updated-dependencies:
    - dependency-name: word-wrap
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Jul 20, 2023
    Copy the full SHA
    aa5137d View commit details

Commits on Aug 7, 2023

  1. Merge pull request markusn#23 from markusn/dependabot/npm_and_yarn/wo…

    …rd-wrap-1.2.4
    
    Bump word-wrap from 1.2.3 to 1.2.4
    markusn authored Aug 7, 2023
    Copy the full SHA
    0634c07 View commit details

Commits on Sep 8, 2023

  1. use node test runner

    markusn committed Sep 8, 2023
    Copy the full SHA
    e26d4ec View commit details

Commits on Mar 8, 2024

  1. Merge pull request markusn#24 from markusn/user-node-test-runner

    use node test runner
    markusn authored Mar 8, 2024
    Copy the full SHA
    7ad453c View commit details
Showing with 4,235 additions and 989 deletions.
  1. +15 −0 .editorconfig
  2. +6 −0 .eslintrc.json
  3. +28 −0 .github/workflows/build-latest.yaml
  4. +27 −0 .github/workflows/build-pr.yaml
  5. +4 −1 .gitignore
  6. +1 −0 .nvmrc
  7. +1 −0 .prettierignore
  8. +0 −4 .travis.yml
  9. +17 −0 CHANGELOG.md
  10. +1 −1 COPYING
  11. +65 −21 README.md
  12. +214 −0 index.js
  13. +94 −72 lib/convert.js
  14. +127 −86 lib/diff.js
  15. +0 −40 lib/index.js
  16. +93 −108 lib/palette.js
  17. +2,674 −0 package-lock.json
  18. +26 −8 package.json
  19. +105 −49 test/convert.js
  20. +502 −419 test/diff.js
  21. +211 −180 test/palette.js
  22. +24 −0 tsconfig.json
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 }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -47,5 +47,8 @@ reference/
jscoverage_lib/
temp/
coverage/
.eslintcache
.nyc_output


# built using rollup
index.cjs
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
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.

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

## 1.4.0

* Use ESM modules. Backwards compatible with CJS using rollup.
* Replaced nyc with c8 (nyc does not support esm).

## 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
86 changes: 65 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Color-diff
[![Build Status](https://travis-ci.org/markusn/color-diff.png)](https://travis-ci.org/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
@@ -16,80 +17,123 @@ 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');
// CommonJS
const {
closest,
furthest,
diff,
mapPalette,
paletteMapKey,
rgbaToLab,
mapPaletteLab,
labPaletteMapKey,
} = require("color-diff");

// ESM
import {
closest,
furthest,
diff,
mapPalette,
paletteMapKey,
rgbaToLab,
mapPaletteLab,
labPaletteMapKey,
} from "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', 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