Apply clippy::option_if_let_else
This commit is contained in:
parent
06ce65c714
commit
14ff609b8e
2 changed files with 17 additions and 25 deletions
|
|
@ -127,22 +127,18 @@ impl RowFilter {
|
||||||
}
|
}
|
||||||
Self::Average => {
|
Self::Average => {
|
||||||
for (i, byte) in data.iter().enumerate() {
|
for (i, byte) in data.iter().enumerate() {
|
||||||
buf.push(match i.checked_sub(bpp) {
|
buf.push(byte.wrapping_sub(i.checked_sub(bpp).map_or_else(
|
||||||
Some(x) => byte.wrapping_sub(
|
|| prev_line[i] >> 1,
|
||||||
((u16::from(data[x]) + u16::from(prev_line[i])) >> 1) as u8,
|
|x| ((u16::from(data[x]) + u16::from(prev_line[i])) >> 1) as u8,
|
||||||
),
|
)));
|
||||||
None => byte.wrapping_sub(prev_line[i] >> 1),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Paeth => {
|
Self::Paeth => {
|
||||||
for (i, byte) in data.iter().enumerate() {
|
for (i, byte) in data.iter().enumerate() {
|
||||||
buf.push(match i.checked_sub(bpp) {
|
buf.push(byte.wrapping_sub(i.checked_sub(bpp).map_or_else(
|
||||||
Some(x) => {
|
|| prev_line[i],
|
||||||
byte.wrapping_sub(paeth_predictor(data[x], prev_line[i], prev_line[x]))
|
|x| paeth_predictor(data[x], prev_line[i], prev_line[x]),
|
||||||
}
|
)));
|
||||||
None => byte.wrapping_sub(prev_line[i]),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -241,10 +237,7 @@ impl RowFilter {
|
||||||
Self::Sub => {
|
Self::Sub => {
|
||||||
for (i, &cur) in data.iter().enumerate() {
|
for (i, &cur) in data.iter().enumerate() {
|
||||||
let prev_byte = i.checked_sub(bpp).and_then(|x| buf.get(x).copied());
|
let prev_byte = i.checked_sub(bpp).and_then(|x| buf.get(x).copied());
|
||||||
buf.push(match prev_byte {
|
buf.push(prev_byte.map_or(cur, |b| cur.wrapping_add(b)));
|
||||||
Some(b) => cur.wrapping_add(b),
|
|
||||||
None => cur,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Up => {
|
Self::Up => {
|
||||||
|
|
@ -257,10 +250,10 @@ impl RowFilter {
|
||||||
Self::Average => {
|
Self::Average => {
|
||||||
for (i, (&cur, &last)) in data.iter().zip(prev_line).enumerate() {
|
for (i, (&cur, &last)) in data.iter().zip(prev_line).enumerate() {
|
||||||
let prev_byte = i.checked_sub(bpp).and_then(|x| buf.get(x).copied());
|
let prev_byte = i.checked_sub(bpp).and_then(|x| buf.get(x).copied());
|
||||||
buf.push(match prev_byte {
|
buf.push(cur.wrapping_add(prev_byte.map_or_else(
|
||||||
Some(b) => cur.wrapping_add(((u16::from(b) + u16::from(last)) >> 1) as u8),
|
|| last >> 1,
|
||||||
None => cur.wrapping_add(last >> 1),
|
|b| ((u16::from(b) + u16::from(last)) >> 1) as u8,
|
||||||
});
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::Paeth => {
|
Self::Paeth => {
|
||||||
|
|
|
||||||
|
|
@ -310,11 +310,10 @@ impl PngImage {
|
||||||
match &self.ihdr.color_type {
|
match &self.ihdr.color_type {
|
||||||
ColorType::Indexed { palette } => {
|
ColorType::Indexed { palette } => {
|
||||||
let plte = 12 + palette.len() * 3;
|
let plte = 12 + palette.len() * 3;
|
||||||
if let Some(trns) = palette.iter().rposition(|p| p.a != 255) {
|
palette
|
||||||
plte + 12 + trns + 1
|
.iter()
|
||||||
} else {
|
.rposition(|p| p.a != 255)
|
||||||
plte
|
.map_or(plte, |trns| plte + 12 + trns + 1)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ColorType::Grayscale { transparent_shade } if transparent_shade.is_some() => 12 + 2,
|
ColorType::Grayscale { transparent_shade } if transparent_shade.is_some() => 12 + 2,
|
||||||
ColorType::RGB { transparent_color } if transparent_color.is_some() => 12 + 6,
|
ColorType::RGB { transparent_color } if transparent_color.is_some() => 12 + 6,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue