Color.RGB
(Color v0.4.0)
Copy Markdown
Linear (un-companded) RGB relative to a named working space.
See Color.SRGB for the companded sRGB working-space color type.
This module covers every RGB working space listed in
Color.RGB.WorkingSpace: :SRGB, :Adobe, :ProPhoto, :Rec709,
:Rec2020 etc. Channels are unit floats.
The working-space conversion matrix is computed lazily and memoised
in :persistent_term, so the first call for a given working space
pays the Lindbloom derivation cost once and subsequent calls are a
plain :persistent_term.get/1.
Summary
Types
Linear RGB in any named working space. The working_space field
identifies which set of primaries and reference white to use; see
Color.RGB.WorkingSpace.rgb_working_spaces/0 for the full list.
Functions
Converts a CIE XYZ color to linear RGB in the given working space.
Converts a linear RGB color to CIE XYZ.
Types
@type t() :: %Color.RGB{ alpha: Color.Types.alpha(), b: float() | nil, g: float() | nil, r: float() | nil, working_space: Color.Types.working_space() | nil }
Linear RGB in any named working space. The working_space field
identifies which set of primaries and reference white to use; see
Color.RGB.WorkingSpace.rgb_working_spaces/0 for the full list.
Functions
Converts a CIE XYZ color to linear RGB in the given working space.
Arguments
xyzis aColor.XYZstruct. Its illuminant must match the working space — if not, chromatically adapt first.working_spaceis an atom naming the target RGB working space.
Returns
- A
Color.RGBstruct.
Examples
iex> xyz = %Color.XYZ{x: 0.95047, y: 1.0, z: 1.08883, illuminant: :D65, observer_angle: 2}
iex> {:ok, rgb} = Color.RGB.from_xyz(xyz, :SRGB)
iex> {Float.round(rgb.r, 3), Float.round(rgb.g, 3), Float.round(rgb.b, 3)}
{1.0, 1.0, 1.0}
Converts a linear RGB color to CIE XYZ.
Arguments
rgbis aColor.RGBstruct whose:working_spacenames an RGB working space (for example:SRGB,:Adobe,:ProPhoto).
Returns
- A
Color.XYZstruct tagged with the working space's illuminant and 2° observer angle.
Examples
iex> {:ok, xyz} = Color.RGB.to_xyz(%Color.RGB{r: 1.0, g: 1.0, b: 1.0, working_space: :SRGB})
iex> {Float.round(xyz.x, 4), Float.round(xyz.y, 4)}
{0.9505, 1.0}