Minor optimizations
This commit is contained in:
parent
b95c562651
commit
8116d69c3c
2 changed files with 7 additions and 9 deletions
|
|
@ -19,6 +19,7 @@ impl fmt::Display for PngError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PngError {
|
impl PngError {
|
||||||
|
#[inline]
|
||||||
pub fn new(description: &str) -> PngError {
|
pub fn new(description: &str) -> PngError {
|
||||||
PngError { description: description.to_owned() }
|
PngError { description: description.to_owned() }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,18 @@ pub fn filter_line(filter: u8, bpp: usize, data: &[u8], last_line: &[u8]) -> Vec
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
filtered.extend_from_slice(&data[0..bpp]);
|
filtered.extend_from_slice(&data[0..bpp]);
|
||||||
filtered.extend_from_slice(&data.iter()
|
filtered.extend(data.iter()
|
||||||
.skip(bpp)
|
.skip(bpp)
|
||||||
.zip(data.iter())
|
.zip(data.iter())
|
||||||
.map(|(cur, last)| cur.wrapping_sub(*last))
|
.map(|(cur, last)| cur.wrapping_sub(*last)));
|
||||||
.collect::<Vec<u8>>());
|
|
||||||
}
|
}
|
||||||
2 => {
|
2 => {
|
||||||
if last_line.is_empty() {
|
if last_line.is_empty() {
|
||||||
filtered.extend_from_slice(data);
|
filtered.extend_from_slice(data);
|
||||||
} else {
|
} else {
|
||||||
filtered.extend_from_slice(&data.iter()
|
filtered.extend(data.iter()
|
||||||
.zip(last_line.iter())
|
.zip(last_line.iter())
|
||||||
.map(|(cur, last)| cur.wrapping_sub(*last))
|
.map(|(cur, last)| cur.wrapping_sub(*last)));
|
||||||
.collect::<Vec<u8>>());
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
3 => {
|
3 => {
|
||||||
|
|
@ -84,10 +82,9 @@ pub fn unfilter_line(filter: u8, bpp: usize, data: &[u8], last_line: &[u8]) -> V
|
||||||
if last_line.is_empty() {
|
if last_line.is_empty() {
|
||||||
unfiltered.extend_from_slice(data);
|
unfiltered.extend_from_slice(data);
|
||||||
} else {
|
} else {
|
||||||
unfiltered.extend_from_slice(&data.iter()
|
unfiltered.extend(data.iter()
|
||||||
.zip(last_line.iter())
|
.zip(last_line.iter())
|
||||||
.map(|(cur, last)| cur.wrapping_add(*last))
|
.map(|(cur, last)| cur.wrapping_add(*last)));
|
||||||
.collect::<Vec<u8>>());
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
3 => {
|
3 => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue