pub struct ColorMatrix {
pub matrix: [[f32; 5]; 4],
}Expand description
A 4×5 colour transformation matrix.
Each output channel is:
out_R = m[0][0]*R + m[0][1]*G + m[0][2]*B + m[0][3]*A + m[0][4]
out_G = m[1][0]*R + m[1][1]*G + m[1][2]*B + m[1][3]*A + m[1][4]
out_B = m[2][0]*R + m[2][1]*G + m[2][2]*B + m[2][3]*A + m[2][4]
out_A = m[3][0]*R + m[3][1]*G + m[3][2]*B + m[3][3]*A + m[3][4]Fields§
§matrix: [[f32; 5]; 4]Row-major 4×5 matrix: rows are [R, G, B, A] output channels.
Implementations§
Source§impl ColorMatrix
impl ColorMatrix
Sourcepub fn brightness(factor: f32) -> Self
pub fn brightness(factor: f32) -> Self
Scale all RGB channels by factor. Alpha is unchanged.
Sourcepub fn contrast(factor: f32) -> Self
pub fn contrast(factor: f32) -> Self
Contrast adjustment around the midpoint 0.5.
A factor of 1.0 is a no-op; values above 1.0 increase contrast.
Sourcepub fn saturation(factor: f32) -> Self
pub fn saturation(factor: f32) -> Self
Saturation adjustment.
Uses ITU-R BT.601 luma weights. factor = 0 → greyscale, factor = 1
→ no change, factor > 1 → more saturated.
Sourcepub fn hue_rotate(degrees: f32) -> Self
pub fn hue_rotate(degrees: f32) -> Self
Hue rotation by degrees.
Implemented as a rotation in the colour-opponent plane after projecting out the luminance axis (Hacker-level approximation suitable for real-time use).
Sourcepub fn apply(&self, pixel: Rgba) -> Rgba
pub fn apply(&self, pixel: Rgba) -> Rgba
Apply the matrix to a single pixel, clamping the result to [0, 1].
Sourcepub fn compose(&self, other: &ColorMatrix) -> ColorMatrix
pub fn compose(&self, other: &ColorMatrix) -> ColorMatrix
Compose two matrices: self ∘ other (apply other first, then self).
The 4×5 matrices are augmented to 5×5 (with an implicit row [0,0,0,0,1]) for standard homogeneous composition, then the result is trimmed back to 4×5.
Trait Implementations§
Source§impl Clone for ColorMatrix
impl Clone for ColorMatrix
Source§fn clone(&self) -> ColorMatrix
fn clone(&self) -> ColorMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more