Struct Gamma

Source
#[repr(C)]
pub struct Gamma<T> { pub exp: T, }
Available on crate feature 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<T> Gamma<T>

Source

pub const fn new(gamma: T) -> Self

Constructs a new gamma curve with the given exponent.

Source§

impl Gamma<f32>

Gamma encoding, decoding, and sRGB transfer functions for floating-point values.

Source

pub fn encode(self, v: f32) -> f32

Available on crate features std or _float_f32 only.

Encodes the given linear value using this gamma: $v^{(1/γ)}$.

Performs basic gamma encoding (power-law).

Source

pub fn decode(self, v: f32) -> f32

Available on crate features std or _float_f32 only.

Decodes the given gamma-encoded value using this gamma: $v^γ$ .

Performs basic gamma decoding (power-law inverse).

Source

pub fn encode_srgb(self, v: f32) -> f32

Available on crate features std or _float_f32 only.

Encodes the given value 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} $$

Source

pub fn decode_srgb(self, v: f32) -> f32

Available on crate features std or _float_f32 only.

Decodes the given value 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.

Source

pub const SRGB: [f32; 3] = Self::REC_709

R′G′B′ coefficients for computing sRGB luma (same as Rec. 709).

Source

pub const SRGB_GAMMA: f32 = 2.20000005f32

Typical gamma value for sRGB/Rec.709 (≈2.2)

Source

pub const SRGB_LINEAR_THRESHOLD: f32 = 0.00313080009f32

Threshold for sRGB linear segment (0.0031308)

Source

pub const REC_709: [f32; 3]

R′G′B′ coefficients for computing luma using Rec. 709.

Source

pub const REC_601: [f32; 3]

R′G′B′ coefficients for computing luma using Rec. 601.

Source

pub const REC_2020: [f32; 3]

R′G′B′ coefficients for computing luma using Rec. 2020.

Source

pub const REC_1886_GAMMA: f32 = 2.4000001f32

Typical gamma value for Rec.1886 (≈2.4)

Source

pub const CIE_E: f32 = 0.00885645207f32

CIE lightness transition point (216/24389 ≈ 0.008856)

Source

pub const CIE_K: f32 = 903.296325f32

CIE lightness linear coefficient (24389/27 ≈ 903.3)

Source

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.

Source

pub const fn luma_srgb(rgb: [f32; 3]) -> f32

Computes luma from R′G′B′ using Rec. 709 coefficients.

Source

pub const fn luma_rec_709(rgb: [f32; 3]) -> f32

Computes luma from R′G′B′ using Rec. 709 coefficients.

Source

pub const fn luma_rec_601(rgb: [f32; 3]) -> f32

Computes luma from R′G′B′ using Rec. 601 coefficients.

Source

pub const fn luma_rec_2020(rgb: [f32; 3]) -> f32

Computes luma from R′G′B′ using Rec. 2020 coefficients.

Source

pub fn luminance_to_lightness(y: f32) -> f32

Available on crate features std or _float_f32 only.

Converts linear luminance to CIE lightness (L*)

Source

pub fn lightness_to_luminance(l_star: f32) -> f32

Available on crate features 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.

Source

pub fn encode(self, v: f64) -> f64

Available on crate features std or _float_f64 only.

Encodes the given linear value using this gamma: $v^{(1/γ)}$.

Performs basic gamma encoding (power-law).

Source

pub const fn const_encode(self, v: f64) -> f64

Available on crate feature _float_f64 only.

Compile-time encode.

Source

pub fn decode(self, v: f64) -> f64

Available on crate features std or _float_f64 only.

Decodes the given gamma-encoded value using this gamma: $v^γ$ .

Performs basic gamma decoding (power-law inverse).

Source

pub const fn const_decode(self, v: f64) -> f64

Available on crate feature _float_f64 only.

Compile-time decode.

Source

pub fn encode_srgb(self, v: f64) -> f64

Available on crate features std or _float_f64 only.

Encodes the given value 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} $$

Source

pub const fn const_encode_srgb(self, v: f64) -> f64

Available on crate feature _float_f64 only.

Compile-time encode_srgb.

Source

pub fn decode_srgb(self, v: f64) -> f64

Available on crate features std or _float_f64 only.

Decodes the given value 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

pub const fn const_decode_srgb(self, v: f64) -> f64

Available on crate feature _float_f64 only.

Compile-time decode_srgb.

Source§

impl Gamma<f64>

Weighted RGB → luma conversion utilities using standard coefficients.

Source

pub const SRGB: [f64; 3] = Self::REC_709

R′G′B′ coefficients for computing sRGB luma (same as Rec. 709).

Source

pub const SRGB_GAMMA: f64 = 2.2000000000000002f64

Typical gamma value for sRGB/Rec.709 (≈2.2)

Source

pub const SRGB_LINEAR_THRESHOLD: f64 = 0.0031308f64

Threshold for sRGB linear segment (0.0031308)

Source

pub const REC_709: [f64; 3]

R′G′B′ coefficients for computing luma using Rec. 709.

Source

pub const REC_601: [f64; 3]

R′G′B′ coefficients for computing luma using Rec. 601.

Source

pub const REC_2020: [f64; 3]

R′G′B′ coefficients for computing luma using Rec. 2020.

Source

pub const REC_1886_GAMMA: f64 = 2.3999999999999999f64

Typical gamma value for Rec.1886 (≈2.4)

Source

pub const CIE_E: f64 = 0.0088564516790356311f64

CIE lightness transition point (216/24389 ≈ 0.008856)

Source

pub const CIE_K: f64 = 903.2962962962963f64

CIE lightness linear coefficient (24389/27 ≈ 903.3)

Source

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.

Source

pub const fn luma_srgb(rgb: [f64; 3]) -> f64

Computes luma from R′G′B′ using Rec. 709 coefficients.

Source

pub const fn luma_rec_709(rgb: [f64; 3]) -> f64

Computes luma from R′G′B′ using Rec. 709 coefficients.

Source

pub const fn luma_rec_601(rgb: [f64; 3]) -> f64

Computes luma from R′G′B′ using Rec. 601 coefficients.

Source

pub const fn luma_rec_2020(rgb: [f64; 3]) -> f64

Computes luma from R′G′B′ using Rec. 2020 coefficients.

Source

pub fn luminance_to_lightness(y: f64) -> f64

Available on crate features std or _float_f64 only.

Converts linear luminance to CIE lightness (L*)

Source

pub const fn const_luminance_to_lightness(y: f64) -> f64

Available on crate feature _float_f64 only.

Compile-time luminance_to_lightness.

Source

pub fn lightness_to_luminance(l_star: f64) -> f64

Available on crate features std or _float_f64 only.

Converts CIE lightness (L*) to linear luminance

Source

pub const fn const_lightness_to_luminance(l_star: f64) -> f64

Available on crate feature _float_f64 only.

Compile-time lightness_to_luminance.

Trait Implementations§

Source§

impl<T: Clone> Clone for Gamma<T>

Source§

fn clone(&self) -> Gamma<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Gamma<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for Gamma<T>

Source§

fn eq(&self, other: &Gamma<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Gamma<T>

Source§

fn partial_cmp(&self, other: &Gamma<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Copy> Copy for Gamma<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByteSized for T

Source§

const BYTE_ALIGN: usize = _

The alignment of this type in bytes.
Source§

const BYTE_SIZE: usize = _

The size of this type in bytes.
Source§

fn byte_align(&self) -> usize

Returns the alignment of this type in bytes.
Source§

fn byte_size(&self) -> usize

Returns the size of this type in bytes. Read more
Source§

fn ptr_size_ratio(&self) -> [usize; 2]

Returns the size ratio between Ptr::BYTES and BYTE_SIZE. Read more
Source§

impl<T, R> Chain<R> for T
where T: ?Sized,

Source§

fn chain<F>(self, f: F) -> R
where F: FnOnce(Self) -> R, Self: Sized,

Chain a function which takes the parameter by value.
Source§

fn chain_ref<F>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Chain a function which takes the parameter by shared reference.
Source§

fn chain_mut<F>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Chain a function which takes the parameter by exclusive reference.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ExtAny for T
where T: Any + ?Sized,

Source§

fn type_id() -> TypeId

Returns the TypeId of Self. Read more
Source§

fn type_of(&self) -> TypeId

Returns the TypeId of self. Read more
Source§

fn type_name(&self) -> &'static str

Returns the type name of self. Read more
Source§

fn type_is<T: 'static>(&self) -> bool

Returns true if Self is of type T. Read more
Source§

fn type_hash(&self) -> u64

Returns a deterministic hash of the TypeId of Self.
Source§

fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64

Returns a deterministic hash of the TypeId of Self using a custom hasher.
Source§

fn as_any_ref(&self) -> &dyn Any
where Self: Sized,

Upcasts &self as &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any
where Self: Sized,

Upcasts &mut self as &mut dyn Any. Read more
Source§

fn as_any_box(self: Box<Self>) -> Box<dyn Any>
where Self: Sized,

Upcasts Box<self> as Box<dyn Any>. Read more
Source§

fn downcast_ref<T: 'static>(&self) -> Option<&T>

Available on crate feature unsafe_layout only.
Returns some shared reference to the inner value if it is of type T. Read more
Source§

fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T>

Available on crate feature unsafe_layout only.
Returns some exclusive reference to the inner value if it is of type T. Read more
Source§

impl<T> ExtMem for T
where T: ?Sized,

Source§

const NEEDS_DROP: bool = _

Know whether dropping values of this type matters, in compile-time.
Source§

fn mem_align_of<T>() -> usize

Returns the minimum alignment of the type in bytes. Read more
Source§

fn mem_align_of_val(&self) -> usize

Returns the alignment of the pointed-to value in bytes. Read more
Source§

fn mem_size_of<T>() -> usize

Returns the size of a type in bytes. Read more
Source§

fn mem_size_of_val(&self) -> usize

Returns the size of the pointed-to value in bytes. Read more
Source§

fn mem_copy(&self) -> Self
where Self: Copy,

Bitwise-copies a value. Read more
Source§

fn mem_needs_drop(&self) -> bool

Returns true if dropping values of this type matters. Read more
Source§

fn mem_drop(self)
where Self: Sized,

Drops self by running its destructor. Read more
Source§

fn mem_forget(self)
where Self: Sized,

Forgets about self without running its destructor. Read more
Source§

fn mem_replace(&mut self, other: Self) -> Self
where Self: Sized,

Replaces self with other, returning the previous value of self. Read more
Source§

fn mem_take(&mut self) -> Self
where Self: Default,

Replaces self with its default value, returning the previous value of self. Read more
Source§

fn mem_swap(&mut self, other: &mut Self)
where Self: Sized,

Swaps the value of self and other without deinitializing either one. Read more
Source§

unsafe fn mem_zeroed<T>() -> T

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst

Available on crate feature unsafe_layout only.
Returns the value of type T represented by the all-zero byte-pattern. Read more
Source§

fn mem_as_bytes(&self) -> &[u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &[u8]. Read more
Source§

fn mem_as_bytes_mut(&mut self) -> &mut [u8]
where Self: Sync + Unpin,

Available on crate feature unsafe_slice only.
View a Sync + Unpin self as &mut [u8]. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

Source§

impl<T> Hook for T

Source§

fn hook_ref<F>(self, f: F) -> Self
where F: FnOnce(&Self),

Applies a function which takes the parameter by shared reference, and then returns the (possibly) modified owned value. Read more
Source§

fn hook_mut<F>(self, f: F) -> Self
where F: FnOnce(&mut Self),

Applies a function which takes the parameter by exclusive reference, and then returns the (possibly) modified owned value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Ungil for T
where T: Send,