Debian Codegraph @

src/encoding/gamma.rs

raw symbols SCIP
1 //! Gamma encoding.
2
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::{markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#};
4
5 use craterust-analyzer cargo palette 0.7.6 crate/::{
6 lumarust-analyzer cargo palette 0.7.6 luma/::LumaStandardrust-analyzer cargo palette 0.7.6 luma/LumaStandard#,
7 numrust-analyzer cargo palette 0.7.6 num/::{Onerust-analyzer cargo palette 0.7.6 num/One#, Powfrust-analyzer cargo palette 0.7.6 num/Powf#, Realrust-analyzer cargo palette 0.7.6 num/Real#},
8 rgbrust-analyzer cargo palette 0.7.6 rgb/::{RgbSpacerust-analyzer cargo palette 0.7.6 rgb/RgbSpace#, RgbStandardrust-analyzer cargo palette 0.7.6 rgb/RgbStandard#},
9 };
10
11 use superrust-analyzer cargo palette 0.7.6 encoding/::{FromLinearrust-analyzer cargo palette 0.7.6 encoding/FromLinear#, IntoLinearrust-analyzer cargo palette 0.7.6 encoding/IntoLinear#};
12
13 /// Gamma encoding.
14 ///
15 /// Gamma encoding or gamma correction is used to transform the intensity
16 /// values to either match a non-linear display, like CRT, or to prevent
17 /// banding among the darker colors. `GammaRgb` represents a gamma corrected
18 /// RGB color, where the intensities are encoded using the following power-law
19 /// expression: _V<sup> γ</sup>_ (where _V_ is the intensity value an _γ_ is the
20 /// encoding gamma).
21 ///
22 /// The gamma value is stored as a simple type that represents an `f32`
23 /// constant.
24 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
25 pub struct Gammarust-analyzer cargo palette 0.7.6 encoding/gamma/Gamma#<S, N: Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number# = F2p2rust-analyzer cargo palette 0.7.6 encoding/gamma/F2p2#>(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<(S, N)>);
26
27 impl<Sp, N> RgbStandardrust-analyzer cargo palette 0.7.6 rgb/RgbStandard# for Gammarust-analyzer cargo palette 0.7.6 encoding/gamma/Gamma#<Sp, N>
28 where
29 Sp: RgbSpacerust-analyzer cargo palette 0.7.6 rgb/RgbSpace#,
30 N: Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number#,
31 {
32 type Spacerust-analyzer cargo palette 0.7.6 encoding/gamma/impl#[`Gamma<Sp, N>`][RgbStandard]Space# = Sp;
33 type TransferFnrust-analyzer cargo palette 0.7.6 encoding/gamma/impl#[`Gamma<Sp, N>`][RgbStandard]TransferFn# = GammaFnrust-analyzer cargo palette 0.7.6 encoding/gamma/GammaFn#<N>;
34 }
35
36 impl<Wp, N> LumaStandardrust-analyzer cargo palette 0.7.6 luma/LumaStandard# for Gammarust-analyzer cargo palette 0.7.6 encoding/gamma/Gamma#<Wp, N>
37 where
38 N: Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number#,
39 {
40 type WhitePointrust-analyzer cargo palette 0.7.6 encoding/gamma/impl#[`Gamma<Wp, N>`][LumaStandard]WhitePoint# = Wp;
41 type TransferFnrust-analyzer cargo palette 0.7.6 encoding/gamma/impl#[`Gamma<Wp, N>`][LumaStandard]TransferFn# = GammaFnrust-analyzer cargo palette 0.7.6 encoding/gamma/GammaFn#<N>;
42 }
43
44 /// The transfer function for gamma encoded colors.
45 ///
46 /// Conversion is performed using a single `powf(x, gamma)` and `powf(x, 1.0 /
47 /// gamma)` call, for from and into linear respectively. This makes
48 /// `GammaFn<F2p2>` usable as a slightly less expensive approximation of the
49 /// [`Srgb`][super::Srgb] transfer function.
50 ///
51 /// The gamma value is stored as a simple type that represents an `f32`
52 /// constant.
53 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
54 pub struct GammaFnrust-analyzer cargo palette 0.7.6 encoding/gamma/GammaFn#<N: Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number# = F2p2rust-analyzer cargo palette 0.7.6 encoding/gamma/F2p2#>(PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<N>);
55
56 impl<T, N> IntoLinearrust-analyzer cargo palette 0.7.6 encoding/IntoLinear#<T, T> for GammaFnrust-analyzer cargo palette 0.7.6 encoding/gamma/GammaFn#<N>
57 where
58 T: Realrust-analyzer cargo palette 0.7.6 num/Real# + Onerust-analyzer cargo palette 0.7.6 num/One# + Powfrust-analyzer cargo palette 0.7.6 num/Powf# + Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#Output# = T>,
59 N: Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number#,
60 {
61 #[inline]
62 fn into_linearrust-analyzer cargo palette 0.7.6 encoding/gamma/impl#[`GammaFn<N>`][`IntoLinear<T, T>`]into_linear().(x: T) -> T {
63 x.powfrust-analyzer cargo palette 0.7.6 num/Powf#powf().(T::onerust-analyzer cargo palette 0.7.6 num/One#one().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(N::VALUErust-analyzer cargo palette 0.7.6 encoding/gamma/Number#VALUE.))
64 }
65 }
66
67 impl<T, N> FromLinearrust-analyzer cargo palette 0.7.6 encoding/FromLinear#<T, T> for GammaFnrust-analyzer cargo palette 0.7.6 encoding/gamma/GammaFn#<N>
68 where
69 T: Realrust-analyzer cargo palette 0.7.6 num/Real# + Powfrust-analyzer cargo palette 0.7.6 num/Powf#,
70 N: Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number#,
71 {
72 #[inline]
73 fn from_linearrust-analyzer cargo palette 0.7.6 encoding/gamma/impl#[`GammaFn<N>`][`FromLinear<T, T>`]from_linear().(x: T) -> T {
74 x.powfrust-analyzer cargo palette 0.7.6 num/Powf#powf().(T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(N::VALUErust-analyzer cargo palette 0.7.6 encoding/gamma/Number#VALUE.))
75 }
76 }
77
78 /// A type level float constant.
79 pub trait Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number#: 'static {
80 /// The represented number.
81 const VALUErust-analyzer cargo palette 0.7.6 encoding/gamma/Number#VALUE.: f64;
82 }
83
84 /// Represents `2.2f64`.
85 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
86 pub struct F2p2rust-analyzer cargo palette 0.7.6 encoding/gamma/F2p2#;
87
88 impl Numberrust-analyzer cargo palette 0.7.6 encoding/gamma/Number# for F2p2rust-analyzer cargo palette 0.7.6 encoding/gamma/F2p2# {
89 const VALUErust-analyzer cargo palette 0.7.6 encoding/gamma/impl#[F2p2][Number]VALUE.: f64 = 2.2;
90 }