Skip to content

Commit

Permalink
lib.rs Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Beinsezii committed Dec 16, 2023
1 parent f852c6f commit dfea29f
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use core::cmp::Ordering;
use core::ffi::{c_char, CStr};

const LAB_DELTA: f32 = 6.0 / 29.0;

// ### MATRICES ### {{{
// CIE XYZ
const XYZ65_MAT: [[f32; 3]; 3] = [
Expand Down Expand Up @@ -70,9 +68,13 @@ fn matmul3t(pixel: [f32; 3], matrix: [[f32; 3]; 3]) -> [f32; 3] {
}
// ### MATRICES ### }}}

/// 'Standard' Illuminant D65.
// ### UTILITIES ### {{{

/// Standard Illuminant D65.
pub const D65: [f32; 3] = [0.9504559270516716, 1.0, 1.0890577507598784];

const LAB_DELTA: f32 = 6.0 / 29.0;

/// Expand gamma of a single value to linear light
#[inline]
#[no_mangle]
Expand All @@ -94,6 +96,9 @@ pub extern "C" fn correct_gamma(n: f32) -> f32 {
1.055 * (n.powf(1.0 / 2.4)) - 0.055
}
}
// ### UTILITIES ### }}}

// ### Helmholtz-Kohlrausch ### {{{

/// Extended K-values from High et al 2021/2022
const K_HIGH2022: [f32; 4] = [0.1644, 0.0603, 0.1307, 0.0060];
Expand Down Expand Up @@ -131,6 +136,10 @@ pub extern "C" fn hk_comp_2023(lch: &mut [f32; 3]) {
lch[0] += HIGH2023_MEAN * (lch[1] / 100.0) - hk_delta_2023(lch)
}

// ### Helmholtz-Kohlrausch ### }}}

// ### Space ### {{{

/// Defines colorspace pixels will take.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Space {
Expand Down Expand Up @@ -222,6 +231,10 @@ impl PartialOrd for Space {
}
}

// ### Space ### }}}

// ### Convert Space ### {{{

/// Runs conversion functions to convert `pixel` from one `Space` to another
/// in the least possible moves.
pub fn convert_space(from: Space, to: Space, pixel: &mut [f32; 3]) {
Expand Down Expand Up @@ -375,7 +388,9 @@ pub fn convert_space_alpha(from: Space, to: Space, pixel: &mut [f32; 4]) {
}
}

// UP {{{
// ### Convert Space ### }}}

// ### UP ### {{{

/// Convert floating (0.0..1.0) RGB to integer (0..255) RGB.
/// Simply clips values > 1.0 && < 0.0.
Expand Down Expand Up @@ -489,9 +504,9 @@ pub extern "C" fn lab_to_lch(pixel: &mut [f32; 3]) {
];
}

// UP }}}
// ### UP ### }}}

// DOWN {{{
// ### DOWN ### {{{

/// Convert integer (0..255) RGB to floating (0.0..1.0) RGB.
/// Not RGB specific, but other formats typically aren't represented as integers.
Expand Down Expand Up @@ -625,7 +640,7 @@ pub extern "C" fn lch_to_lab(pixel: &mut [f32; 3]) {

// DOWN }}}

// TESTS {{{
// ### TESTS ### {{{
#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -654,7 +669,9 @@ mod tests {
});
}

fn pixcmp(a: [f32; 3], b: [f32; 3]) { pixcmp_eps(a, b, 1e-4) }
fn pixcmp(a: [f32; 3], b: [f32; 3]) {
pixcmp_eps(a, b, 1e-4)
}

#[test]
fn hsv_to() {
Expand Down Expand Up @@ -858,4 +875,4 @@ mod tests {
}
}
}
// TESTS }}}
// ### TESTS ### }}}

0 comments on commit dfea29f

Please sign in to comment.