Trait PrimitiveColorChannel

Source
pub trait PrimitiveColorChannel: PrimitiveNum {
    const MAX_INTENSITY: Self;

    // Provided method
    fn color_cast_from<SrcT: PrimitiveColorChannel>(src: SrcT) -> Self { ... }
}
Expand description

Types that can be used as a color channel.

Implemented for u8, u16, u32, f32 and f64. For integer types, the whole range is used (0 to T::max_value()) while for floats, the values are always between 0 and 1.

Required Associated Constants§

Source

const MAX_INTENSITY: Self

The value representing maximum intensity.

T::max_value() for integer, 1.0 for floats. The minimum intensity is always 0.

Provided Methods§

Source

fn color_cast_from<SrcT: PrimitiveColorChannel>(src: SrcT) -> Self

Creates one channel type from another one, converting correctly between values.

This is not a simple as cast or even cast::lossy. For example, 255u8 becomes 1.0f32 or u16::max_value(). These casts are not lossless, but might round the value a bit (like casting rigor AllowRounding).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl PrimitiveColorChannel for f32

Source§

const MAX_INTENSITY: Self = 1f32

Source§

impl PrimitiveColorChannel for f64

Source§

const MAX_INTENSITY: Self = 1f64

Source§

impl PrimitiveColorChannel for u8

Source§

const MAX_INTENSITY: Self = 255u8

Source§

impl PrimitiveColorChannel for u16

Source§

const MAX_INTENSITY: Self = 65_535u16

Source§

impl PrimitiveColorChannel for u32

Source§

const MAX_INTENSITY: Self = 4_294_967_295u32

Implementors§