Skip to main content

colr_types/model/
luma.rs

1//! Luma and luma+alpha color models.
2
3use core::marker::PhantomData;
4
5use crate::BackingStore;
6use crate::primaries::Primaries;
7use crate::transfer::TransferFunction;
8use crate::{AlphaState, Straight};
9
10/// Luma derived from an RGB space with primaries P and transfer function TF.
11///
12/// Luma Y' is the weighted sum of gamma-encoded RGB channels. The weights
13/// are the Y row of the primaries' RGB-to-XYZ matrix, so they vary by primary
14/// set.
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
16pub struct Luma<P: Primaries, TF: TransferFunction>(PhantomData<(P, TF)>);
17
18/// Luma with an alpha channel. Alpha state defaults to `Straight`.
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
20pub struct LumaAlpha<P: Primaries, TF: TransferFunction, A: AlphaState = Straight>(
21    PhantomData<(P, TF, A)>,
22);
23
24impl<P: Primaries, TF: TransferFunction> BackingStore<f32> for Luma<P, TF> {}
25impl<P: Primaries, TF: TransferFunction, A: AlphaState> BackingStore<[f32; 2]>
26    for LumaAlpha<P, TF, A>
27{
28}
29
30#[cfg(feature = "glam")]
31mod glam_impls {
32    use super::*;
33    impl<P: Primaries, TF: TransferFunction, A: AlphaState> BackingStore<glam::Vec2>
34        for LumaAlpha<P, TF, A>
35    {
36    }
37}