Color.RGB.WorkingSpace (Color v0.4.0)

Copy Markdown

Summary

Functions

Looks up an RGB working space by its CSS Color 4 name.

Returns the RGB→XYZ and XYZ→RGB conversion matrices for a named RGB working space, computed from its primaries and reference white using the Lindbloom formulas.

Returns the CSS Color 4 name for an internal working-space atom, or nil if there isn't one.

Functions

from_css_name(name)

@spec from_css_name(String.t()) :: {:ok, atom()} | {:error, Exception.t()}

Looks up an RGB working space by its CSS Color 4 name.

Arguments

  • name is a string.

Returns

  • {:ok, atom} — the internal working-space atom.

  • {:error, reason} if the name is unknown.

Examples

iex> Color.RGB.WorkingSpace.from_css_name("display-p3")
{:ok, :P3_D65}

iex> Color.RGB.WorkingSpace.from_css_name("srgb")
{:ok, :SRGB}

rgb_conversion_matrix(rgb_space)

@spec rgb_conversion_matrix(atom()) ::
  {:ok,
   %{
     to_xyz: list(),
     from_xyz: list(),
     illuminant: atom(),
     observer_angle: 2 | 10,
     gamma: term()
   }}
  | {:error, Exception.t()}

Returns the RGB→XYZ and XYZ→RGB conversion matrices for a named RGB working space, computed from its primaries and reference white using the Lindbloom formulas.

Arguments

  • rgb_space is the working-space atom (for example :sRGB, :Adobe, :ProPhoto).

Returns

  • An {:ok, %{to_xyz: m, from_xyz: mi, illuminant: atom, observer_angle: 2}} tuple where m and mi are 3x3 matrices represented as lists of rows.

  • {:error, reason} when the working space is unknown.

Examples

iex> {:ok, %{to_xyz: [[a, _, _] | _]}} = Color.RGB.WorkingSpace.rgb_conversion_matrix(:SRGB)
iex> Float.round(a, 4)
0.4125

rgb_working_spaces()

to_css_name(atom)

@spec to_css_name(atom()) :: String.t() | nil

Returns the CSS Color 4 name for an internal working-space atom, or nil if there isn't one.

Arguments

  • atom is a working-space atom.

Returns

  • A string or nil.

Examples

iex> Color.RGB.WorkingSpace.to_css_name(:P3_D65)
"display-p3"

iex> Color.RGB.WorkingSpace.to_css_name(:SRGB)
"srgb"

iex> Color.RGB.WorkingSpace.to_css_name(:Bruce)
nil