use colr_types::tonemap::Tonemap;
use crate::BackingStore;
use crate::ChannelMap;
use crate::Color;
use crate::model::Rgb;
use crate::primaries::Primaries;
use crate::transfer::Linear;
impl<P, L> Color<[f32; 3], Rgb<P, Linear, L>>
where
P: Primaries,
L: BackingStore<[f32; 3]> + ChannelMap<3>,
{
#[inline(always)]
pub fn tonemap<TMO: Tonemap<[f32; 3]>>(self) -> Self {
let s = self.inner();
let [ri, gi, bi] = L::INDICES;
let mapped = TMO::tonemap([s[ri], s[gi], s[bi]]);
let mut out = [0.0f32; 3];
out[ri] = mapped[0];
out[gi] = mapped[1];
out[bi] = mapped[2];
Color::new(out)
}
}
impl<P, L> Color<[f32; 4], Rgb<P, Linear, L>>
where
P: Primaries,
L: BackingStore<[f32; 4]> + ChannelMap<4>,
{
#[inline(always)]
pub fn tonemap<TMO: Tonemap<[f32; 3]>>(self) -> Self {
let s = self.inner();
let [ri, gi, bi, ai] = L::INDICES;
let mapped = TMO::tonemap([s[ri], s[gi], s[bi]]);
let mut out = [0.0f32; 4];
out[ri] = mapped[0];
out[gi] = mapped[1];
out[bi] = mapped[2];
out[ai] = s[ai];
Color::new(out)
}
}