Index bugfix: force decoder index to be 4-channel

This commit is contained in:
Ivan Smirnov 2022-01-05 22:52:19 +03:00
parent fcbec6cf76
commit 5a899bbf25
2 changed files with 15 additions and 4 deletions

View file

@ -31,14 +31,16 @@ where
let data_len = data.len();
let mut data = data;
let mut index = [Pixel::<N>::new(); 256];
let mut index = [Pixel::<4>::new(); 256];
let mut px = Pixel::<N>::new().with_a(0xff);
let mut px_rgba: Pixel<4>;
while let [px_out, ptail @ ..] = pixels {
pixels = ptail;
match data {
[b1 @ QOI_OP_INDEX..=QOI_OP_INDEX_END, dtail @ ..] => {
px = index[*b1 as usize];
px_rgba = index[*b1 as usize];
px.update(px_rgba);
*px_out = px.into();
data = dtail;
continue;
@ -76,8 +78,8 @@ where
}
}
let px_rgba = px.as_rgba(0xff);
index[px_rgba.hash_index() as usize] = px;
px_rgba = px.as_rgba(0xff);
index[px_rgba.hash_index() as usize] = px_rgba;
*px_out = px.into();
}

View file

@ -26,6 +26,15 @@ impl<const N: usize> Pixel<N> {
}
}
#[inline]
pub fn update<const M: usize>(&mut self, px: Pixel<M>) {
let mut i = 0;
while i < M && i < N {
self.0[i] = px.0[i];
i += 1;
}
}
#[inline]
pub fn update_rgb(&mut self, r: u8, g: u8, b: u8) {
self.0[0] = r;