1 use num_traits::PrimInt; 2 3 pub trait Bounded { 4 const MIN: Self; 5 const MAX: Self; 6 } 7 8 impl Bounded for u8 { 9 const MIN: u8 = 0; 10 const MAX: u8 = 255; 11 } 12 13 impl Bounded for u16 { 14 const MIN: u16 = 0; 15 const MAX: u16 = 65535; 16 } 17 18 pub trait Depth: 'static { 19 type Pixel: PrimInt + Bounded; 20 const MAX: Self::Pixel; 21 } 22 23 pub struct Depth8; 24 pub struct Depth10; 25 pub struct Depth12; 26 pub struct Depth16; 27 28 impl Depth for Depth8 { 29 type Pixel = u8; 30 const MAX: u8 = 255; 31 } 32 33 impl Depth for Depth10 { 34 type Pixel = u16; 35 const MAX: u16 = (1<<10) - 1; 36 } 37 38 impl Depth for Depth12 { 39 type Pixel = u16; 40 const MAX: u16 = (1<<12) - 1; 41 } 42 43 impl Depth for Depth16 { 44 type Pixel = u16; 45 const MAX: u16 = 65535; 46 } 47