diff --git a/src/filters.rs b/src/filters.rs index 527f4fbd..517148fc 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -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), }); } }