Skip to main content

GamutMatrix

Struct GamutMatrix 

Source
pub struct GamutMatrix(/* private fields */);
Expand description

A 3×3 row-major matrix between linear-light tristimulus spaces, in f32.

The array stays private so that the representation can change. Kernels read it through rows.

use zenpixels_convert::{Primaries, gamut::GamutMatrix};

let to_srgb = GamutMatrix::between(Primaries::DisplayP3, Primaries::Bt709).unwrap();
let mut row = [[1.0_f32, 1.0, 1.0], [0.5, 0.5, 0.5]];
to_srgb.apply_row_rgb(&mut row);
assert!((row[1][0] - 0.5).abs() < 1e-4, "gray stays gray");

Implementations§

Source§

impl GamutMatrix

Source

pub const fn from_rows(rows: [[f32; 3]; 3]) -> Self

A matrix from its rows.

Source

pub const fn rows(&self) -> &[[f32; 3]; 3]

The rows, for a kernel that takes them directly.

Source

pub const fn to_xyz(primaries: Primaries) -> Option<&'static Self>

Linear RGB in primaries → CIE XYZ (D65), or None for unknown primaries.

Source

pub const fn from_xyz(primaries: Primaries) -> Option<&'static Self>

CIE XYZ (D65) → linear RGB in primaries, or None for unknown primaries.

Source

pub const fn between(from: Primaries, to: Primaries) -> Option<Self>

The matrix taking linear RGB in from to linear RGB in to.

Equal primaries give the identity. None when either is Unknown.

Source

pub fn then(&self, next: &Self) -> Self

The matrix that applies self, then next: next × self.

Source

pub fn inverse(&self) -> Option<Self>

The inverse, or None for a singular matrix.

Source

pub fn apply(&self, [r, g, b]: [f32; 3]) -> [f32; 3]

This matrix applied to one color.

Source

pub fn apply_row_rgb(&self, row: &mut [[f32; 3]])

Apply in place to a row of RGB pixels in linear light.

Source

pub fn apply_row_rgba(&self, row: &mut [[f32; 4]])

Apply in place to a row of RGBA pixels in linear light. Alpha is unchanged.

Trait Implementations§

Source§

impl Clone for GamutMatrix

Source§

fn clone(&self) -> GamutMatrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for GamutMatrix

Source§

impl Debug for GamutMatrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for GamutMatrix

Source§

fn eq(&self, other: &GamutMatrix) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GamutMatrix

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.