Skip to content

Commit

Permalink
Add inline to matrix functions
Browse files Browse the repository at this point in the history
  • Loading branch information
okaneco committed Apr 19, 2020
1 parent fb1798e commit 07ac642
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions palette/src/matrix.rs
Expand Up @@ -14,6 +14,7 @@ use crate::{FloatComponent, Xyz};
pub type Mat3<T> = [T; 9];

/// Multiply the 3x3 matrix with an XYZ color.
#[inline]
pub fn multiply_xyz<Swp: WhitePoint, Dwp: WhitePoint, T: FloatComponent>(
c: &Mat3<T>,
f: &Xyz<Swp, T>,
Expand All @@ -39,6 +40,7 @@ pub fn multiply_xyz<Swp: WhitePoint, Dwp: WhitePoint, T: FloatComponent>(
}
}
/// Multiply the 3x3 matrix with an XYZ color to return an RGB color.
#[inline]
pub fn multiply_xyz_to_rgb<S: RgbSpace, T: FloatComponent>(
c: &Mat3<T>,
f: &Xyz<S::WhitePoint, T>,
Expand All @@ -55,6 +57,7 @@ pub fn multiply_xyz_to_rgb<S: RgbSpace, T: FloatComponent>(
}
}
/// Multiply the 3x3 matrix with an RGB color to return an XYZ color.
#[inline]
pub fn multiply_rgb_to_xyz<S: RgbSpace, T: FloatComponent>(
c: &Mat3<T>,
f: &Rgb<Linear<S>, T>,
Expand All @@ -72,6 +75,7 @@ pub fn multiply_rgb_to_xyz<S: RgbSpace, T: FloatComponent>(
}

/// Multiply two 3x3 matrices.
#[inline]
pub fn multiply_3x3<T: Float>(c: &Mat3<T>, f: &Mat3<T>) -> Mat3<T> {
// Input Mat3 are destructured to avoid panic paths
let [c0, c1, c2, c3, c4, c5, c6, c7, c8] = *c;
Expand All @@ -93,6 +97,7 @@ pub fn multiply_3x3<T: Float>(c: &Mat3<T>, f: &Mat3<T>) -> Mat3<T> {
}

/// Invert a 3x3 matrix and panic if matrix is not invertible.
#[inline]
pub fn matrix_inverse<T: Float>(a: &Mat3<T>) -> Mat3<T> {
// This function runs fastest with assert and no destructuring. The `det`'s
// location should not be changed until benched that it's faster elsewhere
Expand Down Expand Up @@ -128,6 +133,7 @@ pub fn matrix_inverse<T: Float>(a: &Mat3<T>) -> Mat3<T> {
}

/// Generates the Srgb to Xyz transformation matrix for a given white point.
#[inline]
pub fn rgb_to_xyz_matrix<S: RgbSpace, T: FloatComponent>() -> Mat3<T> {
let r: Xyz<S::WhitePoint, T> = S::Primaries::red().into_color_unclamped();
let g: Xyz<S::WhitePoint, T> = S::Primaries::green().into_color_unclamped();
Expand Down Expand Up @@ -155,6 +161,7 @@ pub fn rgb_to_xyz_matrix<S: RgbSpace, T: FloatComponent>() -> Mat3<T> {
}

#[rustfmt::skip]
#[inline]
fn mat3_from_primaries<T: FloatComponent, Wp: WhitePoint>(r: Xyz<Wp, T>, g: Xyz<Wp, T>, b: Xyz<Wp, T>) -> Mat3<T> {
[
r.x, g.x, b.x,
Expand Down

0 comments on commit 07ac642

Please sign in to comment.