diff --git a/components/pixels/lib.rs b/components/pixels/lib.rs index 016927e909a..a8f9075e595 100644 --- a/components/pixels/lib.rs +++ b/components/pixels/lib.rs @@ -311,18 +311,21 @@ impl RasterImage { self.frames.len() > 1 } - pub fn frames(&self) -> impl Iterator> { - self.frames.iter().map(|frame| ImageFrameView { + fn frame_view<'image>(&'image self, frame: &ImageFrame) -> ImageFrameView<'image> { + ImageFrameView { delay: frame.delay, bytes: self.bytes.get(frame.byte_range.clone()).unwrap(), width: frame.width, height: frame.height, - }) + } + } + + pub fn frame(&self, index: usize) -> Option> { + self.frames.get(index).map(|frame| self.frame_view(frame)) } pub fn first_frame(&self) -> ImageFrameView<'_> { - self.frames() - .next() + self.frame(0) .expect("All images should have at least one frame") } } diff --git a/components/script/image_animation.rs b/components/script/image_animation.rs index eace2f6e3a4..cecf7997df9 100644 --- a/components/script/image_animation.rs +++ b/components/script/image_animation.rs @@ -72,8 +72,7 @@ impl ImageAnimationManager { let image = &state.image; let frame = image - .frames() - .nth(state.active_frame) + .frame(state.active_frame) .expect("active_frame should within range of frames"); if let Some(node) = rooted_nodes.get(&NoTrace(*node)) {