Skip to content

Commit

Permalink
Use chunks_exact_mut in PNG decoder (#2110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel authored Jan 16, 2024
1 parent 778f185 commit a6886ea
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/codecs/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for PngDecoder<R> {

match bpc {
1 => (), // No reodering necessary for u8
2 => buf.chunks_mut(2).for_each(|c| {
2 => buf.chunks_exact_mut(2).for_each(|c| {
let v = BigEndian::read_u16(c);
NativeEndian::write_u16(c, v)
}),
Expand Down Expand Up @@ -676,8 +676,8 @@ impl<W: Write> ImageEncoder for PngEncoder<W> {
// yet take Write/Read traits, create a temporary buffer for
// big endian reordering.
let mut reordered = vec![0; buf.len()];
buf.chunks(2)
.zip(reordered.chunks_mut(2))
buf.chunks_exact(2)
.zip(reordered.chunks_exact_mut(2))
.for_each(|(b, r)| BigEndian::write_u16(r, NativeEndian::read_u16(b)));
self.encode_inner(&reordered, width, height, color_type)
}
Expand Down

0 comments on commit a6886ea

Please sign in to comment.