palette/okhsl/
properties.rs

1use crate::{hues::OklabHueIter, white_point::D65};
2
3use crate::{
4    bool_mask::LazySelect,
5    num::{Arithmetics, PartialCmp, Real},
6    stimulus::Stimulus,
7    FromColor, OklabHue, Xyz,
8};
9
10use super::Okhsl;
11
12impl_is_within_bounds! {
13    Okhsl {
14        saturation => [Self::min_saturation(), Self::max_saturation()],
15        lightness => [Self::min_lightness(), Self::max_lightness()]
16    }
17    where T: Stimulus
18}
19impl_clamp! {
20    Okhsl {
21        saturation => [Self::min_saturation(), Self::max_saturation()],
22        lightness => [Self::min_lightness(), Self::max_lightness()]
23    }
24    other {hue}
25    where T: Stimulus
26}
27
28impl_mix_hue!(Okhsl {
29    saturation,
30    lightness
31});
32impl_lighten!(Okhsl increase {lightness => [Self::min_lightness(), Self::max_lightness()]} other {hue, saturation}  where T: Stimulus);
33impl_saturate!(Okhsl increase {saturation => [Self::min_saturation(), Self::max_saturation()]} other {hue, lightness}  where T: Stimulus);
34impl_hue_ops!(Okhsl, OklabHue);
35
36impl_color_add!(Okhsl, [hue, saturation, lightness]);
37impl_color_sub!(Okhsl, [hue, saturation, lightness]);
38
39impl_array_casts!(Okhsl<T>, [T; 3]);
40impl_simd_array_conversion_hue!(Okhsl, [saturation, lightness]);
41impl_struct_of_array_traits_hue!(Okhsl, OklabHueIter, [saturation, lightness]);
42
43impl_eq_hue!(Okhsl, OklabHue, [hue, saturation, lightness]);
44
45#[allow(deprecated)]
46impl<T> crate::RelativeContrast for Okhsl<T>
47where
48    T: Real + Arithmetics + PartialCmp,
49    T::Mask: LazySelect<T>,
50    Xyz<D65, T>: FromColor<Self>,
51{
52    type Scalar = T;
53
54    #[inline]
55    fn get_contrast_ratio(self, other: Self) -> T {
56        let xyz1 = Xyz::from_color(self);
57        let xyz2 = Xyz::from_color(other);
58
59        crate::contrast_ratio(xyz1.y, xyz2.y)
60    }
61}