Skip to main content

ImagePixel

Trait ImagePixel 

Source
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

Typefrom_u8from_u16Notes
u8identity>> 8
u16* 257identity0..255 → 0..65535
i8XOR 0x80(>> 8) XOR 0x80unsigned-to-signed via sign-bit flip
i16* 257 XOR 0x8000XOR 0x8000unsigned-to-signed via sign-bit flip
f32/ 255.0/ 65535.0normalised to [0.0, 1.0]

Required Methods§

Source

fn from_u8(v: u8) -> Self

Convert a [0, 255] byte value to this pixel type.

Source

fn dtype() -> DType

The DType that corresponds to this Rust type.

Provided Methods§

Source

fn from_u16(v: u16) -> Self

Convert a [0, 65535] 16-bit value to this pixel type.

Used for 16-bit PNG images. The default implementation converts via from_u8(v >> 8) which discards the low byte.

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.

Implementations on Foreign Types§

Source§

impl ImagePixel for f32

Source§

fn from_u8(v: u8) -> Self

Source§

fn from_u16(v: u16) -> Self

Source§

fn dtype() -> DType

Source§

impl ImagePixel for i8

Source§

fn from_u8(v: u8) -> Self

Source§

fn from_u16(v: u16) -> Self

Source§

fn dtype() -> DType

Source§

impl ImagePixel for i16

Source§

fn from_u8(v: u8) -> Self

Source§

fn from_u16(v: u16) -> Self

Source§

fn dtype() -> DType

Source§

impl ImagePixel for u8

Source§

fn from_u8(v: u8) -> Self

Source§

fn from_u16(v: u16) -> Self

Source§

fn dtype() -> DType

Source§

impl ImagePixel for u16

Source§

fn from_u8(v: u8) -> Self

Source§

fn from_u16(v: u16) -> Self

Source§

fn dtype() -> DType

Implementors§