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§
Required Methods§
Sourcefn to_full_range_u16(self) -> u16
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.
Sourcefn from_full_range_u16(value: u16) -> Self
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".