Skip to main content

Sample

Trait Sample 

Source
pub trait Sample:
    Copy
    + Clone
    + PartialOrd
    + Default
    + Send
    + Sync
    + 'static
    + Into<f32>
    + FromF32 {
    const MAX: Self;
    const MIN: Self;
    const BIT_DEPTH: u8;

    // Required methods
    fn clamp_sample(self) -> Self;
    fn from_normalized(v: f32) -> Self;
    fn to_normalized(self) -> f32;
}
Expand description

Trait for scalar sample values used in image processing.

Implemented for u8, u16, and f32 — the common pixel sample types in raw image processing pipelines.

Required Associated Constants§

Source

const MAX: Self

The maximum representable value for this sample type.

Source

const MIN: Self

The minimum representable value for this sample type.

Source

const BIT_DEPTH: u8

The number of bits used to represent this sample.

Required Methods§

Source

fn clamp_sample(self) -> Self

Clamp a value to the valid range.

Source

fn from_normalized(v: f32) -> Self

Convert from a normalized f32 value in [0.0, 1.0] to this sample type.

Source

fn to_normalized(self) -> f32

Convert this sample to a normalized f32 value in [0.0, 1.0].

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 MAX: Self = 1.0

Source§

const MIN: Self = 0.0

Source§

const BIT_DEPTH: u8 = 32

Source§

fn clamp_sample(self) -> Self

Source§

fn from_normalized(v: f32) -> Self

Source§

fn to_normalized(self) -> f32

Source§

impl Sample for u8

Source§

const MAX: Self = 255

Source§

const MIN: Self = 0

Source§

const BIT_DEPTH: u8 = 8

Source§

fn clamp_sample(self) -> Self

Source§

fn from_normalized(v: f32) -> Self

Source§

fn to_normalized(self) -> f32

Source§

impl Sample for u16

Source§

const MAX: Self = 65535

Source§

const MIN: Self = 0

Source§

const BIT_DEPTH: u8 = 16

Source§

fn clamp_sample(self) -> Self

Source§

fn from_normalized(v: f32) -> Self

Source§

fn to_normalized(self) -> f32

Implementors§