pub trait ImagePixel:
Num
+ Clone
+ Debug
+ Send
+ Sync
+ 'static {
// 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] |
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.