You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some color spaces (Lab and LCh in particular) allow you to express colors that can't be displayed on-screen. The methods below allow you to identify when that's the case and to produce displayable versions of the colors.
Given a color space, returns a function with which to check whether a particular color is within the gamut of that color space.
291
+
292
+
This is meant to be used with RGB-based color spaces and their derivates (`hsl`, `hsv`, etc.). If the color space has no gamut limits, the function will always return `true`, regardless of the color passed to it. To find out which color spaces have gamut limits, see the [Color Spaces](/color-spaces/) page.
293
+
294
+
```js
295
+
import { inGamut } from'culori';
296
+
297
+
constinRgb=inGamut('rgb');
298
+
299
+
inRgb('red');
300
+
// ⇒ true
301
+
302
+
inRgb('color(srgb 1.1 0 0)');
303
+
// ⇒ false
304
+
```
305
+
284
306
<aid="displayable"href="#displayable">#</a> **displayable**(_color_ or _string_) → _boolean_
This function extends the functionality of `clampRgb` to other color spaces. Given a color space, it returns a function with which to obtain colors within the gamut of that color space.
343
+
344
+
If the color space has no gamut limits, colors are returned unchanged. To find out which color spaces have gamut limits, see the [Color Spaces](/color-spaces/) page.
345
+
346
+
The in-gamut color is always returned in the color space of the original color.
Copy file name to clipboardExpand all lines: docs/color-spaces.md
+56Lines changed: 56 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,37 +39,48 @@ The [sRGB color space](https://en.wikipedia.org/wiki/SRGB), which most people re
39
39
40
40
Serialized as `color(srgb r g b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
41
41
42
+
Has gamut limits.
43
+
42
44
#### `lrgb`
43
45
44
46
The linear-light form of the sRGB color space.
45
47
46
48
Serialized as `color(srgb-linear r g b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
47
49
50
+
Has gamut limits.
51
+
48
52
#### `a98`
49
53
50
54
The A98 RGB color space, compatible with the [Adobe RGB (1998) color space](https://en.wikipedia.org/wiki/Adobe_RGB_color_space).
51
55
52
56
Serialized as `color(a98-rgb r g b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
53
57
58
+
Has gamut limits.
59
+
54
60
#### `p3`
55
61
56
62
The [Display P3 color space](https://en.wikipedia.org/wiki/DCI-P3#Display_P3).
57
63
58
64
Serialized as `color(display-p3 r g b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
59
65
66
+
Has gamut limits.
60
67
61
68
#### `prophoto`
62
69
63
70
The [ProPhoto RGB color space](https://en.wikipedia.org/wiki/ProPhoto_RGB_color_space).
64
71
65
72
Serialized as `color(prophoto-rgb r g b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
66
73
74
+
Has gamut limits.
75
+
67
76
#### `rec2020`
68
77
69
78
The [Rec. 2020 color space](https://en.wikipedia.org/wiki/Rec._2020).
70
79
71
80
Serialized as `color(rec2020 r g b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
72
81
82
+
Has gamut limits.
83
+
73
84
### The HSL/HSV/HSI family
74
85
75
86
[HSL, HSV, and HSI](https://en.wikipedia.org/wiki/HSL_and_HSV) are alternative representations of the RGB color model, created in an attempt to provide a more intuitive way to specify colors.
@@ -90,6 +101,8 @@ The HSL color space.
90
101
91
102
Serialized as `hsl(h s% l%)`. A missing hue is serialized as `0`, with the `none` keyword for any other missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
92
103
104
+
Has gamut limits.
105
+
93
106
#### `hsv`
94
107
95
108
The HSV color space.
@@ -102,6 +115,8 @@ The HSV color space.
102
115
103
116
Serialized as `color(--hsv h s v)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
104
117
118
+
Has gamut limits.
119
+
105
120
#### `hsi`
106
121
107
122
The HSI color space.
@@ -114,6 +129,8 @@ The HSI color space.
114
129
115
130
Serialized as `color(--hsi h s i)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
116
131
132
+
Has gamut limits.
133
+
117
134
### HWB
118
135
119
136
[The HWB color model](https://en.wikipedia.org/wiki/HWB_color_model) was developed by Alvy Ray Smith, who also created the HSV color model. It's meant to be more intuitive for humans to use and faster to compute.
@@ -128,6 +145,8 @@ Serialized as `hwb(h w% b%)`.
128
145
129
146
Serialized as `hwb(h w% b%)`. A missing hue is serialized as `0`, with the `none` keyword for any other missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
130
147
148
+
Has gamut limits.
149
+
131
150
> Smith, Alvy Ray (1996) — ["HWB — A More Intuitive Hue-Based Color Model"](http://alvyray.com/Papers/CG/HWB_JGTv208.pdf), Journal of Graphics, GPU and Game tools.
132
151
133
152
### CIELAB
@@ -146,6 +165,8 @@ The CIELAB color space using the [D50 standard illuminant](https://en.wikipedia.
146
165
147
166
Serialized as `lab(l a b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
148
167
168
+
Does not have gamut limits.
169
+
149
170
#### `lch`
150
171
151
172
The CIELCh color space using the D50 standard illuminant.
@@ -158,6 +179,8 @@ The CIELCh color space using the D50 standard illuminant.
158
179
159
180
Serialized as `lch(l c h)`. A missing hue is serialized as `0`, with the `none` keyword for any other missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
160
181
182
+
Does not have gamut limits.
183
+
161
184
#### `lab65`
162
185
163
186
CIELAB relative to the D65 standard illuminant.
@@ -170,6 +193,8 @@ CIELAB relative to the D65 standard illuminant.
170
193
171
194
Serialized as `color(--lab-d65 l a b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
172
195
196
+
Does not have gamut limits.
197
+
173
198
#### `lch65`
174
199
175
200
CIELCh relative to the D65 standard illuminant.
@@ -182,6 +207,8 @@ CIELCh relative to the D65 standard illuminant.
182
207
183
208
Serialized as `color(--lch-d65 l c h)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
184
209
210
+
Does not have gamut limits.
211
+
185
212
### CIELUV
186
213
187
214
The [CIELUV color space](https://en.wikipedia.org/wiki/CIELUV) in Cartesian (Luv) and cylindrical (LCh) forms, using the D50 standard illuminant.
@@ -202,6 +229,8 @@ let deltaE_uv = culori.colorDifferenceEuclidean('luv');
202
229
203
230
Serialized as `color(--luv l u v)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
204
231
232
+
Does not have gamut limits.
233
+
205
234
#### `lchuv`
206
235
207
236
| Channel | Range | Description |
@@ -212,6 +241,8 @@ Serialized as `color(--luv l u v)`, with the `none` keyword for any missing colo
212
241
213
242
Serialized as `color(--lchuv l c h)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
214
243
244
+
Does not have gamut limits.
245
+
215
246
### DIN99 Lab / LCh
216
247
217
248
The [DIN99](https://de.wikipedia.org/wiki/DIN99-Farbraum) color space "squishes" the CIELAB D65 color space to obtain an [effective color difference](#culoriDifferenceDin99o) metric that can be expressed as a simple Euclidean distance. The latest iteration of the the standard, DIN99o, is available in Cartesian (`dlab`) and plar (`dlch`) form.
@@ -230,6 +261,8 @@ The DIN99o color space in Cartesian form.
230
261
231
262
Serialized as `color(--din99o-lab l a b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
232
263
264
+
Does not have gamut limits.
265
+
233
266
#### `dlch`
234
267
235
268
The DIN99o color space in cylindrical form.
@@ -242,6 +275,8 @@ The DIN99o color space in cylindrical form.
242
275
243
276
Serialized as `color(--din99o-lch l c h)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
244
277
278
+
Does not have gamut limits.
279
+
245
280
### Oklab, Oklch, Okhsl, Okhsv
246
281
247
282
The [Oklab color space](https://bottosson.github.io/posts/oklab/), in Cartesian (Lab) and cylindrical (LCh) forms. It uses the D65 standard illuminant.
@@ -260,6 +295,8 @@ The Oklab color space in Cartesian form.
260
295
261
296
Serialized as `oklab(l a b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
262
297
298
+
Does not have gamut limits.
299
+
263
300
#### `oklch`
264
301
265
302
The Oklab color space in cylindrical form.
@@ -272,6 +309,8 @@ The Oklab color space in cylindrical form.
272
309
273
310
Serialized as `oklch(l c h)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
274
311
312
+
Does not have gamut limits.
313
+
275
314
### `okhsl`
276
315
277
316
| Channel | Range | Description |
@@ -282,6 +321,8 @@ Serialized as `oklch(l c h)`, with the `none` keyword for any missing color chan
282
321
283
322
Serialized as `color(--okhsl h s l)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
284
323
324
+
Does not have gamut limits.
325
+
285
326
### `okhsv`
286
327
287
328
| Channel | Range | Description |
@@ -292,6 +333,8 @@ Serialized as `color(--okhsl h s l)`, with the `none` keyword for any missing co
292
333
293
334
Serialized as `color(--okhsv h s v)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
294
335
336
+
Does not have gamut limits.
337
+
295
338
#### Further reading
296
339
297
340
*[An interactive review of Oklab](https://raphlinus.github.io/color/2021/01/18/oklab-critique.html) by Raph Levien
@@ -316,6 +359,8 @@ The J<sub>z</sub>a<sub>z</sub>b<sub>z</sub> color space in Cartesian form.
316
359
317
360
Serialized as `color(--jzazbz j a b)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
318
361
362
+
Does not have gamut limits.
363
+
319
364
#### `jch`
320
365
321
366
The J<sub>z</sub>a<sub>z</sub>b<sub>z</sub> color space in cylindrical form.
@@ -328,6 +373,8 @@ The J<sub>z</sub>a<sub>z</sub>b<sub>z</sub> color space in cylindrical form.
328
373
329
374
Serialized as `color(--jzczhz j c h)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
330
375
376
+
Does not have gamut limits.
377
+
331
378
### YIQ (`yiq`)
332
379
333
380
[YIQ](https://en.wikipedia.org/wiki/YIQ) is the color space used by the NTSC color TV system. It contains the following channels:
@@ -340,6 +387,8 @@ Serialized as `color(--jzczhz j c h)`, with the `none` keyword for any missing c
340
387
341
388
Serialized as `color(--yiq y i q)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
342
389
390
+
Does not have gamut limits.
391
+
343
392
The conversion matrices between the sRGB and YIQ color spaces are taken from:
344
393
345
394
> Yuriy Kotsarenko, Fernando Ramos, [_Measuring perceived color difference using YIQ NTSC transmission color space in mobile applications_](http://www.progmat.uaem.mx:8080/artVol2Num2/Articulo3Vol2Num2.pdf), Programación Matemática y Software (2010), Vol. 2, No 2.
@@ -360,6 +409,8 @@ The CIE XYZ color space in respect to the D50 standard illuminant.
360
409
361
410
Serialized as `color(xyz-d50 x y z)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
362
411
412
+
Does not have gamut limits.
413
+
363
414
#### `xyz65`
364
415
365
416
The CIE XYZ color space in respect to the D65 standard illuminant.
@@ -372,6 +423,8 @@ The CIE XYZ color space in respect to the D65 standard illuminant.
372
423
373
424
Serialized as `color(xyz-d65 x y z)`, with the `none` keyword for any missing color channel. An explicit `alpha < 1` is included as ` / alpha`.
374
425
426
+
Does not have gamut limits.
427
+
375
428
### XYB
376
429
377
430
The XYB color model is part of [the JPEG XL Image Coding System](https://ds.jpeg.org/whitepapers/jpeg-xl-whitepaper.pdf), as an <q>LMS-based colour model inspired by the human visual system, facilitating perceptually uniform quantization. It uses a gamma of 3 for computationally efficient decoding</q>.
@@ -388,6 +441,8 @@ It has the default _Chroma from Luma_ adjustment applied (effectively Y is subtr
0 commit comments