Skip to content

Commit 3d43fb7

Browse files
committed
Make 1BPP image work with 16 bit display
1 parent 1db5b8a commit 3d43fb7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/rotation.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern crate stm32f1xx_hal as hal;
3333
use cortex_m_rt::ExceptionFrame;
3434
use cortex_m_rt::{entry, exception};
3535
use embedded_graphics::image::Image1BPP;
36+
use embedded_graphics::pixelcolor::PixelColorU16;
3637
use embedded_graphics::prelude::*;
3738
use hal::delay::Delay;
3839
use hal::prelude::*;
@@ -95,10 +96,14 @@ fn main() -> ! {
9596

9697
let (w, h) = disp.get_dimensions();
9798

98-
let im = Image1BPP::new(include_bytes!("./rust.raw"), 64, 64)
99-
.translate(Coord::new(w as i32 / 2 - 64 / 2, h as i32 / 2 - 64 / 2));
99+
let im = Image1BPP::new(include_bytes!("./rust.raw"), 64, 64);
100+
// .translate(Coord::new(w as i32 / 2 - 64 / 2, h as i32 / 2 - 64 / 2));
100101

101-
disp.draw(im.into_iter());
102+
// Map 0x00 or 0x01 to 0x0000 or 0xffff to draw a white Rust logo from a 1BPP image
103+
disp.draw(
104+
im.into_iter()
105+
.map(|p: Pixel<u8>| Pixel::<PixelColorU16>(p.0, (p.1 as u16 * 0xffff).into())),
106+
);
102107

103108
disp.flush().unwrap();
104109

0 commit comments

Comments
 (0)