#[repr(C)]pub struct Gamma<T> {
pub exp: T,
}
color
only.Expand description
Gamma correction curves.
Used for encoding and decoding linear luminance or tristimulus values via power-law transformations (e.g. $v^γ$ and $v^{(1/γ)}$).
Fields§
§exp: T
The gamma exponent (γ
) used in the encoding/decoding transform.
Implementations§
Source§impl Gamma<f32>
Gamma encoding, decoding, and sRGB transfer functions for floating-point values.
impl Gamma<f32>
Gamma encoding, decoding, and sRGB transfer functions for floating-point values.
Sourcepub fn encode(self, v: f32) -> f32
Available on crate features std
or _float_f32
only.
pub fn encode(self, v: f32) -> f32
std
or _float_f32
only.Encodes the given linear v
alue using this gamma: $v^{(1/γ)}$.
Performs basic gamma encoding (power-law).
Sourcepub fn decode(self, v: f32) -> f32
Available on crate features std
or _float_f32
only.
pub fn decode(self, v: f32) -> f32
std
or _float_f32
only.Decodes the given gamma-encoded v
alue using this gamma: $v^γ$ .
Performs basic gamma decoding (power-law inverse).
Sourcepub fn encode_srgb(self, v: f32) -> f32
Available on crate features std
or _float_f32
only.
pub fn encode_srgb(self, v: f32) -> f32
std
or _float_f32
only.Encodes the given v
alue using the sRGB transfer function.
Applies a piecewise curve based on this gamma (typically 2.4).
§Algorithm
$$ f_\text{encode}(c) = \begin{cases} 12.92c, & \text{if } c <= 0.0031308 \cr 1.055c^{1/\gamma} - 0.055, & \text{if } c > 0.0031308 \end{cases} $$
Sourcepub fn decode_srgb(self, v: f32) -> f32
Available on crate features std
or _float_f32
only.
pub fn decode_srgb(self, v: f32) -> f32
std
or _float_f32
only.Decodes the given v
alue using the sRGB inverse transfer function.
Applies the inverse piecewise curve based on this gamma (typically 2.4).
§Algorithm
$$ \notag f_\text{decode}(c) = \begin{cases} c / 12.92, & \normalsize\text{if } c <= 0.04045 \cr \left(\Large\frac{c + 0.055}{1.055}\right)^\gamma & \normalsize \text{if } c > 0.04045 \end{cases} $$
Source§impl Gamma<f32>
Weighted RGB → luma conversion utilities using standard coefficients.
impl Gamma<f32>
Weighted RGB → luma conversion utilities using standard coefficients.
Sourcepub const SRGB: [f32; 3] = Self::REC_709
pub const SRGB: [f32; 3] = Self::REC_709
R′G′B′ coefficients for computing sRGB luma (same as Rec. 709).
Sourcepub const SRGB_GAMMA: f32 = 2.20000005f32
pub const SRGB_GAMMA: f32 = 2.20000005f32
Typical gamma value for sRGB/Rec.709 (≈2.2)
Sourcepub const SRGB_LINEAR_THRESHOLD: f32 = 0.00313080009f32
pub const SRGB_LINEAR_THRESHOLD: f32 = 0.00313080009f32
Threshold for sRGB linear segment (0.0031308)
Sourcepub const REC_1886_GAMMA: f32 = 2.4000001f32
pub const REC_1886_GAMMA: f32 = 2.4000001f32
Typical gamma value for Rec.1886 (≈2.4)
Sourcepub const fn compute_luma(rgb: [f32; 3], weights: [f32; 3]) -> f32
pub const fn compute_luma(rgb: [f32; 3], weights: [f32; 3]) -> f32
Computes luma from R′G′B′ using the given [kr, kg, kb]
weights.
Sourcepub const fn luma_srgb(rgb: [f32; 3]) -> f32
pub const fn luma_srgb(rgb: [f32; 3]) -> f32
Computes luma from R′G′B′ using Rec. 709 coefficients.
Sourcepub const fn luma_rec_709(rgb: [f32; 3]) -> f32
pub const fn luma_rec_709(rgb: [f32; 3]) -> f32
Computes luma from R′G′B′ using Rec. 709 coefficients.
Sourcepub const fn luma_rec_601(rgb: [f32; 3]) -> f32
pub const fn luma_rec_601(rgb: [f32; 3]) -> f32
Computes luma from R′G′B′ using Rec. 601 coefficients.
Sourcepub const fn luma_rec_2020(rgb: [f32; 3]) -> f32
pub const fn luma_rec_2020(rgb: [f32; 3]) -> f32
Computes luma from R′G′B′ using Rec. 2020 coefficients.
Sourcepub fn luminance_to_lightness(y: f32) -> f32
Available on crate features std
or _float_f32
only.
pub fn luminance_to_lightness(y: f32) -> f32
std
or _float_f32
only.Converts linear luminance to CIE lightness (L*)
Sourcepub fn lightness_to_luminance(l_star: f32) -> f32
Available on crate features std
or _float_f32
only.
pub fn lightness_to_luminance(l_star: f32) -> f32
std
or _float_f32
only.Converts CIE lightness (L*) to linear luminance
Source§impl Gamma<f64>
Gamma encoding, decoding, and sRGB transfer functions for floating-point values.
impl Gamma<f64>
Gamma encoding, decoding, and sRGB transfer functions for floating-point values.
Sourcepub fn encode(self, v: f64) -> f64 ⓘ
Available on crate features std
or _float_f64
only.
pub fn encode(self, v: f64) -> f64 ⓘ
std
or _float_f64
only.Encodes the given linear v
alue using this gamma: $v^{(1/γ)}$.
Performs basic gamma encoding (power-law).
Sourcepub const fn const_encode(self, v: f64) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub const fn const_encode(self, v: f64) -> f64 ⓘ
_float_f64
only.Compile-time encode
.
Sourcepub fn decode(self, v: f64) -> f64 ⓘ
Available on crate features std
or _float_f64
only.
pub fn decode(self, v: f64) -> f64 ⓘ
std
or _float_f64
only.Decodes the given gamma-encoded v
alue using this gamma: $v^γ$ .
Performs basic gamma decoding (power-law inverse).
Sourcepub const fn const_decode(self, v: f64) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub const fn const_decode(self, v: f64) -> f64 ⓘ
_float_f64
only.Compile-time decode
.
Sourcepub fn encode_srgb(self, v: f64) -> f64 ⓘ
Available on crate features std
or _float_f64
only.
pub fn encode_srgb(self, v: f64) -> f64 ⓘ
std
or _float_f64
only.Encodes the given v
alue using the sRGB transfer function.
Applies a piecewise curve based on this gamma (typically 2.4).
§Algorithm
$$ f_\text{encode}(c) = \begin{cases} 12.92c, & \text{if } c <= 0.0031308 \cr 1.055c^{1/\gamma} - 0.055, & \text{if } c > 0.0031308 \end{cases} $$
Sourcepub const fn const_encode_srgb(self, v: f64) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub const fn const_encode_srgb(self, v: f64) -> f64 ⓘ
_float_f64
only.Compile-time encode_srgb
.
Sourcepub fn decode_srgb(self, v: f64) -> f64 ⓘ
Available on crate features std
or _float_f64
only.
pub fn decode_srgb(self, v: f64) -> f64 ⓘ
std
or _float_f64
only.Decodes the given v
alue using the sRGB inverse transfer function.
Applies the inverse piecewise curve based on this gamma (typically 2.4).
§Algorithm
$$ \notag f_\text{decode}(c) = \begin{cases} c / 12.92, & \normalsize\text{if } c <= 0.04045 \cr \left(\Large\frac{c + 0.055}{1.055}\right)^\gamma & \normalsize \text{if } c > 0.04045 \end{cases} $$
Sourcepub const fn const_decode_srgb(self, v: f64) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub const fn const_decode_srgb(self, v: f64) -> f64 ⓘ
_float_f64
only.Compile-time decode_srgb
.
Source§impl Gamma<f64>
Weighted RGB → luma conversion utilities using standard coefficients.
impl Gamma<f64>
Weighted RGB → luma conversion utilities using standard coefficients.
Sourcepub const SRGB: [f64; 3] = Self::REC_709
pub const SRGB: [f64; 3] = Self::REC_709
R′G′B′ coefficients for computing sRGB luma (same as Rec. 709).
Sourcepub const SRGB_GAMMA: f64 = 2.2000000000000002f64
pub const SRGB_GAMMA: f64 = 2.2000000000000002f64
Typical gamma value for sRGB/Rec.709 (≈2.2)
Sourcepub const SRGB_LINEAR_THRESHOLD: f64 = 0.0031308f64
pub const SRGB_LINEAR_THRESHOLD: f64 = 0.0031308f64
Threshold for sRGB linear segment (0.0031308)
Sourcepub const REC_1886_GAMMA: f64 = 2.3999999999999999f64
pub const REC_1886_GAMMA: f64 = 2.3999999999999999f64
Typical gamma value for Rec.1886 (≈2.4)
Sourcepub const CIE_E: f64 = 0.0088564516790356311f64
pub const CIE_E: f64 = 0.0088564516790356311f64
CIE lightness transition point (216/24389 ≈ 0.008856)
Sourcepub const CIE_K: f64 = 903.2962962962963f64
pub const CIE_K: f64 = 903.2962962962963f64
CIE lightness linear coefficient (24389/27 ≈ 903.3)
Sourcepub const fn compute_luma(rgb: [f64; 3], weights: [f64; 3]) -> f64 ⓘ
pub const fn compute_luma(rgb: [f64; 3], weights: [f64; 3]) -> f64 ⓘ
Computes luma from R′G′B′ using the given [kr, kg, kb]
weights.
Sourcepub const fn luma_srgb(rgb: [f64; 3]) -> f64 ⓘ
pub const fn luma_srgb(rgb: [f64; 3]) -> f64 ⓘ
Computes luma from R′G′B′ using Rec. 709 coefficients.
Sourcepub const fn luma_rec_709(rgb: [f64; 3]) -> f64 ⓘ
pub const fn luma_rec_709(rgb: [f64; 3]) -> f64 ⓘ
Computes luma from R′G′B′ using Rec. 709 coefficients.
Sourcepub const fn luma_rec_601(rgb: [f64; 3]) -> f64 ⓘ
pub const fn luma_rec_601(rgb: [f64; 3]) -> f64 ⓘ
Computes luma from R′G′B′ using Rec. 601 coefficients.
Sourcepub const fn luma_rec_2020(rgb: [f64; 3]) -> f64 ⓘ
pub const fn luma_rec_2020(rgb: [f64; 3]) -> f64 ⓘ
Computes luma from R′G′B′ using Rec. 2020 coefficients.
Sourcepub fn luminance_to_lightness(y: f64) -> f64 ⓘ
Available on crate features std
or _float_f64
only.
pub fn luminance_to_lightness(y: f64) -> f64 ⓘ
std
or _float_f64
only.Converts linear luminance to CIE lightness (L*)
Sourcepub const fn const_luminance_to_lightness(y: f64) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub const fn const_luminance_to_lightness(y: f64) -> f64 ⓘ
_float_f64
only.Compile-time luminance_to_lightness
.
Sourcepub fn lightness_to_luminance(l_star: f64) -> f64 ⓘ
Available on crate features std
or _float_f64
only.
pub fn lightness_to_luminance(l_star: f64) -> f64 ⓘ
std
or _float_f64
only.Converts CIE lightness (L*) to linear luminance
Sourcepub const fn const_lightness_to_luminance(l_star: f64) -> f64 ⓘ
Available on crate feature _float_f64
only.
pub const fn const_lightness_to_luminance(l_star: f64) -> f64 ⓘ
_float_f64
only.Compile-time lightness_to_luminance
.
Trait Implementations§
Source§impl<T: PartialOrd> PartialOrd for Gamma<T>
impl<T: PartialOrd> PartialOrd for Gamma<T>
impl<T: Copy> Copy for Gamma<T>
impl<T> StructuralPartialEq for Gamma<T>
Auto Trait Implementations§
impl<T> Freeze for Gamma<T>where
T: Freeze,
impl<T> RefUnwindSafe for Gamma<T>where
T: RefUnwindSafe,
impl<T> Send for Gamma<T>where
T: Send,
impl<T> Sync for Gamma<T>where
T: Sync,
impl<T> Unpin for Gamma<T>where
T: Unpin,
impl<T> UnwindSafe for Gamma<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more