https://github.com/hsluv/hsluv-java
Java implementation of HSLuv (revision 4)
https://github.com/hsluv/hsluv-java
Last synced: 9 months ago
JSON representation
Java implementation of HSLuv (revision 4)
- Host: GitHub
- URL: https://github.com/hsluv/hsluv-java
- Owner: hsluv
- License: mit
- Created: 2016-04-19T17:16:52.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-06-28T08:21:02.000Z (almost 2 years ago)
- Last Synced: 2024-12-23T21:11:42.983Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 1.51 MB
- Stars: 24
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/hsluv/hsluv-java/actions/workflows/test.yml)
[](http://repo1.maven.org/maven2/org/hsluv/hsluv/)
[](http://www.javadoc.io/doc/org.hsluv/hsluv)
About: http://www.hsluv.org
# Installation
If you are using Maven, add the following to your `pom.xml` file:
org.hsluv
hsluv
1.0
# Usage
The API is designed to avoid heap allocation. The `HSLuv` class defines the following public fields:
- RGB: `hex:String`, `rgb_r` [0;1], `rgb_g` [0;1], `rgb_r` [0;1]
- CIE XYZ: `xyz_x`, `xyz_y`, `xyz_z`
- CIE LUV: `luv_l`, `luv_u`, `luv_v`
- CIE LUV LCh: `lch_l`, `lch_c`, `lch_h`
- HSLuv: `hsluv_h` [0;360], `hsluv_s` [0;100], `hsluv_l` [0;100]
- HPLuv: `hpluv_h` [0;360], `hpluv_p` [0;100], `hpluv_l` [0;100]
To convert between color spaces, simply set the properties of the source color space, run the
conversion methods, then read the properties of the target color space.
Use the following methods to convert to and from RGB:
- HSLuv: `hsluvToRgb()`, `hsluvToHex()`, `rgbToHsluv()`, `hexToHsluv()`
- HPLuv: `hpluvToRgb()`, `hpluvToHex()`, `rgbToHpluv()`, `hexToHpluv()`
Use the following methods to do step-by-step conversion:
- Forward: `hsluvToLch()` (or `hpluvToLch()`), `lchToLuv()`, `luvToXyz()`, `xyzToRgb()`, `rgbToHex()`
- Backward: `hexToRgb()`, `rgbToXyz()`, `xyzToLuv()`, `luvToLch()`, `lchToHsluv()` (or `lchToHpluv()`)
For advanced usage, we also export the [bounding lines](https://www.hsluv.org/math/) in slope-intercept
format, two for each RGB channel representing the limit of the gamut.
- R < 0: `r0s`, `r0i`
- R > 1: `r1s`, `r1i`
- G < 0: `g0s`, `g0i`
- G > 1: `g1s`, `g1i`
- B < 0: `b0s`, `b0i`
- B > 1: `b1s`, `b1i`
Example:
```java
HsluvColorConverter conv = new HsluvColorConverter();
conv.hsluv_h = 10;
conv.hsluv_s = 75;
conv.hsluv_l = 65;
conv.hsluvToHex();
System.out.println(conv.hex); // Will print "#ec7d82"
```
# Testing
mvn test
# Deployment
Docs:
- https://central.sonatype.org/publish/publish-maven/
- https://central.sonatype.org/publish/requirements/gpg/
Set `~/m2/settings.xml`:
```xml
ossrh
hsluv
REDACTEDREDACTEDREDACTED
ossrh
true
REDACTEDREDACTEDREDACTED
```
Then run:
```bash
mvn versions:set -DnewVersion=0.3 # bump version
mvn clean deploy -P release
```