Skip to main content

Sample

Trait Sample 

Source
pub trait Sample:
    Sealed
    + Copy
    + Default
    + Ord
    + Debug
    + 'static {
    const MAX_VALUE: Self;

    // Required methods
    fn to_full_range_u16(self) -> u16;
    fn from_full_range_u16(value: u16) -> Self;
}
Expand description

A pixel-sample storage primitive: u8 (8-bit) or u16 (10/12/16-bit, high-bit-depth).

Sealed — only u8 and u16 implement it. The supertrait bounds are chosen so that P::Sample transitively gives buffer types everything they need (copy, zero-fill via Default, ordering) without callers repeating where P::Sample: … clauses. The storage width is available as size_of::<Self>(); a stream’s coded bit depth (e.g. 10 or 12) is a separate codec concern carried elsewhere (see gamut_color::BitDepth).

Sample::MAX_VALUE and the two full-range conversions are what lets crate::convert do depth-generic arithmetic: every sample width maps onto one canonical 16-bit working range, so the conversion engine is written once rather than once per width.

Required Associated Constants§

Source

const MAX_VALUE: Self

The all-ones value for this width: fully opaque alpha, or white.

Required Methods§

Source

fn to_full_range_u16(self) -> u16

Widens this sample onto the canonical full-range 16-bit working scale.

Exact and reversible: Sample::MAX_VALUE maps to u16::MAX and 0 maps to 0, with no value left unreachable. For u8 this is the × 0x101 rescale PNG specifies for sample-depth expansion (3rd edition, §13.12); for u16 it is the identity.

Source

fn from_full_range_u16(value: u16) -> Self

Narrows a canonical full-range 16-bit working value back to this width, rounding to nearest.

The inverse of Sample::to_full_range_u16 — lossless for values that round-trip, and half-up rounded otherwise. For u16 it is the identity.

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 u8

Source§

const MAX_VALUE: Self = u8::MAX

Source§

fn to_full_range_u16(self) -> u16

Source§

fn from_full_range_u16(value: u16) -> Self

Source§

impl Sample for u16

Source§

const MAX_VALUE: Self = u16::MAX

Source§

fn to_full_range_u16(self) -> u16

Source§

fn from_full_range_u16(value: u16) -> Self

Implementors§