Similarly optimize unfilter mode 2
Unfilter mode 1 can't benefit from this optimization because it modifies and reads from the same line of data
This commit is contained in:
parent
3652a69255
commit
aaf443fca7
1 changed files with 8 additions and 7 deletions
15
src/png.rs
15
src/png.rs
|
|
@ -1149,13 +1149,14 @@ fn unfilter_line(filter: u8, bpp: usize, data: &[u8], last_line: &[u8]) -> Vec<u
|
|||
}
|
||||
}
|
||||
2 => {
|
||||
for (i, byte) in data.iter().enumerate() {
|
||||
if last_line.is_empty() {
|
||||
unfiltered.push(*byte);
|
||||
} else {
|
||||
unfiltered.push(byte.wrapping_add(last_line[i]));
|
||||
};
|
||||
}
|
||||
if last_line.is_empty() {
|
||||
unfiltered.extend_from_slice(data);
|
||||
} else {
|
||||
unfiltered.extend_from_slice(&data.iter()
|
||||
.zip(last_line.iter())
|
||||
.map(|(cur, last)| cur.wrapping_add(*last))
|
||||
.collect::<Vec<u8>>());
|
||||
};
|
||||
}
|
||||
3 => {
|
||||
for (i, byte) in data.iter().enumerate() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue