From 0ad742df485a142e2d33e3cb411508252fd91b73 Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 13 Sep 2025 14:05:08 +0300 Subject: [PATCH] Tweak api a little bit --- src/main.rs | 12 ++++-------- src/qoi.rs | 28 +++++++--------------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/main.rs b/src/main.rs index b094651..bc27706 100644 --- a/src/main.rs +++ b/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 }, ) { diff --git a/src/qoi.rs b/src/qoi.rs index 4ee4832..1f2dc53 100644 --- a/src/qoi.rs +++ b/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( serial: &mut Usart, Pin, CoreClock>, - image: &Image, + iter: &mut dyn Iterator, display: &mut Display, 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( 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( }, ); - 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],