Skip to main content

HomogeneousPixel

Derive Macro HomogeneousPixel 

Source
#[derive(HomogeneousPixel)]
Expand description

Derive macro for HomogeneousPixel trait.

§Requirements

  • Struct must be #[repr(C)] or #[repr(transparent)]
  • For #[repr(C)]: all fields must have the same type (the channel type)
  • For #[repr(transparent)]: exactly one field, treated as a single-channel pixel
  • The struct must also implement PlainPixel (typically via #[derive(PlainPixel)])

§Example

#[derive(Clone, Copy, PlainPixel, HomogeneousPixel)]
#[repr(C)]
pub struct Rgb8 {
    pub r: Saturating<u8>,
    pub g: Saturating<u8>,
    pub b: Saturating<u8>,
}

§Generated Implementation

unsafe impl HomogeneousPixel for Rgb8 {
    type Channel = Saturating<u8>;
    type Channels = [Saturating<u8>; 3];
}