sRGB primitives and constants
The crate provides primitives for manipulating colours in sRGB colour space.
Specifically, it provides functions for converting between sRGB, linear sRGB and XYZ colour spaces; exposes definition of the D65 reference white point together with XYZ conversion matrices; and finally provides functions for handling Rec.709 components encoding.
It intents to offer low-level primitives needed to work with sRGB colour space. Those primitives can be used by other libraries which need to convert between sRGB and other colour spaces (if the conversion requires going through XYZ colour space) or blend colours together (which requires performing gamma correction).
Functions provided in the main module implement conversions between
sRGB and XYZ colour spaces. Functions in [gamma
] submodule provide
functions for doing gamma compression and expansion; they operate on
a single colour component. Lastly, [xyz
] submodule provides
functions for converting between linear sRGB and XYZ colour spaces as
well as constants exposing the matrices used by those functions.
The crate includes highly-optimised 8-bit gamma functions both when converting from an 8-bit compressed value to a floating point linear value as well as conversion in the opposite direction. The latter is over two and a half times faster than naïve implementation of the gamma compression formula.
Usage
Using this package with Cargo projects requires adding a single dependency:
[]
= "0.3"
With it in place, it’s now possible to write an application which converts an sRGB colour into other colour spaces:
;
rgb
crate support
This crate crate does not have an explicit rgb
crate support. However, since all
functions taking an (s)RGB colour as argument accept impl Into<[f32; 3]>
or impl Into<[u8; 3]>
it is possible to pass RGB
structure to
them. Similarly, such functions return [f32; 3]
or [u8; 3]
which
can be converted into an RGB
structure.
extern crate rgb;
use ComponentMap;