palette/cam16/math/
luminance.rsuse crate::{
bool_mask::LazySelect,
cam16::BakedParameters,
num::{Arithmetics, FromScalar, PartialCmp, Real, Sqrt, Zero},
};
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub(crate) enum LuminanceType<T> {
Lightness(T),
Brightness(T),
}
impl<T> LuminanceType<T> {
pub(crate) fn into_cam16<Wp>(self, parameters: BakedParameters<Wp, T::Scalar>) -> (T, T)
where
T: Real + FromScalar + Zero + Arithmetics + Sqrt + PartialCmp + Clone,
T::Mask: LazySelect<T> + Clone,
{
let parameters = parameters.inner;
match self {
LuminanceType::Lightness(lightness) => {
let is_black = lightness.eq(&T::zero());
let brightness = lazy_select! {
if is_black => T::zero(),
else => crate::cam16::math::lightness_to_brightness(
lightness.clone(),
T::from_scalar(parameters.c),
T::from_scalar(parameters.a_w),
T::from_scalar(parameters.f_l_4),
)
};
(lightness, brightness)
}
LuminanceType::Brightness(brightness) => {
let is_black = brightness.eq(&T::zero());
let lightness = lazy_select! {
if is_black => T::zero(),
else => crate::cam16::math::brightness_to_lightness(
brightness.clone(),
T::from_scalar(parameters.c),
T::from_scalar(parameters.a_w),
T::from_scalar(parameters.f_l_4),
)
};
(lightness, brightness)
}
}
}
}