← Back to Pull requests

Take APNG frame deltas against the canvas after disposal #10616

Open
unknown opened this pull request with 244 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 24, 2026 18:51 UTC
Author

#10336 compares each APNG frame with the previous frame directly, so the disposal of the previous frame is no longer applied before the delta is taken. A frame that follows OP_PREVIOUS or OP_BACKGROUND is then saved as a delta against a canvas the viewer no longer has, and the area that the disposal reverted or cleared is left wrong. This is not in 13.0.0.

from PIL import Image
f0 = Image.new("RGBA", (8, 8), (255, 0, 0, 255))
f1 = f0.copy(); f1.paste((0, 255, 0, 255), (0, 0, 4, 4))
f2 = f1.copy(); f2.paste((0, 0, 255, 255), (4, 4, 8, 8))
f0.save("a.png", save_all=True, append_images=[f1, f2], disposal=[0, 2, 0], duration=100)
with Image.open("a.png") as im:
    im.seek(2)
    im.getpixel((0, 0))  # (255, 0, 0, 255), expected (0, 255, 0, 255)

disposal=[0, 1, 0] is wrong too: the pixel is (0, 0, 0, 0). Frame 2 is wrong in Pillow's reader and in ffmpeg; before #10336 both decoded it correctly.

The change keeps #10336's merge rule (a frame equal to the previous frame is merged into it) and takes the bounding box of each delta against the canvas left after the previous frame's disposal. For that it tracks the canvas: OP_BACKGROUND clears the frame's region, and OP_PREVIOUS keeps the canvas from before the previous frame, which is not the previous frame when that frame was itself disposed of. Files saved without disposal are byte-identical to main.

Tests: test_apng_save_delta_after_disposal (RGB, RGBA and L, with OP_PREVIOUS and OP_BACKGROUND in a list) and test_apng_save_delta_after_disposal_previous_chain (RGB, RGBA and L, scalar OP_PREVIOUS on four frames). On main Tests/test_file_apng.py has 9 failed, 56 passed (the 9 are these tests); with the change it is 65 passed. Tests/test_file_gif.py, Tests/test_file_png.py and Tests/test_imagesequence.py pass as well (268 passed, 1 skipped with Tests/test_file_apng.py).

The implementation and tests were written with AI assistance.

Diff: 244 lines (+183 / -61) across 3 files Reviewer: radarhere Review duration: 8640m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 244 lines diff across 3 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.329
Real PR Conversation Timeline
1 comments
"Review active on #10616"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 38.8% (MEDIUM) · Higher = larger blast radius
38.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 20.7% · Safe to merge
20.7%