From 74337e8fc5c828322f9325ce57c0923c19cba09e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 13 Nov 2026 21:27:44 +0000 Subject: [PATCH] fix(gif): report frame cap after merging --- crates/gif/src/frames.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/gif/src/frames.rs b/crates/gif/src/frames.rs index 243128809..12ae37dda 100644 --- a/crates/gif/src/frames.rs +++ b/crates/gif/src/frames.rs @@ -143,8 +143,10 @@ fn collect( ) -> Result { let frame_bytes = u64::from(width) * u64::from(height) * 4; let mut out: Vec = Vec::new(); + let mut decoded_frames = 0; let mut stop = Stop::End; for frame in frames { + decoded_frames += 1; let frame = match frame { Ok(f) => f, Err(e) if out.is_empty() => { @@ -180,7 +182,7 @@ fn collect( } out.push(AnimFrame { rgba, delay_ms }); } - if stop == Stop::End && out.len() == limits.max_frames { + if stop == Stop::End && decoded_frames == limits.max_frames { stop = match has_more { Some(true) => Stop::FrameLimit, Some(false) => Stop::End, @@ -311,6 +313,14 @@ mod tests { ); } + #[test] + fn merged_frames_still_report_the_decode_frame_limit() { + let bytes = gif(&[(10, 5), (10, 7), (200, 1)]); + let animation = read_frames(&bytes, &FrameLimits { max_frames: 2, merge_identical: true, ..FrameLimits::default() }).unwrap(); + assert_eq!(reds(&animation), [(10, 120)]); + assert_eq!(animation.stop, Stop::FrameLimit); + } + #[test] fn a_frame_beyond_the_limit_is_not_decoded_or_allocated() { let mut bytes = gif(&[(1, 1), (2, 1)]);