Color.HSL (Color v0.4.0)

Copy Markdown

HSL color space — hue, saturation, lightness.

All channels are unit floats in [0, 1]. HSL is a non-linear reparameterisation of sRGB, so conversions to any CIE space route through Color.SRGB.

Summary

Types

t()

A non-linear HSL reparameterisation of sRGB. All three components are unit floats: h in [0.0, 1.0] (one full turn), s and l in [0.0, 1.0].

Functions

Converts an sRGB color to HSL.

Converts a CIE XYZ color to HSL via sRGB.

Converts an HSL color to sRGB.

Converts an HSL color to CIE XYZ via sRGB.

Types

t()

@type t() :: %Color.HSL{
  alpha: Color.Types.alpha(),
  h: float() | nil,
  l: float() | nil,
  s: float() | nil
}

A non-linear HSL reparameterisation of sRGB. All three components are unit floats: h in [0.0, 1.0] (one full turn), s and l in [0.0, 1.0].

Functions

from_srgb(srgb)

Converts an sRGB color to HSL.

Arguments

  • srgb is a Color.SRGB struct with unit-range channels.

Returns

Examples

iex> {:ok, hsl} = Color.HSL.from_srgb(%Color.SRGB{r: 1.0, g: 0.0, b: 0.0})
iex> {hsl.h, hsl.s, hsl.l}
{0.0, 1.0, 0.5}

from_xyz(xyz)

Converts a CIE XYZ color to HSL via sRGB.

Arguments

Returns

to_srgb(hsl)

Converts an HSL color to sRGB.

Arguments

Returns

Examples

iex> {:ok, srgb} = Color.HSL.to_srgb(%Color.HSL{h: 0.0, s: 1.0, l: 0.5})
iex> {srgb.r, srgb.g, srgb.b}
{1.0, 0.0, 0.0}

to_xyz(hsl)

Converts an HSL color to CIE XYZ via sRGB.

Arguments

Returns