diff --git a/src/qoi.rs b/src/qoi.rs index b84fc77..bdff872 100644 --- a/src/qoi.rs +++ b/src/qoi.rs @@ -15,7 +15,6 @@ use crate::{ // https://qoiformat.org/qoi-specification.pdf const image: &[u8; 1253] = include_bytes!("../images/hi.qoi"); -const BUFFER_SIZE: usize = 64; #[derive(Debug, uDebug)] pub enum QoiErr { @@ -100,9 +99,7 @@ struct QoiIterator<'a> { inner: Iter<'a, u8>, serial: &'a mut Usart, Pin, CoreClock>, prev_pixels: [Rgb565; 64], - prev_alphas: [u8; 64], last_pixel: Rgb565, - last_alpha: u8, repeat: u8, expected_colors: u16, parsed_colors: u16, @@ -118,9 +115,7 @@ impl<'a> QoiIterator<'a> { inner: bytes, serial, prev_pixels: [Rgb565(0, 255, 0); 64], - prev_alphas: [255; 64], last_pixel: Rgb565(0, 0, 0), - last_alpha: 255, repeat: 0, expected_colors: expected, parsed_colors: 0, @@ -143,19 +138,19 @@ impl<'a> Iterator for QoiIterator<'a> { return Some(self.last_pixel); } if let Some(byte) = self.inner.next() { - let (color, alpha) = if *byte == 0xff { + let color = if *byte == 0xff { let red = self.inner.next().unwrap(); let green = self.inner.next().unwrap(); let blue = self.inner.next().unwrap(); - let alpha = self.inner.next().unwrap(); + let _alpha = self.inner.next().unwrap(); // ufmt::uwriteln!(self.serial, "RGBA: {} {} {} {}", red, green, blue, alpha).unwrap(); - (Rgb565(*red, *green, *blue), *alpha) + Rgb565(*red, *green, *blue) } else if *byte == 0b11111110 { let red = self.inner.next().unwrap(); let green = self.inner.next().unwrap(); let blue = self.inner.next().unwrap(); // ufmt::uwriteln!(self.serial, "RGB: {} {} {}", red, green, blue).unwrap(); - (Rgb565(*red, *green, *blue), self.last_alpha) + Rgb565(*red, *green, *blue) } else { let tag = (0b11000000 & byte) >> 6; let data = 0b00111111 & byte; @@ -163,10 +158,7 @@ impl<'a> Iterator for QoiIterator<'a> { // ufmt::uwriteln!(self.serial, "Tag: {}", tag).unwrap(); if tag == 0 { - ( - self.prev_pixels[data as usize], - self.prev_alphas[data as usize], - ) + self.prev_pixels[data as usize] } else if tag == 1 { let dr = ((0b110000 & data) >> 4) as i8 - 2; let dg = ((0b001100 & data) >> 2) as i8 - 2; @@ -179,13 +171,10 @@ impl<'a> Iterator for QoiIterator<'a> { // (0b000011 & data) // ) // .unwrap(); - ( - Rgb565( - (self.last_pixel.0 as i8).wrapping_add(dr) as u8, - (self.last_pixel.1 as i8).wrapping_add(dg) as u8, - (self.last_pixel.2 as i8).wrapping_add(db) as u8, - ), - self.last_alpha, + Rgb565( + (self.last_pixel.0 as i8).wrapping_add(dr) as u8, + (self.last_pixel.1 as i8).wrapping_add(dg) as u8, + (self.last_pixel.2 as i8).wrapping_add(db) as u8, ) } else if tag == 2 { let second = self.inner.next().unwrap(); @@ -209,27 +198,23 @@ impl<'a> Iterator for QoiIterator<'a> { // self.last_pixel.2 as i8 + db // ) // .unwrap(); - ( - Rgb565( - (self.last_pixel.0 as i8 + dr) as u8, - (self.last_pixel.1 as i8 + dg) as u8, - (self.last_pixel.2 as i8 + db) as u8, - ), - self.last_alpha, + Rgb565( + (self.last_pixel.0 as i8 + dr) as u8, + (self.last_pixel.1 as i8 + dg) as u8, + (self.last_pixel.2 as i8 + db) as u8, ) } else if tag == 3 { // QOI_OP_RUN self.repeat = data; // ufmt::uwriteln!(self.serial, "Repeat: {}", self.repeat).unwrap(); - (self.last_pixel, self.last_alpha) + self.last_pixel } else { - (Rgb565::green(), 255) + Rgb565::green() } }; self.last_pixel = color; - self.last_alpha = alpha; let hash = - ((color.0 as u32 * 3 + color.1 as u32 * 5 + color.2 as u32 * 7 + alpha as u32 * 11) + ((color.0 as u32 * 3 + color.1 as u32 * 5 + color.2 as u32 * 7 + 255 as u32 * 11) % 64) as usize; // ufmt::uwriteln!(