diff --git a/src/lib8/interpolate.rs b/src/lib8/interpolate.rs index f9a0f76..76594ea 100644 --- a/src/lib8/interpolate.rs +++ b/src/lib8/interpolate.rs @@ -1,8 +1,19 @@ use num::PrimInt; -pub fn scale8(i: u8, scale: u8) -> u8 { - // borrowed from FastLED - (i as u16 * scale as u16).wrapping_shr(8) as u8 +type Fract8 = u8; +pub trait Fract8Ops { + fn scale8(self, scale: Fract8) -> Self; +} + +impl Fract8Ops for u8 { + fn scale8(self, scale: Fract8) -> Self { + // borrowed from FastLED + (self as u16 * (1 + scale as u16)).unsigned_shr(8) as u8 + } +} + +pub fn scale8(i: T, scale: Fract8) -> T { + i.scale8(scale) } pub fn avg7(i: i8, j: i8) -> i8 {