diff --git a/src/color.rs b/src/color.rs index c8edc2e..6c915fd 100644 --- a/src/color.rs +++ b/src/color.rs @@ -11,6 +11,8 @@ extern crate embedded_graphics; #[cfg(feature = "graphics")] use self::embedded_graphics::pixelcolor::raw::RawU8; #[cfg(feature = "graphics")] +use self::embedded_graphics::pixelcolor::{BinaryColor, Rgb888, RgbColor}; +#[cfg(feature = "graphics")] use self::embedded_graphics::prelude::*; #[cfg(feature = "graphics")] impl PixelColor for Color { @@ -28,6 +30,41 @@ impl From for Color { } } +#[cfg(feature = "graphics")] +impl From for Color { + fn from(value: BinaryColor) -> Self { + match value { + BinaryColor::On => Color::Black, + BinaryColor::Off => Color::White, + } + } +} + +#[cfg(feature = "graphics")] +impl From for Color { + fn from(value: Rgb888) -> Self { + // NOTE(feliix42): This is admittedly a very simplistic approximation, it'd be more + // accurate to map the colors accordingly, but since that's an injective mapping anyways, + // why not keep it simple for now. + match value { + Rgb888::WHITE => Color::White, + Rgb888::BLACK => Color::Black, + _ => Color::Red, + } + } +} + +#[cfg(feature = "graphics")] +impl Into for Color { + fn into(self) -> Rgb888 { + match self { + Color::White => Rgb888::WHITE, + Color::Black => Rgb888::BLACK, + Color::Red => Rgb888::RED, + } + } +} + #[cfg(test)] mod tests { use super::*;