palette/encoding/
linear.rs

1//! Linear encoding
2
3use core::marker::PhantomData;
4
5use crate::{
6    luma::LumaStandard,
7    rgb::{RgbSpace, RgbStandard},
8};
9
10use super::{FromLinear, IntoLinear};
11
12/// A generic standard with linear components.
13#[derive(Copy, Clone, Debug, PartialEq, Eq)]
14pub struct Linear<S>(PhantomData<S>);
15
16impl<Sp> RgbStandard for Linear<Sp>
17where
18    Sp: RgbSpace,
19{
20    type Space = Sp;
21    type TransferFn = LinearFn;
22}
23
24impl<Wp> LumaStandard for Linear<Wp> {
25    type WhitePoint = Wp;
26    type TransferFn = LinearFn;
27}
28
29/// Linear color component encoding.
30///
31/// Converting anything from linear to linear space is a no-op and constant
32/// time. This is a useful property in generic code, where the transfer
33/// functions may be unknown.
34#[derive(Copy, Clone, Debug, PartialEq, Eq)]
35pub struct LinearFn;
36
37impl<T> IntoLinear<T, T> for LinearFn {
38    #[inline(always)]
39    fn into_linear(x: T) -> T {
40        x
41    }
42}
43
44impl<T> FromLinear<T, T> for LinearFn {
45    #[inline(always)]
46    fn from_linear(x: T) -> T {
47        x
48    }
49}