spatialrust_vision/
pixel.rs1pub trait PixelComponent: Copy + Send + Sync + 'static {
3 fn to_f64(self) -> f64;
5 fn from_f64(value: f64) -> Self;
7}
8
9impl PixelComponent for u8 {
10 fn to_f64(self) -> f64 {
11 f64::from(self)
12 }
13
14 fn from_f64(value: f64) -> Self {
15 value.round().clamp(0.0, 255.0) as Self
16 }
17}
18
19impl PixelComponent for u16 {
20 fn to_f64(self) -> f64 {
21 f64::from(self)
22 }
23
24 fn from_f64(value: f64) -> Self {
25 value.round().clamp(0.0, f64::from(u16::MAX)) as Self
26 }
27}
28
29impl PixelComponent for f32 {
30 fn to_f64(self) -> f64 {
31 f64::from(self)
32 }
33
34 fn from_f64(value: f64) -> Self {
35 value as Self
36 }
37}
38
39impl PixelComponent for f64 {
40 fn to_f64(self) -> f64 {
41 self
42 }
43
44 fn from_f64(value: f64) -> Self {
45 value
46 }
47}