[−][src]Module scarlet::color
This file defines the Color
trait, the foundational defining trait of the entire
library. Despite the dizzying amount of things Color
can do in Scarlet, especially with its
extending traits, the definition is quite simple: anything that can be converted to and from the
CIE 1931 XYZ space. This color space is
common to use as a master space, and Scarlet is no different. What makes XYZ unique is that it
can be computed directly from the spectral data of a color. Although Scarlet does not implement
this due to its scope, this property makes it possible to derive XYZ colors from real-world data,
something that no other color space can do the same way.
The thing that makes XYZColor
, the base implementation of the CIE 1931 XYZ
space, special is that it is the only color object in Scarlet that keeps track of its own
illuminant data. Every other color space assumes a viewing environment, but because XYZ color
maps directly to neural perception it keeps track of what environment the color is being viewed
in. This allows Scarlet to translate between color spaces that have different assumptions
seamlessly. (If you notice that Scarlet's values for conversions differ from other sources, this
may be why: some sources don't do this properly or implement it differently. Scarlet generally
follows best practices and industry standards, but file an issue if you feel this is not true.)
The essential workflow of Color
, and therefore Scarlet, is generally like this:
convert between different color spaces using the generic convert<T: Color>()
method, which allows any Color
to
be interconverted to any other representation. Leverage the specific attributes of each color
space if need be (for example, using the hue or luminance attributes), and then convert back to
a suitable display space. The many other methods of Color
make some of the more
common such patterns simple to do.
Structs
RGBColor | A color with red, green, and blue primaries of specified intensity, specifically in the sRGB
gamut: most computer screens use this to display colors. The attributes |
XYZColor | A point in the CIE 1931 XYZ color space. Although any point in XYZ coordinate space is technically valid, in this library XYZ colors are treated as normalized so that Y=1 is the white point of whatever illuminant is being worked with. |
Enums
RGBParseError | An error type that results from an invalid attempt to convert a string into an RGB color. |
Traits
Color | A trait that represents any color representation that can be converted to and from the CIE 1931 XYZ color space. See module-level documentation for more information and examples. |