diff --git a/src/color.rs b/src/color.rs index 7a06ecc..322ae77 100644 --- a/src/color.rs +++ b/src/color.rs @@ -15,7 +15,7 @@ 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}; +use self::embedded_graphics::pixelcolor::{BinaryColor, Rgb555, Rgb565, Rgb888, RgbColor}; #[cfg(feature = "graphics")] use self::embedded_graphics::prelude::*; #[cfg(feature = "graphics")] @@ -80,6 +80,56 @@ impl Into for Color { } } +#[cfg(feature = "graphics")] +impl From for Color { + fn from(value: Rgb555) -> 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 { + Rgb555::WHITE => Color::White, + Rgb555::BLACK => Color::Black, + _ => Color::Red, + } + } +} + +#[cfg(feature = "graphics")] +impl Into for Color { + fn into(self) -> Rgb555 { + match self { + Color::White => Rgb555::WHITE, + Color::Black => Rgb555::BLACK, + Color::Red => Rgb555::RED, + } + } +} + +#[cfg(feature = "graphics")] +impl From for Color { + fn from(value: Rgb565) -> 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 { + Rgb565::WHITE => Color::White, + Rgb565::BLACK => Color::Black, + _ => Color::Red, + } + } +} + +#[cfg(feature = "graphics")] +impl Into for Color { + fn into(self) -> Rgb565 { + match self { + Color::White => Rgb565::WHITE, + Color::Black => Rgb565::BLACK, + Color::Red => Rgb565::RED, + } + } +} + #[cfg(test)] mod tests { use super::*;