Repository navigation
GIF: avoid writing duplicate global header for transparent frame after disposal 2 - #10692
ekanshbannsal wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Reviewed the diff and GifImagePlugin._write_multiple_frames:
- Fix & test look solid: Falling back to
(0, 0, 1, 1)when_getbbox(background_im, im_frame)[1]isNonedirectly fixes #10691, andtest_dispose2_transparent_frame_no_duplicate_headercovers the singleGIF89aheader, frame count, and expected RGBA bboxes across all frames. - Interaction with #10617: Note that open PR #10617 also adds
if not bbox: bbox = (0, 0, 1, 1)right below theprevious_disposal == 2/3branches (to handle both disposal 2 and 3), though it does not have thisdisposal=2transparent-frame regression test — either way this test is great to keep. - Two small non-blocking thoughts:
- A quick check with two consecutive fully-transparent frames after
disposal=2(to verify frame deduplication + combined duration alongside the single header) might be nice coverage. - Longer term, the write loop currently uses
if not frame_data.bbox:as the sentinel for frame 0 instead of checkingi == 0viaenumerate(im_frames), which is how any non-firstNonebbox accidentally re-emits the global header.
- A quick check with two consecutive fully-transparent frames after
0c5e346 to
f703fda
Compare
|
Addressed both non-blocking suggestions from the review in
I also fixed the red Verified locally:
The Re #10617: no conflict — that PR adds a |
|
Quick update on |
Fixes #10691 .
Changes proposed in this pull request:
GifImagePlugin._write_multiple_frames, fall back to a 1x1(0, 0, 1, 1)bounding box when_getbbox(background_im, im_frame)[1]returnsNoneafter a frame withdisposal=2andtransparency, preventing the subsequent empty/fully-transparent frame from being treated as frame 0 (if not frame_data.bbox:) and emitting a duplicateGIF89aglobal header and color table.test_dispose2_transparent_frame_no_duplicate_headerverifying a singleGIF89aheader, all 3 frames preserved, and the expected RGBA contents across every frame.Root Cause
When a frame follows a
disposal=2frame withtransparencyconfigured,_write_multiple_framescomputes its bounding box againstbackground_im. If the subsequent frame is completely transparent,_getbbox(background_im, im_frame)[1]returnsNone, which caused the write loop'sif not frame_data.bbox:check to write a second global header mid-stream.Testing
pytest Tests/test_file_gif.py Tests/test_imagesequence.py: 126 passed, 2 skipped (unrelated:littlecms2andlibtiffnot installed in local environment).ruff check src/PIL/GifImagePlugin.py Tests/test_file_gif.py: All checks passed.