Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebP's into_frames iterator returns None upon encountering DecodingError::NoMoreFrames #2278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/codecs/webp/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ impl<'a, R: 'a + Read + Seek> AnimationDecoder<'a> for WebPDecoder<R> {
let mut img = RgbaImage::new(width, height);
match self.decoder.inner.read_frame(&mut img) {
Ok(delay) => (img, delay),
Err(image_webp::DecodingError::NoMoreFrames) => return None,
Err(e) => return Some(Err(ImageError::from_webp_decode(e))),
}
} else {
let mut img = RgbImage::new(width, height);
match self.decoder.inner.read_frame(&mut img) {
Ok(delay) => (img.convert(), delay),
Err(image_webp::DecodingError::NoMoreFrames) => return None,
Err(e) => return Some(Err(ImageError::from_webp_decode(e))),
}
};
Expand Down
16 changes: 13 additions & 3 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,26 @@ fn check_webp_frames_regressions() {
.join("*.webp");
let pattern = &*format!("{}", path.display());
for path in glob::glob(pattern).unwrap().filter_map(Result::ok) {
let bytes = fs::read(path).unwrap();
let bytes = fs::read(&path).unwrap();
let cursor = Cursor::new(&bytes);
let frame_count = image_webp::WebPDecoder::new(cursor.clone())
.unwrap()
.num_frames() as usize;
let decoder = WebPDecoder::new(cursor).unwrap();
// The `take` guards against a potentially infinitely running iterator.
// Since we take `frame_count + 1`, we can assume that the last iteration already returns `None`.
let actual_frame_count = decoder.into_frames().take(frame_count + 1).count();
assert_eq!(actual_frame_count, frame_count);
// We then check that each frame has been decoded successfully.
let decoded_frames_count = decoder
.into_frames()
.take(frame_count + 1)
.enumerate()
.inspect(|(frame_index, frame_res)| {
if let Err(e) = frame_res {
panic!("Error decoding {path:?} frame {}: {e:?}", frame_index + 1);
}
})
.count();
assert_eq!(frame_count, decoded_frames_count);
}
}

Expand Down
Loading