Skip to main content

Sample

Trait Sample 

Source
pub trait Sample:
    Sealed
    + Copy
    + Send
    + Sync
    + 'static {
    const KIND: SampleKind;
    const FULL_SCALE: Self;
    const ZERO: Self;
}
Expand description

A channel sample type that kernels can be monomorphized over.

Implemented for exactly u8, u16 and f32 — the sample types of the v1 PixelFormat set. This trait is the type-level half of ADR-0002: ops match on a runtime PixelFormat once per tile, then call a generic kernel that the compiler specializes.

This trait is sealed: implementing it for other types would let a kernel reinterpret tile bytes as a type no codec produces.

Required Associated Constants§

Source

const KIND: SampleKind

The SampleKind this type corresponds to.

Source

const FULL_SCALE: Self

The value representing full intensity: opaque alpha, white luminance.

This is not the type’s maximum representable value. For f32 the nominal range is 0.0..=1.0, so FULL_SCALE is 1.0 while f32::MAX is about 3.4e38.

It is named FULL_SCALE rather than MAX precisely because of that gap: u8, u16 and f32 all have an inherent MAX constant, and inherent constants win name resolution over trait ones. A kernel generic over S: Sample writing S::MAX would therefore compile, resolve to the inherent constant, and be silently wrong for floats.

Source

const ZERO: Self

The value representing zero intensity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Sample for f32

Source§

const KIND: SampleKind = SampleKind::F32

Source§

const FULL_SCALE: Self = 1.0

Source§

const ZERO: Self = 0.0

Source§

impl Sample for u8

Source§

const KIND: SampleKind = SampleKind::U8

Source§

const FULL_SCALE: Self = u8::MAX

Source§

const ZERO: Self = 0

Source§

impl Sample for u16

Source§

const KIND: SampleKind = SampleKind::U16

Source§

const FULL_SCALE: Self = u16::MAX

Source§

const ZERO: Self = 0

Implementors§