Index bugfix: force decoder index to be 4-channel
This commit is contained in:
parent
fcbec6cf76
commit
5a899bbf25
2 changed files with 15 additions and 4 deletions
|
@ -31,14 +31,16 @@ where
|
||||||
let data_len = data.len();
|
let data_len = data.len();
|
||||||
let mut data = data;
|
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 = Pixel::<N>::new().with_a(0xff);
|
||||||
|
let mut px_rgba: Pixel<4>;
|
||||||
|
|
||||||
while let [px_out, ptail @ ..] = pixels {
|
while let [px_out, ptail @ ..] = pixels {
|
||||||
pixels = ptail;
|
pixels = ptail;
|
||||||
match data {
|
match data {
|
||||||
[b1 @ QOI_OP_INDEX..=QOI_OP_INDEX_END, dtail @ ..] => {
|
[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();
|
*px_out = px.into();
|
||||||
data = dtail;
|
data = dtail;
|
||||||
continue;
|
continue;
|
||||||
|
@ -76,8 +78,8 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let px_rgba = px.as_rgba(0xff);
|
px_rgba = px.as_rgba(0xff);
|
||||||
index[px_rgba.hash_index() as usize] = px;
|
index[px_rgba.hash_index() as usize] = px_rgba;
|
||||||
*px_out = px.into();
|
*px_out = px.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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]
|
#[inline]
|
||||||
pub fn update_rgb(&mut self, r: u8, g: u8, b: u8) {
|
pub fn update_rgb(&mut self, r: u8, g: u8, b: u8) {
|
||||||
self.0[0] = r;
|
self.0[0] = r;
|
||||||
|
|
Loading…
Reference in a new issue