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
Copy file name to clipboardExpand all lines: README.md
+19-4Lines changed: 19 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,21 +47,36 @@ features = ["libm"] # Makes it use libm instead of std for float math
47
47
48
48
## It's Never "Just RGB"
49
49
50
-
Colors in, for example, images are often "gamma corrected" or stored in sRGB format as a compression method and to prevent banding. This is also a bit of a legacy from the ages of the CRT monitors, where the output from the electron gun was nonlinear. The problem is that these formats don't represent the actual intensities, and the compression has to be reverted to make sure that any operations on the colors are accurate. This library uses a completely linear work flow, and comes with the tools for transitioning between linear and non-linear RGB.
50
+
Colors in, for example, images, are often "gamma corrected", or converted using some non-linear transfer function into a format like sRGB before being stored or displayed. This is done as a compression method and to prevent banding, and is also a bit of a legacy from the ages of the CRT monitors, where the output from the electron gun was nonlinear. The problem is that these formats are *non-linear color spaces*, which means that many operations that you may want to perform on colors (addition, subtraction, multiplication, linear interpolation, etc.) will work unexpectedly when performed in such a non-linear color space. As such, the compression has to be reverted to restore linearity and make sure that many operations on the colors are accurate.
51
51
52
-
Adding to that, there are more than one kind of non-linear RGB. Ironically enough, this turns RGB into one of the most complex color spaces.
52
+
But, even when colors *are* 'linear', there is yet more to explore.
53
+
54
+
The most common way that colors are defined, especially for computer storage, is in terms of so-called *tristimulus values*, meaning that all colors are defined as a vector of three values which may represent any color. The reason colors can generally be stored as only a three dimensional vector, and not an *n* dimensional one, where *n* is some number of possible frequencies of light, is because our eyes contain only three types of cones. Each of these cones have different sensitivity curves to different wavelengths of light, giving us three "dimensions" of sensitivity to color. These cones are often called the S, M, and L (for small, medium, and large) cones, and their sensitivity curves *roughly* position them as most sensitive to "red", "green", and "blue" parts of the spectrum. As such, we can choose only three values to represent any possible color that a human is able to see. An interesting consequence of this is that humans can see two different objects which are emitting *completely different actual light spectra* as the *exact same perceptual color* so long as those wavelengths, when transformed by the sensitivity curves of our cones, end up resulting in the same S, M, and L values sent to our brains.
55
+
56
+
A **color space** (which simply refers to a set of standards by which we map a set of arbitrary values to real-world colors) which uses tristimulus values is often defined in terms of
57
+
58
+
1. Its **primaries**
59
+
2. Its **reference white** or **white point**
60
+
61
+
The **primaries** together represent the total *gamut* (i.e. displayable range of colors) of that color space, while the **white point** defines which concrete tristimulus value corresponds to a real, physical white reflecting object being lit by a known light source and observed by the 'standard observer' (i.e. a standardized model of human color perception).
62
+
63
+
The informal "RGB" color space is such a tristimulus color space, since it is defined by three values, but it is underspecified since we don't know which primaries are being used (i.e. how exactly are the canonical "red", "green", and "blue" defined?), nor its white point. In most cases, when people talk about "RGB" or "Linear RGB" colors, what they are *actually* talking about is the "Linear sRGB" color space, which uses the primaries and white point defined in the sRGB standard, but which *does not* have the (non-linear) sRGB *transfer function* applied.
64
+
65
+
This library takes these things into account, and attempts to provide an interface which will let those who don't care so much about the intricacies of color still use colors correctly, while also allowing the advanced user a high degree of flexibility in how they use it.
53
66
54
67
## What It Can Do
55
68
56
69
Palette provides tools for both color manipulation and conversion between color spaces. These are some highlights.
57
70
58
71
### Color Spaces
59
72
60
-
RGB is probably the most widely known color space, but it's not the only one. You have probably used a color picker with a rainbow wheel and a brightness slider. That may have been an HSV or an HSL color picker, where the color is encoded as hue, saturation and brightness/lightness. There's also a group of color spaces that are designed to be perceptually uniform, meaning that the perceptual change is equal to the numerical change.
73
+
"RGB" (which we now know, from the discussion above, is usually actually referring to the **Linear sRGB** color space) is probably the most widely known color space, and is great when you want to perform physically plausible math on color (such as in a 2d or 3d rendering program) but it's not the only one. You have probably used a color picker with a rainbow wheel and a brightness slider. That may have been an HSV or an HSL color picker, where the color is encoded as hue, saturation and brightness/lightness. Even though these spaces are defined using 3 values, they *aren't* based on tristimulus values, since those three values don't have a direct relation to human vision (i.e. our S, M, and L cones). Such color spaces are excellent when it comes to humans intuitively selecting color values, though, and as such are the go-to choice when this interaction is needed. They can then be converted into other color spaces in order to actually perform operations on those colors.
74
+
75
+
There's also a group of color spaces that are designed to be perceptually uniform, meaning that the perceptual change is equal to the numerical change. An example of this is the CIE L\*a\*b\* color space. These color spaces are excellent when you want to "blend" between colors in a *perceptually pleasing* manner (for example, in a data visualization) rather than a *physically correct* one.
61
76
62
77
Selecting the proper color space can have a big impact on how the resulting image looks (as illustrated by some of the programs in `examples`), and Palette makes the conversion between them as easy as a call to `from_color` or `into_color`.
63
78
64
-
This example takes an sRGB color, converts it to CIE L\*C\*h°, shifts its hue by 180° and converts it back to RGB:
79
+
This example takes an sRGB color, converts it to CIE L\*C\*h°, a color space similar to the colloquial HSL/HSV color spaces, shifts its hue by 180° and converts it back to RGB:
0 commit comments