Zip with last line
This commit is contained in:
parent
7ebdb8bb1a
commit
790a410a55
1 changed files with 11 additions and 11 deletions
|
|
@ -71,42 +71,42 @@ pub fn unfilter_line(filter: u8, bpp: usize, data: &[u8], last_line: &[u8], buf:
|
||||||
buf.extend_from_slice(data);
|
buf.extend_from_slice(data);
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
for (i, byte) in data.iter().enumerate() {
|
for (i, &cur) in data.iter().enumerate() {
|
||||||
buf.push(match i.checked_sub(bpp) {
|
buf.push(match i.checked_sub(bpp) {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
let b = buf[x];
|
let b = buf[x];
|
||||||
byte.wrapping_add(b)
|
cur.wrapping_add(b)
|
||||||
}
|
}
|
||||||
None => *byte,
|
None => cur,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
buf.extend(
|
buf.extend(
|
||||||
data.iter()
|
data.iter()
|
||||||
.zip(last_line.iter())
|
.zip(last_line)
|
||||||
.map(|(cur, last)| cur.wrapping_add(*last)),
|
.map(|(&cur, &last)| cur.wrapping_add(last)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
3 => {
|
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) {
|
buf.push(match i.checked_sub(bpp) {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
let b = buf[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 => {
|
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) {
|
buf.push(match i.checked_sub(bpp) {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
let b = buf[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),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue