Skip to content

Commit

Permalink
Redo some srgb gamut range computations, fix docs/definiton files acc…
Browse files Browse the repository at this point in the history
…ordingly
  • Loading branch information
danburzo committed Jul 26, 2021
1 parent b6d8a21 commit b3af2b5
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 54 deletions.
54 changes: 27 additions & 27 deletions docs/color-spaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ The CIELAB color space using the [D50 standard illuminant](https://en.wikipedia.
| Channel | Range | Description |
| ------- | --------------------- | --------------------- |
| `l` | `[0, 100]` | Lightness |
| `a` | `[-79.167, 93.408]`| Green–red component |
| `b` | `[-111.859, 93.246]`| Blue–yellow component |
| `a` | `[-79.287, 93.55]` | Green–red component |
| `b` | `[-112.029, 93.388]`| Blue–yellow component |

#### `lch`

Expand All @@ -123,7 +123,7 @@ The CIELCh color space using the D50 standard illuminant.
| Channel | Range | Description |
| ------- | --------------- | ----------- |
| `l` | `[0, 100]` | Lightness |
| `c` | `[0, 131.008]`| Chroma |
| `c` | `[0, 131.207]`| Chroma |
| `h` | `[0, 360)` | Hue |

#### `lab65`
Expand Down Expand Up @@ -161,15 +161,15 @@ let deltaE_uv = culori.colorDifferenceEuclidean('luv');
| Channel | Range | Description |
| ------- | --------------------- | --------------------- |
| `l` | `[0, 100]` | Lightness |
| `u` | `[-84.86, 174.87]` | Green–red component |
| `v` | `[-125.744, 87.165]`| Blue–yellow component |
| `u` | `[-84.936, 175.042]`| Green–red component |
| `v` | `[-125.882, 87.243]`| Blue–yellow component |

#### `lchuv`

| Channel | Range | Description |
| ------- | --------------- | ----------- |
| `l` | `[0, 100]` | Lightness |
| `c` | `[0, 176.609]`| Chroma |
| `c` | `[0, 176.956]`| Chroma |
| `h` | `[0, 360)` | Hue |

### DIN99 Lab / LCh
Expand All @@ -182,11 +182,11 @@ The [DIN99][din99o] color space "squishes" the CIELAB D65 color space to obtain

The DIN99o color space in Cartesian form.

| Channel | Range | Description |
| ------- | ------------------- | ----------- |
| `l` | `[0, 100]` | Lightness |
| `a` | `[-40.09, 45.5]` |
| `b` | `[-40.47, 44.344]`|
| Channel | Range | Description |
| ------- | -------------------- | ----------- |
| `l` | `[0, 100]` | Lightness |
| `a` | `[-40.09, 45.501]`|
| `b` | `[-40.469, 44.344]`|

#### `dlch`

Expand Down Expand Up @@ -234,8 +234,8 @@ The J<sub>z</sub>a<sub>z</sub>b<sub>z</sub> color space in Cartesian form.

| Channel | Range | Description |
| ------- | ------------------ | --------------------- |
| `j` | `[0, 0.221]`| Lightness |
| `a` | `[-0.108, 0.129]`| Green–red component |
| `j` | `[0, 0.222]`| Lightness |
| `a` | `[-0.109, 0.129]`| Green–red component |
| `b` | `[-0.185, 0.134]`| Blue–yellow component |

#### `jch`
Expand All @@ -244,7 +244,7 @@ The J<sub>z</sub>a<sub>z</sub>b<sub>z</sub> color space in cylindrical form.

| Channel | Range | Description |
| ------- | ------------- | ----------- |
| `j` | `[0, 0.221]`| Lightness |
| `j` | `[0, 0.222]`| Lightness |
| `c` | `[0, 0.190]`| Chroma |
| `h` | `[0, 360)` | Hue |

Expand All @@ -255,8 +255,8 @@ The J<sub>z</sub>a<sub>z</sub>b<sub>z</sub> color space in cylindrical form.
| Channel | Range | Description |
| ------- | ------------------ | ------------------------------ |
| Y | `[0, 1]` | Luma |
| I | `[-0.593, 0.593]`| In-phase (orange-blue axis) |
| Q | `[-0.520, 0.520]`| Quadrature (green-purple axis) |
| I | `[-0.595, 0.595]`| In-phase (orange-blue axis) |
| Q | `[-0.522, 0.522]`| Quadrature (green-purple axis) |

### CIE XYZ

Expand All @@ -268,19 +268,19 @@ The CIE XYZ color space in respect to the D50 standard illuminant.

| Channel | Range | Description |
| ------- | ------------- | ----------- |
| X | `[0, 0.962]`| ? |
| Y | `[0, 0.997]`| ? |
| Z | `[0, 0.823]`| ? |
| X | `[0, 0.964]`| ? |
| Y | `[0, 0.999]`| ? |
| Z | `[0, 0.825]`| ? |

#### `xyz65`

The CIE XYZ color space in respect to the D65 standard illuminant.

| Channel | Range | Description |
| ------- | ------------- | ----------- |
| X | `[0, 0.946]`| ? |
| Y | `[0, 0.995]`| ? |
| Z | `[0, 1.083]`| ? |
| X | `[0, 0.950]`| ? |
| Y | `[0, 1]` | ? |
| Z | `[0, 1.088]`| ? |

### Cubehelix

Expand All @@ -294,11 +294,11 @@ It was expanded into a cylindrical color space by [Mike Bostock](https://en.wiki

The channels in the `cubehelix` color space maintain the conventions from D3, namely:

| Channel | Range | Description |
| ------- | ------------- | ------------------------------------------------------------------------ |
| `h` | `[0, 360)` | Hue (Based on _start color_ and _rotations_ as defined in Green's paper) |
| `s` | `[0, 4.6143]` | Saturation (Called _hue_ in op. cit.) |
| `l` | `[0, 1]` | Lightness |
| Channel | Range | Description |
| ------- | ------------ | ------------------------------------------------------------------------ |
| `h` | `[0, 360)` | Hue (Based on _start color_ and _rotations_ as defined in Green's paper) |
| `s` | `[0, 4.614]` | Saturation (Called _hue_ in op. cit.) |
| `l` | `[0, 1]` | Lightness |

[din99o]: https://de.wikipedia.org/wiki/DIN99-Farbraum
[yiq]: https://en.wikipedia.org/wiki/YIQ
3 changes: 2 additions & 1 deletion src/cubehelix/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const definition = {

ranges: {
h: [0, 360],
s: [0, 4.6143]
s: [0, 4.614],
l: [0, 1]
},

input: {
Expand Down
4 changes: 2 additions & 2 deletions src/dlab/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const definition = {

ranges: {
l: [0, 100],
a: [-40.09, 45.5],
b: [-40.47, 44.344]
a: [-40.09, 45.501],
b: [-40.469, 44.344]
},

interpolate: {
Expand Down
4 changes: 2 additions & 2 deletions src/jab/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const definition = {
},

ranges: {
j: [0, 0.221],
a: [-0.108, 0.129],
j: [0, 0.222],
a: [-0.109, 0.129],
b: [-0.185, 0.134]
},

Expand Down
4 changes: 2 additions & 2 deletions src/lab/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const definition = {

ranges: {
l: [0, 100],
a: [-79.167, 93.408],
b: [-111.859, 93.246]
a: [-79.287, 93.55],
b: [-112.029, 93.388]
},

parsers: [parseLab],
Expand Down
4 changes: 2 additions & 2 deletions src/lab65/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const definition = {

ranges: {
l: [0, 100],
a: [-86.183, 98.234],
b: [-107.86, 94.478]
a: [-86.182, 98.234],
b: [-107.86, 94.477]
},

parsers: []
Expand Down
2 changes: 1 addition & 1 deletion src/lch/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const definition = {

ranges: {
l: [0, 100],
c: [0, 131.008],
c: [0, 131.207],
h: [0, 360]
},

Expand Down
2 changes: 1 addition & 1 deletion src/lchuv/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const definition = {

ranges: {
l: [0, 100],
c: [0, 131.008],
c: [0, 176.956],
h: [0, 360]
},

Expand Down
4 changes: 2 additions & 2 deletions src/luv/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const definition = {

ranges: {
l: [0, 100],
u: [-84.86, 174.87],
v: [-125.744, 87.165]
u: [-84.936, 175.042],
v: [-125.882, 87.243]
},

interpolate: {
Expand Down
6 changes: 3 additions & 3 deletions src/xyz/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const definition = {
channels: ['x', 'y', 'z', 'alpha'],

ranges: {
x: [0, 0.962],
y: [0, 0.997],
z: [0, 0.823]
x: [0, 0.964],
y: [0, 0.999],
z: [0, 0.825]
},

interpolate: {
Expand Down
6 changes: 3 additions & 3 deletions src/xyz65/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const definition = {
},

ranges: {
x: [0, 0.946],
y: [0, 0.995],
z: [0, 1.083]
x: [0, 0.95],
y: [0, 1],
z: [0, 1.088]
},

channels: ['x', 'y', 'z', 'alpha'],
Expand Down
4 changes: 2 additions & 2 deletions src/yiq/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const definition = {
channels: ['y', 'i', 'q', 'alpha'],

ranges: {
i: [-0.593, 0.593],
q: [-0.52, 0.52]
i: [-0.595, 0.595],
q: [-0.522, 0.522]
},

interpolate: {
Expand Down
13 changes: 7 additions & 6 deletions tools/ranges.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ let ranges = (mode, step = 0.01) => {
(acc, ch) => ((acc[ch] = [Infinity, -Infinity]), acc),
{}
);
let r, g, b, c;
let r, g, b, c, v;
for (r = 0; r <= 1; r += step) {
for (g = 0; g <= 1; g += step) {
for (b = 0; b <= 1; b += step) {
c = conv({ mode: 'rgb', r, g, b });
chs.forEach(ch => {
if (c[ch] < res[ch][0]) {
res[ch][0] = c[ch];
v = c[ch];
if (v < res[ch][0]) {
res[ch][0] = v;
}
if (c[ch] > res[ch][1]) {
res[ch][1] = c[ch];
if (v > res[ch][1]) {
res[ch][1] = v;
}
});
}
Expand All @@ -31,4 +32,4 @@ let ranges = (mode, step = 0.01) => {
return res;
};

console.log(ranges('oklch', 0.0025));
console.log(ranges(process.argv[2], 0.0025));

0 comments on commit b3af2b5

Please sign in to comment.