Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to interop with embedded_graphics::image::ImageRaw #23

Open
patcher-ms opened this issue Feb 12, 2025 · 0 comments
Open

Unable to interop with embedded_graphics::image::ImageRaw #23

patcher-ms opened this issue Feb 12, 2025 · 0 comments

Comments

@patcher-ms
Copy link

I'm trying to load an 1BPP image and display it using this crate. I am having trouble because of the way Color is defined.

I'm trying to do something along these lines, inspired by this ImageRaw example

let mut driver = WeActStudio420BlackWhiteDriver::new(spi_interface, busy, reset, delay);
let mut display = Display420BlackWhite::new();
display.set_rotation(DisplayRotation::Rotate0);
driver.init().await.unwrap();

// Render image obtained via API call, for the example let's use a placeholder
let server_sent_image = [0u8; 400 * 300 / 8].as_slice();
let raw_image = ImageRaw::<Color>::new(server_sent_image, 400);
let image = Image::new(&raw_image, Point::zero());
image.draw(&mut display);
driver.full_update(&display).await.unwrap();

This fails because:

error[E0277]: the trait bound `Color: From<()>` is not satisfied
   --> src/bin/async_main.rs:67:21
    |
    |     let raw_image = ImageRaw::<Color>::new(server_sent_image, 400);
    |                     ^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `Color`
    |
    = help: the following other types implement trait `From<T>`:
              `Color` implements `From<BinaryColor>`
              `Color` implements `From<Rgb555>`
              `Color` implements `From<Rgb565>`
              `Color` implements `From<Rgb888>`
note: required by a bound in `ImageRaw`
   --> /Users/mariosangiorgio/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embedded-graphics-0.8.1/src/image/image_raw.rs:116:21
    |
114 | pub struct ImageRaw<'a, C, BO = BigEndian>
    |            -------- required by a bound in this struct
115 | where
116 |     C: PixelColor + From<<C as PixelColor>::Raw>,
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ImageRaw`

This originates from:

impl PixelColor for Color {
    type Raw = ();
}

defined here. Is there any reason Raw is defined as () instead of RawU1?

I tried to use ImageRaw::<BinaryColor>::new(server_sent_image, 400); but that breaks when I call image.draw(&mut display) with a:

error[E0271]: type mismatch resolving `<Display<400, 300, 15000, Color> as DrawTarget>::Color == BinaryColor`

As a final attempt, I tried to redefine display to use a different color:

pub type Display420BlackWhite2 = Display<400, 300, 15_000, BinaryColor>;

but that leaves me with a type I cannot construct. Display::new() is defined only when the color is Color and I cannot construct it myself because I don't have access to the member of the structure.

Am I missing something or is this library not compatible with ImageRaw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant