Fixes for embedded-graphics 0.8

This commit is contained in:
Felix Suchert 2023-05-29 14:35:03 +02:00
parent 45b00687aa
commit 1d4ee1a2e9
Signed by: feliix42
GPG key ID: 24363525EA0E8A99

View file

@ -15,7 +15,7 @@ extern crate embedded_graphics;
#[cfg(feature = "graphics")] #[cfg(feature = "graphics")]
use self::embedded_graphics::pixelcolor::raw::RawU8; use self::embedded_graphics::pixelcolor::raw::RawU8;
#[cfg(feature = "graphics")] #[cfg(feature = "graphics")]
use self::embedded_graphics::pixelcolor::{BinaryColor, Rgb888, RgbColor}; use self::embedded_graphics::pixelcolor::{BinaryColor, Rgb555, Rgb565, Rgb888, RgbColor};
#[cfg(feature = "graphics")] #[cfg(feature = "graphics")]
use self::embedded_graphics::prelude::*; use self::embedded_graphics::prelude::*;
#[cfg(feature = "graphics")] #[cfg(feature = "graphics")]
@ -80,6 +80,56 @@ impl Into<Rgb888> for Color {
} }
} }
#[cfg(feature = "graphics")]
impl From<Rgb555> 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<Rgb555> 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<Rgb565> 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<Rgb565> for Color {
fn into(self) -> Rgb565 {
match self {
Color::White => Rgb565::WHITE,
Color::Black => Rgb565::BLACK,
Color::Red => Rgb565::RED,
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;