Tweak api a little bit
This commit is contained in:
parent
6a999e3db8
commit
0ad742df48
12
src/main.rs
12
src/main.rs
@ -20,7 +20,7 @@ use panic_halt as _;
|
||||
use crate::{
|
||||
display::{Display, Position},
|
||||
peripherals::Button,
|
||||
qoi::{Image, LARGE_CAT_UNSAFE, PRESS_BTN_UNSAFE, RICK_UNSAFE, XP_DESKTOP_UNSAFE, draw_image},
|
||||
qoi::{Image, LARGE_CAT_UNSAFE, PRESS_BTN_UNSAFE, draw_image},
|
||||
};
|
||||
|
||||
mod display;
|
||||
@ -78,16 +78,12 @@ fn main() -> ! {
|
||||
let mut button = Button::from(pins.pd5.into_pull_up_input());
|
||||
|
||||
let mut idx = 0;
|
||||
let images = [
|
||||
Image::from(addr_of!(LARGE_CAT_UNSAFE)),
|
||||
Image::from(addr_of!(XP_DESKTOP_UNSAFE)),
|
||||
Image::from(addr_of!(RICK_UNSAFE)),
|
||||
];
|
||||
let images = [Image::from(addr_of!(LARGE_CAT_UNSAFE))];
|
||||
let len = images.len();
|
||||
|
||||
match draw_image(
|
||||
&mut serial,
|
||||
&Image::from(addr_of!(PRESS_BTN_UNSAFE)),
|
||||
&mut Image::from(addr_of!(PRESS_BTN_UNSAFE)).iter(),
|
||||
&mut display,
|
||||
Position { x: 0, y: 0 },
|
||||
) {
|
||||
@ -99,7 +95,7 @@ fn main() -> ! {
|
||||
if button.poll() {
|
||||
match draw_image(
|
||||
&mut serial,
|
||||
&images[idx],
|
||||
&mut images[idx].iter(),
|
||||
&mut display,
|
||||
Position { x: 0, y: 0 },
|
||||
) {
|
||||
|
28
src/qoi.rs
28
src/qoi.rs
@ -18,10 +18,6 @@ use crate::{
|
||||
#[unsafe(link_section = ".progmem.data")]
|
||||
pub static LARGE_CAT_UNSAFE: [u8; 8765] = *include_bytes!("../images/cat.qoi");
|
||||
#[unsafe(link_section = ".progmem.data")]
|
||||
pub static XP_DESKTOP_UNSAFE: [u8; 7360] = *include_bytes!("../images/xp_desktop.qoi");
|
||||
#[unsafe(link_section = ".progmem.data")]
|
||||
pub static RICK_UNSAFE: [u8; 2391] = *include_bytes!("../images/rick.qoi");
|
||||
#[unsafe(link_section = ".progmem.data")]
|
||||
pub static PRESS_BTN_UNSAFE: [u8; 1225] = *include_bytes!("../images/press_btn.qoi");
|
||||
|
||||
pub struct Image {
|
||||
@ -81,11 +77,10 @@ pub enum QoiErr {
|
||||
|
||||
pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
||||
serial: &mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
||||
image: &Image,
|
||||
iter: &mut dyn Iterator<Item = u8>,
|
||||
display: &mut Display<T, DCPin, RSTPin>,
|
||||
position: Position,
|
||||
) -> Result<(), QoiErr> {
|
||||
let mut iter = image.iter();
|
||||
if let (Some(113), Some(111), Some(105), Some(102)) =
|
||||
(iter.next(), iter.next(), iter.next(), iter.next())
|
||||
{
|
||||
@ -93,20 +88,11 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
||||
iter.next().ok_or(QoiErr::UnexpectedEOF)
|
||||
}
|
||||
|
||||
let width = u32::from_be_bytes([
|
||||
next(&mut iter)?,
|
||||
next(&mut iter)?,
|
||||
next(&mut iter)?,
|
||||
next(&mut iter)?,
|
||||
]) as u16;
|
||||
let height = u32::from_be_bytes([
|
||||
next(&mut iter)?,
|
||||
next(&mut iter)?,
|
||||
next(&mut iter)?,
|
||||
next(&mut iter)?,
|
||||
]) as u16;
|
||||
let _channels = next(&mut iter)?;
|
||||
let _colorspace = next(&mut iter)?;
|
||||
let width = u32::from_be_bytes([next(iter)?, next(iter)?, next(iter)?, next(iter)?]) as u16;
|
||||
let height =
|
||||
u32::from_be_bytes([next(iter)?, next(iter)?, next(iter)?, next(iter)?]) as u16;
|
||||
let _channels = next(iter)?;
|
||||
let _colorspace = next(iter)?;
|
||||
|
||||
ufmt::uwriteln!(serial, "Successfully read QOI header").unwrap();
|
||||
|
||||
@ -120,7 +106,7 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
||||
},
|
||||
);
|
||||
|
||||
let qoi_iter = QoiIterator::from(&mut iter, width * height);
|
||||
let qoi_iter = QoiIterator::from(iter, width * height);
|
||||
let scale_iter = ScaleIterator {
|
||||
qoi: qoi_iter,
|
||||
last_row: [Rgb565::yellow(); 120],
|
||||
|
Loading…
Reference in New Issue
Block a user