diff --git a/src/lib8/mod.rs b/src/lib8/mod.rs index b95db0b..36b0c71 100644 --- a/src/lib8/mod.rs +++ b/src/lib8/mod.rs @@ -4,31 +4,32 @@ pub mod trig; use palette::encoding::srgb::Srgb; -use rgb::RGB8; +use rgb::Rgb; pub trait Rgb8Blend { - fn saturating_add(self, b: Self) -> Self; + fn saturating_add>(self, b: T) -> Self where Self: Sized; } -impl Rgb8Blend for RGB8 { - fn saturating_add(self, b: Self) -> Self { - RGB8::new(self.r.saturating_add(b.r), self.g.saturating_add(b.g), self.b.saturating_add(b.b)) +impl Rgb8Blend for Rgb { + fn saturating_add>(self, b: T) -> Self where Self: Sized { + let rgb = b.into(); + Rgb::new(self.r.saturating_add(rgb.r), self.g.saturating_add(rgb.g), self.b.saturating_add(rgb.b)) } } pub trait IntoRgb8 { - fn into_rgb8(self) -> RGB8; + fn into_rgb8(self) -> Rgb; } -impl IntoRgb8 for RGB8 { - fn into_rgb8(self) -> RGB8 { +impl IntoRgb8 for Rgb { + fn into_rgb8(self) -> Rgb { self } } impl IntoRgb8 for palette::Hsv { //TODO: Borrowed from FastLED - fn into_rgb8(self) -> RGB8 { + fn into_rgb8(self) -> Rgb { const HSV_SECTION_3: u8 = 0x40; let value: u8 = self.value; @@ -50,9 +51,9 @@ impl IntoRgb8 for palette::Hsv { let rampdown_adj_with_floor: u8 = rampdown_amp_adj + brightness_floor; match section { - 1 => RGB8::new(brightness_floor, rampdown_adj_with_floor, rampup_adj_with_floor), - 0 => RGB8::new(rampdown_adj_with_floor, rampup_adj_with_floor, brightness_floor), - _ => RGB8::new(rampup_adj_with_floor, brightness_floor, rampdown_adj_with_floor) + 1 => Rgb::new(brightness_floor, rampdown_adj_with_floor, rampup_adj_with_floor), + 0 => Rgb::new(rampdown_adj_with_floor, rampup_adj_with_floor, brightness_floor), + _ => Rgb::new(rampup_adj_with_floor, brightness_floor, rampdown_adj_with_floor) } } }