Remove alpha
This commit is contained in:
parent
b31d6255bf
commit
91d04ff3cc
47
src/qoi.rs
47
src/qoi.rs
@ -15,7 +15,6 @@ use crate::{
|
|||||||
|
|
||||||
// https://qoiformat.org/qoi-specification.pdf
|
// https://qoiformat.org/qoi-specification.pdf
|
||||||
const image: &[u8; 1253] = include_bytes!("../images/hi.qoi");
|
const image: &[u8; 1253] = include_bytes!("../images/hi.qoi");
|
||||||
const BUFFER_SIZE: usize = 64;
|
|
||||||
|
|
||||||
#[derive(Debug, uDebug)]
|
#[derive(Debug, uDebug)]
|
||||||
pub enum QoiErr {
|
pub enum QoiErr {
|
||||||
@ -100,9 +99,7 @@ struct QoiIterator<'a> {
|
|||||||
inner: Iter<'a, u8>,
|
inner: Iter<'a, u8>,
|
||||||
serial: &'a mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
serial: &'a mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
||||||
prev_pixels: [Rgb565; 64],
|
prev_pixels: [Rgb565; 64],
|
||||||
prev_alphas: [u8; 64],
|
|
||||||
last_pixel: Rgb565,
|
last_pixel: Rgb565,
|
||||||
last_alpha: u8,
|
|
||||||
repeat: u8,
|
repeat: u8,
|
||||||
expected_colors: u16,
|
expected_colors: u16,
|
||||||
parsed_colors: u16,
|
parsed_colors: u16,
|
||||||
@ -118,9 +115,7 @@ impl<'a> QoiIterator<'a> {
|
|||||||
inner: bytes,
|
inner: bytes,
|
||||||
serial,
|
serial,
|
||||||
prev_pixels: [Rgb565(0, 255, 0); 64],
|
prev_pixels: [Rgb565(0, 255, 0); 64],
|
||||||
prev_alphas: [255; 64],
|
|
||||||
last_pixel: Rgb565(0, 0, 0),
|
last_pixel: Rgb565(0, 0, 0),
|
||||||
last_alpha: 255,
|
|
||||||
repeat: 0,
|
repeat: 0,
|
||||||
expected_colors: expected,
|
expected_colors: expected,
|
||||||
parsed_colors: 0,
|
parsed_colors: 0,
|
||||||
@ -143,19 +138,19 @@ impl<'a> Iterator for QoiIterator<'a> {
|
|||||||
return Some(self.last_pixel);
|
return Some(self.last_pixel);
|
||||||
}
|
}
|
||||||
if let Some(byte) = self.inner.next() {
|
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 red = self.inner.next().unwrap();
|
||||||
let green = self.inner.next().unwrap();
|
let green = self.inner.next().unwrap();
|
||||||
let blue = 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();
|
// ufmt::uwriteln!(self.serial, "RGBA: {} {} {} {}", red, green, blue, alpha).unwrap();
|
||||||
(Rgb565(*red, *green, *blue), *alpha)
|
Rgb565(*red, *green, *blue)
|
||||||
} else if *byte == 0b11111110 {
|
} else if *byte == 0b11111110 {
|
||||||
let red = self.inner.next().unwrap();
|
let red = self.inner.next().unwrap();
|
||||||
let green = self.inner.next().unwrap();
|
let green = self.inner.next().unwrap();
|
||||||
let blue = self.inner.next().unwrap();
|
let blue = self.inner.next().unwrap();
|
||||||
// ufmt::uwriteln!(self.serial, "RGB: {} {} {}", red, green, blue).unwrap();
|
// ufmt::uwriteln!(self.serial, "RGB: {} {} {}", red, green, blue).unwrap();
|
||||||
(Rgb565(*red, *green, *blue), self.last_alpha)
|
Rgb565(*red, *green, *blue)
|
||||||
} else {
|
} else {
|
||||||
let tag = (0b11000000 & byte) >> 6;
|
let tag = (0b11000000 & byte) >> 6;
|
||||||
let data = 0b00111111 & byte;
|
let data = 0b00111111 & byte;
|
||||||
@ -163,10 +158,7 @@ impl<'a> Iterator for QoiIterator<'a> {
|
|||||||
// ufmt::uwriteln!(self.serial, "Tag: {}", tag).unwrap();
|
// ufmt::uwriteln!(self.serial, "Tag: {}", tag).unwrap();
|
||||||
|
|
||||||
if tag == 0 {
|
if tag == 0 {
|
||||||
(
|
self.prev_pixels[data as usize]
|
||||||
self.prev_pixels[data as usize],
|
|
||||||
self.prev_alphas[data as usize],
|
|
||||||
)
|
|
||||||
} else if tag == 1 {
|
} else if tag == 1 {
|
||||||
let dr = ((0b110000 & data) >> 4) as i8 - 2;
|
let dr = ((0b110000 & data) >> 4) as i8 - 2;
|
||||||
let dg = ((0b001100 & data) >> 2) as i8 - 2;
|
let dg = ((0b001100 & data) >> 2) as i8 - 2;
|
||||||
@ -179,13 +171,10 @@ impl<'a> Iterator for QoiIterator<'a> {
|
|||||||
// (0b000011 & data)
|
// (0b000011 & data)
|
||||||
// )
|
// )
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
(
|
Rgb565(
|
||||||
Rgb565(
|
(self.last_pixel.0 as i8).wrapping_add(dr) as u8,
|
||||||
(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.1 as i8).wrapping_add(dg) as u8,
|
(self.last_pixel.2 as i8).wrapping_add(db) as u8,
|
||||||
(self.last_pixel.2 as i8).wrapping_add(db) as u8,
|
|
||||||
),
|
|
||||||
self.last_alpha,
|
|
||||||
)
|
)
|
||||||
} else if tag == 2 {
|
} else if tag == 2 {
|
||||||
let second = self.inner.next().unwrap();
|
let second = self.inner.next().unwrap();
|
||||||
@ -209,27 +198,23 @@ impl<'a> Iterator for QoiIterator<'a> {
|
|||||||
// self.last_pixel.2 as i8 + db
|
// self.last_pixel.2 as i8 + db
|
||||||
// )
|
// )
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
(
|
Rgb565(
|
||||||
Rgb565(
|
(self.last_pixel.0 as i8 + dr) as u8,
|
||||||
(self.last_pixel.0 as i8 + dr) as u8,
|
(self.last_pixel.1 as i8 + dg) as u8,
|
||||||
(self.last_pixel.1 as i8 + dg) as u8,
|
(self.last_pixel.2 as i8 + db) as u8,
|
||||||
(self.last_pixel.2 as i8 + db) as u8,
|
|
||||||
),
|
|
||||||
self.last_alpha,
|
|
||||||
)
|
)
|
||||||
} else if tag == 3 {
|
} else if tag == 3 {
|
||||||
// QOI_OP_RUN
|
// QOI_OP_RUN
|
||||||
self.repeat = data;
|
self.repeat = data;
|
||||||
// ufmt::uwriteln!(self.serial, "Repeat: {}", self.repeat).unwrap();
|
// ufmt::uwriteln!(self.serial, "Repeat: {}", self.repeat).unwrap();
|
||||||
(self.last_pixel, self.last_alpha)
|
self.last_pixel
|
||||||
} else {
|
} else {
|
||||||
(Rgb565::green(), 255)
|
Rgb565::green()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.last_pixel = color;
|
self.last_pixel = color;
|
||||||
self.last_alpha = alpha;
|
|
||||||
let hash =
|
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;
|
% 64) as usize;
|
||||||
|
|
||||||
// ufmt::uwriteln!(
|
// ufmt::uwriteln!(
|
||||||
|
Loading…
Reference in New Issue
Block a user