1//! Linear encoding
23use core::marker::PhantomData;
45use crate::{
6 luma::LumaStandard,
7 rgb::{RgbSpace, RgbStandard},
8};
910use super::{FromLinear, IntoLinear};
1112/// A generic standard with linear components.
13#[derive(Copy, Clone, Debug, PartialEq, Eq)]
14pub struct Linear<S>(PhantomData<S>);
1516impl<Sp> RgbStandard for Linear<Sp>
17where
18Sp: RgbSpace,
19{
20type Space = Sp;
21type TransferFn = LinearFn;
22}
2324impl<Wp> LumaStandard for Linear<Wp> {
25type WhitePoint = Wp;
26type TransferFn = LinearFn;
27}
2829/// 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;
3637impl<T> IntoLinear<T, T> for LinearFn {
38#[inline(always)]
39fn into_linear(x: T) -> T {
40 x
41 }
42}
4344impl<T> FromLinear<T, T> for LinearFn {
45#[inline(always)]
46fn from_linear(x: T) -> T {
47 x
48 }
49}