Debian Codegraph @

src/encoding/linear.rs

raw symbols SCIP
1 //! Linear encoding
2
3 use core::marker::PhantomData;
4
5 use crate::{
6 luma::LumaStandard,
7 rgb::{RgbSpace, RgbStandard},
8 };
9
10 use super::{FromLinear, IntoLinear};
11
12 /// A generic standard with linear components.
13 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
14 pub struct Linear<S>(PhantomData<S>);
15
16 impl<Sp> RgbStandard for Linear<Sp>
17 where
18 Sp: RgbSpace,
19 {
20 type Space = Sp;
21 type TransferFn = LinearFn;
22 }
23
24 impl<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)]
35 pub struct LinearFn;
36
37 impl<T> IntoLinear<T, T> for LinearFn {
38 #[inline(always)]
39 fn into_linear(x: T) -> T {
40 x
41 }
42 }
43
44 impl<T> FromLinear<T, T> for LinearFn {
45 #[inline(always)]
46 fn from_linear(x: T) -> T {
47 x
48 }
49 }