pub trait ImagePixel: Element {
// Required methods
fn from_u8(v: u8) -> Self;
fn dtype() -> DType;
// Provided method
fn from_u16(v: u16) -> Self { ... }
}Expand description
Marker trait for pixel element types supported by image decoding.
Provides conversions from decoded u8 and u16 pixel values into the
tensor’s native element type. The from_u16 path is used for 16-bit PNG
images; JPEG always decodes to u8.
§Supported types and conversions
| Type | from_u8 | from_u16 | Notes |
|---|---|---|---|
u8 | identity | >> 8 | |
u16 | * 257 | identity | 0..255 → 0..65535 |
i8 | XOR 0x80 | (>> 8) XOR 0x80 | unsigned-to-signed via sign-bit flip |
i16 | * 257 XOR 0x8000 | XOR 0x8000 | unsigned-to-signed via sign-bit flip |
f32 | / 255.0 | / 65535.0 | normalised to [0.0, 1.0] |
edgefirst_tensor::Element is a supertrait: under the dynamic tensor
backend, Tensor<T>’s own constructors need T::DTYPE at compile time
(there is no per-variant enum to allocate through instead), so any T
this crate builds a Tensor<T> over must already be one of the eleven
element types Element is sealed to. Every ImagePixel impl below is
one of those types, so this costs nothing real – it just makes the
existing constraint visible at the trait level instead of failing much
later at a Tensor<T> call site.
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".