Zip with last line

This commit is contained in:
Kornel 2021-02-04 13:51:09 +00:00
parent 7ebdb8bb1a
commit 790a410a55

View file

@ -71,42 +71,42 @@ pub fn unfilter_line(filter: u8, bpp: usize, data: &[u8], last_line: &[u8], buf:
buf.extend_from_slice(data);
}
1 => {
for (i, byte) in data.iter().enumerate() {
for (i, &cur) in data.iter().enumerate() {
buf.push(match i.checked_sub(bpp) {
Some(x) => {
let b = buf[x];
byte.wrapping_add(b)
cur.wrapping_add(b)
}
None => *byte,
None => cur,
});
}
}
2 => {
buf.extend(
data.iter()
.zip(last_line.iter())
.map(|(cur, last)| cur.wrapping_add(*last)),
.zip(last_line)
.map(|(&cur, &last)| cur.wrapping_add(last)),
);
}
3 => {
for (i, byte) in data.iter().enumerate() {
for (i, (&cur, &last)) in data.iter().zip(last_line).enumerate() {
buf.push(match i.checked_sub(bpp) {
Some(x) => {
let b = buf[x];
byte.wrapping_add(((u16::from(b) + u16::from(last_line[i])) >> 1) as u8)
cur.wrapping_add(((u16::from(b) + u16::from(last)) >> 1) as u8)
}
None => byte.wrapping_add(last_line[i] >> 1),
None => cur.wrapping_add(last >> 1),
});
}
}
4 => {
for (i, byte) in data.iter().enumerate() {
for (i, (&cur, &last)) in data.iter().zip(last_line).enumerate() {
buf.push(match i.checked_sub(bpp) {
Some(x) => {
let b = buf[x];
byte.wrapping_add(paeth_predictor(b, last_line[i], last_line[x]))
cur.wrapping_add(paeth_predictor(b, last, last_line[x]))
}
None => byte.wrapping_add(last_line[i]),
None => cur.wrapping_add(last),
});
}
}