Fill only the area that was modified by the previous GIF frame #1093
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
As seen in #1059:
If you look closely you can see there are multiple different flickers:
This is how it should look like:
This change achieves that by clearing only part of the frame when need to dispose to background.
Motivation and Context
I sent the above image through http://ezgif.com/split ("Ignore optimizations") to see what how they look:
As you can see there's an actual half-frame and there are many almost-empty frames, most importantly the one where there's a little pink on the left. These two frames cause the trouble. Their dispose is set to "background" which triggers a code block that fills the entire frame with
bgColor
. The problem is that the frame doesn't contain a full-sized image, just a partial one. This is also confirmed in debug (closed frames look identical to 0th frame):I checked the GIF spec and it says:
This means that when preparing the frame transition from 2 to 3, 2 wants it's partial area to be cleared as defined by the (ix,iy iw,ih) rect. I took a shot at implementing that, I went through these iterations to arrive at the code in the PR.
simple iteration with cached end values
pre-calculate values and name them
lift multiplication up
lift multiplication up again and rename variables
Not sure which one is best, I think the final version is readable enough and all multiplications are lifted outside, so it should be efficient as well.