https://github.com/dajudge/color-diff
A library for comparing colors.
https://github.com/dajudge/color-diff
Last synced: 4 months ago
JSON representation
A library for comparing colors.
- Host: GitHub
- URL: https://github.com/dajudge/color-diff
- Owner: dajudge
- License: other
- Created: 2018-02-28T12:22:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-13T12:58:46.000Z (over 7 years ago)
- Last Synced: 2025-07-15T06:00:40.586Z (12 months ago)
- Language: Java
- Size: 76.2 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# color-diff
[](https://gitlab.com/dajudge/color-diff/commits/master)
[](http://search.maven.org/#search%7Cga%7C1%7Cg%3Acom.dajudge.color-diff%20a%3Acolor-diff)
__Disclaimer__: This project aims to be a 1:1 port of Markus Ekholm's great
[color-diff](https://github.com/markusn/color-diff) library which is
written in Javascript (hence the occasional untypical naming convention).
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.
## Installation
color-diff is available on maven central. It works on JDK 8 and later. Use the following snipped in
your `pom.xml` to add it as a dependency:
```xml
com.dajudge.color-diff
color-diff
0.0.4
```
If you're using gradle then you'll want something like this:
```groovy
buildscript {
repositories {
mavenCentral()
}
}
dependencies {
compile 'com.dajudge.color-diff:color-diff:0.0.4'
}
```
color-diff has no transitive dependencies, so you won't face any compatiblity issues.
## Build / Tests
If you want to build it yourself just checkout the source and run the following command:
```
./gradlew clean build
```
Tests are implemented in JUnit 5 and run with the build.
## Usage
### ColorDiff.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.
```java
RgbColor color = new RgbColor(255, 1, 30);
List palette = Arrays.asList(
new RgbColor(255, 0, 0), // red
new RgbColor(0, 255, 0), // green
new RgbColor(0, 0, 255) // blue
);
RgbColor closestMatch = ColorDiff.closest(color, palette);
assertEquals(new RgbColor(255, 0, 0), closestMatch); // red
```
The result above is obvious, but `ColorDiff.closest()` could deal with more complicated
cases.
### ColorDiff.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.
```java
RgbColor color = new RgbColor(255, 255, 255); // white
List palette = Arrays.asList(
new RgbColor(0, 0, 0), // black
new RgbColor(255, 255, 255) // white
);
RgbColor furthestMatch = ColorDiff.furthest(color, palette);
assertEquals(new RgbColor(0,0,0), furthestMatch); // black
```
The result above is obvious, but `ColorDiff.furthest()` could deal with more
complicated cases.
### ColorDiff.map_palette(palette1, palette2)
Returns a mapping from the colors in `palette1` to `palette2`.
#### RgbColor
`RgbColor` is type containing 3 properties: `R`, `G`, `B`, such as:
```java
RgbColor color = new RgbColor(255, 1, 0);
```
There is an optional (i.e. nullable) property `A`, which specifies
the alpha channel between 0.0 and 1.0.
```java
RgbColor colorWithAlpha = new RgbColor(255, 1, 0, .5);
```
Each RGBA-color is transformed into a RGB-color before being used to calculate
the CIEDE2000 difference, using the specified background color (which defaults to white).
## Authors
Original Javascript version by Markus Ekholm
Java port by Alex Stockinger
## License
3-clause BSD. For details see `COPYING`.