mirror of
https://github.com/Feliix42/ssd1675.git
synced 2024-11-21 18:36:30 +00:00
Impl type conversions for simulator
This commit is contained in:
parent
83066b1013
commit
050e94933d
1 changed files with 37 additions and 0 deletions
37
src/color.rs
37
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<u8> for Color {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
impl From<BinaryColor> for Color {
|
||||
fn from(value: BinaryColor) -> Self {
|
||||
match value {
|
||||
BinaryColor::On => Color::Black,
|
||||
BinaryColor::Off => Color::White,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "graphics")]
|
||||
impl From<Rgb888> 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<Rgb888> 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::*;
|
||||
|
|
Loading…
Reference in a new issue